Пример #1
0
 /**
  * Preparing data and parsing result received
  *
  * @param array $data
  * @return void
  */
 public function handle($data)
 {
     $this->_request = ArrayToXml::render($data);
     $this->_rawRequest = $this->_request;
     $xmlResponse = self::sendMessage($this->_request);
     if (!in_array($this->getConnection()->getHttpStatusCode(), array('200', '301', '302'))) {
         $this->_response = array('errors' => array('error' => array('code' => array('@data' => $this->getConnection()->getHttpStatusCode()), 'message' => array('@data' => $this->getConnection()->error))));
     } else {
         try {
             $this->_response = XmlToArray::render($xmlResponse);
         } catch (\Exception $e) {
             $this->_response = array('errors' => array('error' => array('code' => array('@data' => '0999'), 'message' => array('@data' => $e->getMessage()))));
         }
     }
     $this->_rawResponse = $xmlResponse;
 }
Пример #2
0
 public function testRender()
 {
     $ArrayToXml = new ArrayToXml(array(array(1)));
     $this->assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<test>1</test>", $ArrayToXml->render(array('test' => 1)));
 }
Пример #3
0
 /**
  * Static entry point. Options are:
  *  - version: (default 1.0) version string to put in xml prolog
  *  - encoding: (default UTF-8) use the specified encoding
  *  - trim: (default true) Trim values
  *  - depth: (default 10) Maximum depth to parse the given array, throws exception when exceeded
  *
  * @param array $input the input array
  * @param array $options set additional options to pass to XmlToArray
  * @throws ArrayToXmlException
  * @return string
  */
 public static function render(array $input, array $options = array())
 {
     $options = array_merge(array('version' => '1.0', 'encoding' => 'UTF-8', 'trim' => true, 'depth' => 10), $options);
     $Instance = new ArrayToXml($input, $options['depth'], $options['trim']);
     return $Instance->toXml($options['version'], $options['encoding']);
 }