Last active
November 19, 2016 20:03
-
-
Save inri13666/60a52e85d1512a167fd0f440a274d395 to your computer and use it in GitHub Desktop.
Demo for "phrets-core"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
akuma: | |
phrets: | |
crea: #KeyAsAttribute | |
base_uri: 'http://sample.data.crea.ca/' | |
username: 'CXLHfDVrziCfvwgCuL8nUahC' | |
password: 'mFqMsCSPdnb5WO1gpEEtDCHH' | |
http_auth_method: ~ | |
user_agent: ~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; | |
$config = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(dirname(__FILE__) . '/config.yml')); | |
$configuration = new \Akuma\PHRets\Configuration($config['akuma']['phrets']['crea']); | |
$client = new \Akuma\PHRets\Client\GuzzleRetsClient($configuration); | |
$logger = new \Monolog\Logger('PHRETS'); | |
$logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::API)); | |
$client->setLogger($logger); | |
$client->doRequest('Login.svc/Login', ['Format' => 'Standard-XML']); | |
$format = 'Standard-XML'; | |
$params = [ | |
'query' => [ | |
'Format' => $format, | |
'SearchType' => 'Property', | |
'Class' => 'Property', | |
'QueryType' => 'DMQL2', | |
'Culture' => 'en-CA', | |
'Query' => '(ID=*)', | |
//'Count' => '1', | |
//'Limit' => 1, | |
] | |
]; | |
/** @var \Psr\Http\Message\ResponseInterface $response */ | |
$response = $client->doRequest('Search.svc/Search', $params); | |
$contents = $response->getBody()->getContents(); | |
$xml = simplexml_load_string($contents); | |
/** @var SimpleXMLElement $response */ | |
$response = $xml->{'RETS-RESPONSE'}; | |
$data = []; | |
/** @var SimpleXMLElement $property */ | |
foreach ($response->{'Property'} as $property) { | |
foreach ($property->attributes() as $k => $v) { | |
$data[$k][] = (string)$v; | |
} | |
} | |
$data['ID'] = array_unique($data['ID']); | |
$sliced = array_chunk($data['ID'], 100); | |
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); | |
foreach ($sliced as $fetch) { | |
$table = new \Symfony\Component\Console\Helper\Table($output); | |
$table | |
->setHeaders([ | |
'ID', | |
'LastUpdated', | |
'Neighbourhood', | |
'Subdivision', | |
'StreetAddress', | |
'AddressLine1', | |
'AddressLine2', | |
'StreetNumber', | |
'StreetName', | |
'StreetSuffix', | |
'StreetDirectionSuffix', | |
'UnitNumber', | |
'BoxNumber', | |
'City', | |
'Province', | |
'PostalCode', | |
'Country', | |
'AdditionalStreetInfo', | |
'CommunityName', | |
]) | |
->setRows([]); | |
$params['query']['Query'] = sprintf('(ID=%s)', implode(',', $fetch)); | |
$response = $client->doRequest('Search.svc/Search', $params); | |
$contents = $response->getBody()->getContents(); | |
$xml = simplexml_load_string($contents); | |
$response = $xml->{'RETS-RESPONSE'}; | |
foreach ($response->{'PropertyDetails'} as $property) { | |
$table->addRow([ | |
$property->attributes()["ID"], | |
$property->attributes()["LastUpdated"], | |
//Appendix G – Address Payload | |
(string)$property->{'Address'}->{'CommunityName'} ?: 'N/A', | |
(string)$property->{'Address'}->{'Neighbourhood'} ?: 'N/A', | |
(string)$property->{'Address'}->{'StreetAddress'} ?: 'N/A', | |
(string)$property->{'Address'}->{'AddressLine1'} ?: 'N/A', | |
(string)$property->{'Address'}->{'AddressLine2'} ?: 'N/A', | |
(string)$property->{'Address'}->{'StreetNumber'} ?: 'N/A', | |
(string)$property->{'Address'}->{'StreetName'} ?: 'N/A', | |
(string)$property->{'Address'}->{'StreetSuffix'} ?: 'N/A', | |
(string)$property->{'Address'}->{'StreetDirectionSuffix'} ?: 'N/A', | |
(string)$property->{'Address'}->{'UnitNumber'} ?: 'N/A', | |
(string)$property->{'Address'}->{'BoxNumber'} ?: 'N/A', | |
(string)$property->{'Address'}->{'City'} ?: 'N/A', | |
(string)$property->{'Address'}->{'Province'} ?: 'N/A', | |
(string)$property->{'Address'}->{'PostalCode'} ?: 'N/A', | |
(string)$property->{'Address'}->{'Country'} ?: 'N/A', | |
(string)$property->{'Address'}->{'AdditionalStreetInfo'} ?: 'N/A', | |
(string)$property->{'Address'}->{'Subdivision'} ?: 'N/A', | |
]); | |
} | |
$table->render(); | |
}; | |
$client->doRequest('Logout.svc/Logout'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; | |
$config = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(dirname(__FILE__) . '/config.yml')); | |
$configuration = new \Akuma\PHRets\Configuration($config['akuma']['phrets']['crea']); | |
$client = new \Akuma\PHRets\Client\GuzzleRetsClient($configuration); | |
$logger = new \Monolog\Logger('PHRETS'); | |
$logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::API)); | |
//$client->setLogger($logger); | |
$creaFeed = new \Akuma\PHRets\Feed\Crea\CreaFeed($client, new \Akuma\PHRets\Parser\StandardXMLParser()); | |
$query = new \Akuma\PHRets\Query\Query(); | |
$query->setClass('Property') | |
->setSearchType('Property') | |
->setQueryType('DMQL2') | |
->setCulture('en-CA') | |
->setQuery('(ID=*)') | |
->setCount(1) | |
->setLimit(1); | |
//var_dump($creaFeed->search($query)); | |
$query->setQuery('(ID=11937442)'); | |
var_dump($creaFeed->search($query)); | |
//$client->doRequest('Login.svc/Login', ['Format' => 'Standard-XML']); | |
//$format = 'Standard-XML'; | |
//$params = [ | |
// 'query' => [ | |
// 'Format' => $format, | |
// 'SearchType' => 'Property', | |
// 'Class' => 'Property', | |
// 'QueryType' => 'DMQL2', | |
// 'Culture' => 'en-CA', | |
// 'Query' => '(ID=*)', | |
// //'Count' => '1', | |
// //'Limit' => 1, | |
// ] | |
//]; | |
///** @var \Psr\Http\Message\ResponseInterface $response */ | |
//$response = $client->doRequest('Search.svc/Search', $params); | |
//$contents = $response->getBody()->getContents(); | |
//$xml = simplexml_load_string($contents); | |
// | |
///** @var SimpleXMLElement $response */ | |
//$response = $xml->{'RETS-RESPONSE'}; | |
// | |
//$data = []; | |
// | |
///** @var SimpleXMLElement $property */ | |
//foreach ($response->{'Property'} as $property) { | |
// foreach ($property->attributes() as $k => $v) { | |
// $data[$k][] = (string)$v; | |
// } | |
//} | |
//$data['ID'] = array_unique($data['ID']); | |
//$sliced = array_chunk($data['ID'], 100); | |
//$output = new \Symfony\Component\Console\Output\ConsoleOutput(); | |
//foreach ($sliced as $fetch) { | |
// $table = new \Symfony\Component\Console\Helper\Table($output); | |
// $table | |
// ->setHeaders([ | |
// 'ID', | |
// 'LastUpdated', | |
// 'Neighbourhood', | |
// 'Subdivision', | |
// 'StreetAddress', | |
// 'AddressLine1', | |
// 'AddressLine2', | |
// 'StreetNumber', | |
// 'StreetName', | |
// 'StreetSuffix', | |
// 'StreetDirectionSuffix', | |
// 'UnitNumber', | |
// 'BoxNumber', | |
// 'City', | |
// 'Province', | |
// 'PostalCode', | |
// 'Country', | |
// 'AdditionalStreetInfo', | |
// 'CommunityName', | |
// ]) | |
// ->setRows([]); | |
// $params['query']['Query'] = sprintf('(ID=%s)', implode(',', $fetch)); | |
// $response = $client->doRequest('Search.svc/Search', $params); | |
// $contents = $response->getBody()->getContents(); | |
// $xml = simplexml_load_string($contents); | |
// $response = $xml->{'RETS-RESPONSE'}; | |
// foreach ($response->{'PropertyDetails'} as $property) { | |
// $table->addRow([ | |
// $property->attributes()["ID"], | |
// $property->attributes()["LastUpdated"], | |
// //Appendix G – Address Payload | |
// (string)$property->{'Address'}->{'CommunityName'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'Neighbourhood'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'StreetAddress'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'AddressLine1'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'AddressLine2'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'StreetNumber'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'StreetName'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'StreetSuffix'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'StreetDirectionSuffix'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'UnitNumber'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'BoxNumber'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'City'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'Province'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'PostalCode'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'Country'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'AdditionalStreetInfo'} ?: 'N/A', | |
// (string)$property->{'Address'}->{'Subdivision'} ?: 'N/A', | |
// ]); | |
// } | |
// $table->render(); | |
//}; | |
// | |
//$client->doRequest('Logout.svc/Logout'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment