Skip to content

Commit

Permalink
Refactor some.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenguest committed May 16, 2020
1 parent f4b06c5 commit 3066a11
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions Services/OpenStreetMap.php
Expand Up @@ -355,6 +355,23 @@ public function search(array $criteria): array
return $results;
}

/**
* Create an object of specified class and XML
*
* @param string $class Class name of object
* @param string $ObjectXml XML describing object to be created
*
* @return Services_OpenStreetMap_Object
*/
private function createObject(string $class, string $ObjectXml)
{
$obj = new $class();
$obj->setTransport($this->getTransport());
$obj->setConfig($this->getConfig());
$obj->setXml(simplexml_load_string($ObjectXml));
return $obj;
}

/**
* Search node for a specific key/value pair, allowing for value to be
* included in a semicolon delimited list, or allowing for a wild-card
Expand All @@ -378,25 +395,13 @@ private function searchNode(
foreach ($node->tag as $tag) {
if ($tag['k'] == $key) {
if ($tag['v'] == $value) {
$obj = new $class();
$obj->setTransport($this->getTransport());
$obj->setConfig($this->getConfig());
$obj->setXml(simplexml_load_string($node->saveXML()));
$results[] = $obj;
$results[] = $this->createObject($class, $node->saveXML());
} elseif ($value === '*') {
$obj = new $class();
$obj->setTransport($this->getTransport());
$obj->setConfig($this->getConfig());
$obj->setXml(simplexml_load_string($node->saveXML()));
$results[] = $obj;
$results[] = $this->createObject($class, $node->saveXML());
} elseif (strpos($tag['v'], ';')) {
$array = explode(';', $tag['v']);
if (in_array($value, $array)) {
$obj = new $class();
$obj->setTransport($this->getTransport());
$obj->setConfig($this->getConfig());
$obj->setXml(simplexml_load_string($node->saveXML()));
$results[] = $obj;
$results[] = $this->createObject($class, $node->saveXML());
}
}
}
Expand Down

0 comments on commit 3066a11

Please sign in to comment.