Example #1
0
 /**
  * Main find method - performs search on API
  * @param $paramName
  * @param $paramValue
  * @return array|mixed One object or array of objects
  * @throws Exception\NotFound
  */
 private function find($paramName, $paramValue)
 {
     $headers = array(new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', $this->_getMethodUrl('DaneSzukaj'), 0), new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $this->_getServiceUrl(), 0));
     $this->__setSoapHeaders($headers);
     $params = array('pParametryWyszukiwania' => array($paramName => $paramValue));
     $this->solveCaptcha();
     $result = parent::DaneSzukaj($params);
     //        $this->debug("DaneSzukaj: ".print_r($result, true));
     if (empty($result->DaneSzukajResult)) {
         throw new \MWojtowicz\GusClient\Exception\NotFound();
     }
     $xml = new \DOMDocument();
     $xml->loadXML($result->DaneSzukajResult);
     unset($result);
     if ($xml->documentElement->hasChildNodes()) {
         $data = array();
         for ($i = 0; $i < $xml->documentElement->childNodes->length; $i++) {
             $node = $xml->documentElement->childNodes->item($i);
             if ($node instanceof \DOMElement && $node->nodeName == 'dane') {
                 $data[] = $this->parseResult($node);
                 $node->parentNode->removeChild($node);
             }
         }
         if (count($data) == 1) {
             reset($data);
             $data = current($data);
         }
     } else {
         throw new \MWojtowicz\GusClient\Exception\NotFound();
     }
     unset($result);
     return $data;
 }