Example #1
0
 public function getDetails($regon, $type = 'F')
 {
     $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('pRegon' => $regon);
     switch ($type) {
         case 'F':
         case 'LF':
             $params['pNazwaRaportu'] = 'PublDaneRaportDzialalnoscFizycznejCeidg';
             $prefix = 'fiz';
             break;
         case 'P':
         case 'LP':
             $params['pNazwaRaportu'] = 'PublDaneRaportPrawna';
             $prefix = 'praw';
     }
     $this->solveCaptcha();
     $result = parent::DanePobierzPelnyRaport($params);
     //        $this->debug('DanePobierzPelnyRaport: '.print_r($result, true));
     if (empty($result->DanePobierzPelnyRaportResult)) {
         throw new \MWojtowicz\GusClient\Exception\NotFound();
     }
     $xml = new \DOMDocument();
     $xml->loadXML($result->DanePobierzPelnyRaportResult);
     unset($result);
     if ($xml->documentElement->hasChildNodes()) {
         $data = new \stdClass();
         for ($i = 0; $i < $xml->documentElement->childNodes->length; $i++) {
             $node = $xml->documentElement->childNodes->item($i);
             if ($node->nodeName == 'dane') {
                 for ($i = 0; $i < $node->childNodes->length; $i++) {
                     $child = $node->childNodes->item($i);
                     if ($child->nodeName == $prefix . '_adSiedzNumerNieruchomosci') {
                         $data->house = $child->textContent;
                     }
                     if ($child->nodeName == $prefix . '_adSiedzNumerLokalu') {
                         $data->flat = $child->textContent;
                     }
                     if ($child->nodeName == $prefix . '_regon14') {
                         $data->regon = $child->textContent;
                     }
                     if ($child->nodeName == $prefix . '_nip') {
                         $data->nip = $child->textContent;
                     }
                 }
             }
         }
     } else {
         throw new \MWojtowicz\GusClient\Exception\NotFound();
     }
     return $data;
 }