Пример #1
0
 /**
  * Extract relevant data from webservice response.
  *
  * @param string $xml
  * @return array
  * @throws Dhl_Account_Exception
  */
 protected function parsePackstationFinderResponse($xml)
 {
     $element = new SimpleXMLElement($xml, LIBXML_NOCDATA);
     // invalid xml exception
     if (!$element) {
         throw new Dhl_Account_Exception('An error occured while parsing the packstation response.');
     }
     // empty xml exception, optionally with error info
     if (!$element->data->children()->count()) {
         $errorMessage = $this->parseResponseSessionInfo($element->session, 'No data transmitted');
         throw new Dhl_Account_Exception($errorMessage);
     }
     // no or too many packstations found exception, optionally with error info
     if (!$element->data->result->automats || !$element->data->result->automats->children()->count()) {
         $errorMessage = $this->parseResponseSessionInfo($element->session, 'Address is ambigious');
         throw new Dhl_Account_Exception($errorMessage);
     }
     $automats = array();
     foreach ($element->data->result->automats->children() as $automat) {
         $distance = trim(current($automat->location->distance));
         $measure = new Zend_Measure_Length($distance, Zend_Measure_Length::METER, Mage::app()->getLocale()->getLocale());
         if ($distance > 1000) {
             $measure->convertTo(Zend_Measure_Length::KILOMETER);
         }
         $automats[] = array('packstationnumber' => substr(trim(current($automat['objectId'])), -3), 'city' => trim($automat->address->city), 'zip' => trim($automat->address->zip), 'street' => trim($automat->address->street), 'streetno' => trim($automat->address->streetno), 'errors' => '', 'distance' => $measure->toString());
     }
     return $automats;
 }
Пример #2
0
 /**
  * test toString
  * expected string
  */
 public function testLengthToString()
 {
     $value = new Zend_Measure_Length('-100', Zend_Measure_Length::STANDARD, 'de');
     $this->assertEquals('-100 m', $value->toString(), 'Value -100 m expected');
 }
Пример #3
0
 /**
  * Compare if the value and type is equal
  *
  * @param  Zend_Measure_Length  $object  Length object to compare
  * @return boolean
  */
 public function equals($object)
 {
     if ($object->toString() == $this->toString()) {
         return true;
     }
     return false;
 }