createArray() public static méthode

Convert an XML to Array
public static createArray ( $input_xml, $options ) : DOMDocument
Résultat DOMDocument
Exemple #1
0
 /**
  * Confirmation of the request
  */
 public function execute($config)
 {
     // Post strings
     $xml_post_string_one = '<request><EventType>ConfirmMeter</EventType><event><DeviceId>' . $config['DeviceId'] . '</DeviceId><DeviceSer>' . $config['DeviceSer'] . '</DeviceSer><UserPin>' . $config['UserPin'] . '</UserPin><MeterNum>' . $this->meterNumber . '</MeterNum><Amount>0</Amount><Reference></Reference></event></request>' . PHP_EOL;
     $xml_post_string_two = '<request><SessionId></SessionId><EventType>Reprint</EventType><event><TransRef>' . $this->transref . '</TransRef><MeterNum>' . $this->meterNumber . '</MeterNum><OrigReference>' . $this->reference . '</OrigReference></event></request>' . PHP_EOL;
     // Create a TCP/IP socket
     $socket = new \CodeChap\Aeon\Socket($config);
     // STEP 1. Authenticate //
     // Send confirmation request
     $socket->write($xml_post_string_one);
     // Get result of send
     $result_one = $socket->get();
     // STEP 2. Reprint //
     // Find session id field
     preg_match('/<SessionId>(.*)<\\/SessionId>/', $result_one, $SessionId);
     // Swop in Session ID
     $xml_post_string_two = preg_replace('/<SessionId><\\/SessionId>/', $SessionId[0], $xml_post_string_two);
     // Send confirmation request
     $socket->write($xml_post_string_two);
     // Get result of send
     $result = $socket->get();
     // Done
     $finalResult = \LSS\XML2Array::createArray($result);
     // Return usefull data
     return $finalResult['response'];
 }
 /**
  * @return array|\DOMDocument
  * @throws \Exception
  */
 protected function parseResBody()
 {
     $array = ['temp' => []];
     if ($this->interRes->body) {
         $array = XML2Array::createArray($this->interRes->body);
     }
     $this->arrayBody = array_values($array)[0];
 }
Exemple #3
0
 public function __construct(RequestInterface $request, $data)
 {
     parent::__construct($request, $data);
     $this->request = $request;
     $array = XML2Array::createArray($data);
     if (!isset($array['response'])) {
         throw new InvalidResponseException();
     }
     $this->data = $array['response'];
     unset($array);
 }
 public function sendData($data, $root = 'query')
 {
     $headers = array('Content-Type' => 'text/xml; charset=utf-8');
     //$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $this->getData())->send();
     $httpResponse = $this->httpClient->get($this->getEndpoint(), $headers, ['query' => $this->getData()])->send();
     $array = XML2Array::createArray($httpResponse->getBody(true));
     if (isset($array['nm_response'])) {
         $array['response'] = $array['nm_response'];
         unset($array['nm_response']);
         return $this->response = new Response($this, $array);
     } else {
         return $this->response = new Response($this, ['response' => []]);
     }
 }
Exemple #5
0
 /**
  * {@inheritDoc}
  */
 public function match($value, $pattern)
 {
     if (!Xml::isValid($value) || !Xml::isValid($pattern)) {
         return false;
     }
     $arrayValue = XML2Array::createArray($value);
     $arrayPattern = XML2Array::createArray($pattern);
     $match = $this->matcher->match($arrayValue, $arrayPattern);
     if (!$match) {
         $this->error = $this->matcher->getError();
         return false;
     }
     return true;
 }
Exemple #6
0
 /**
  * Confirmation of the request
  */
 public function execute($config)
 {
     // Post strings
     $xml_post_string_one = '<request><EventType>Authentication</EventType><event><DeviceId>' . $config['DeviceId'] . '</DeviceId><DeviceSer>' . $config['DeviceSer'] . '</DeviceSer><UserPin>' . $config['UserPin'] . '</UserPin><TransType>AccountInfo</TransType><Reference>' . $this->reference . '</Reference></event></request>' . PHP_EOL;
     // Create a TCP/IP socket
     $socket = new \CodeChap\Aeon\Socket($config);
     // Send confirmation request
     $socket->write($xml_post_string_one);
     // Get result of send
     $result = $socket->get();
     // Done
     $finalResult = \LSS\XML2Array::createArray($result);
     // Return usefull data
     return $finalResult['response'];
 }
Exemple #7
0
 /**
  * This method is called once a request is executed
  * @param unknown $context
  * @param unknown $storage
  */
 public function onLeaveDoRequest($context, &$storage)
 {
     $client = $context['locals']['client'];
     /*
      * @var Zend\Http\Request
      */
     $response = $client->getResponse();
     /*
      * @var Zend\Http\Response
      */
     $request = $client->getRequest();
     $mediaType = $response->getHeaders()->get('Content-Type')->getMediaType();
     $body = $response->getBody();
     switch ($mediaType) {
         case 'application/json':
             // turn JSON into array
             $body = Json::decode($body, Json::TYPE_ARRAY);
             break;
             // @TODO: Adjust the XML media type
         // @TODO: Adjust the XML media type
         case 'text/xml':
         case 'application/atom+xml':
             // turn XML into an array
             $body = \LSS\XML2Array::createArray($body);
             break;
         default:
             break;
     }
     $trace = debug_backtrace();
     $caller = $trace[2];
     $callerName = $caller['function'];
     if (isset($caller['class'])) {
         $callerName .= " @ ({$caller['class']})";
     }
     // collect the data here
     $this->requests[$callerName][] = array('uri' => $context['functionArgs'][0], 'request' => array('url' => $request->getUri()->toString(), 'method' => $request->getMethod(), 'headers' => $request->getHeaders()->toArray(), 'content' => substr($request->getContent(), 0, 50) . '...'), 'response' => array('code' => $response->getStatusCode(), 'media-type' => $mediaType, 'body' => $body), 'time (ms)' => $this->formatTime($context['durationInclusive']));
     $this->requestCount++;
     /*
     $storage['RequestsAndTime'][] = array (
         'caller' => $callerName,
         'uri' => $context['functionArgs'][0],
         'method' => $request->getMethod(),
         'responseCode' => $response->getStatusCode(),
         'ResponseMedia' => $mediaType,
         'time (ms)' => $this->formatTime($context['durationInclusive']),
     );
     */
 }
Exemple #8
0
 /**
  * Confirmation of the request
  */
 public function execute($config)
 {
     // Set path to temp file
     $filePath = $this->getTemp() . md5($this->meternumber) . ".xml";
     // Open it
     if ($xml = file_get_contents($filePath)) {
         // Create a TCP/IP socket
         $socket = new \CodeChap\Aeon\Socket($config);
         // Send confirmation request
         $socket->write($xml);
         // Get result of send
         $result = $socket->get();
         // Done
         $finalResult = \LSS\XML2Array::createArray($result);
         // Return usefull data
         return $finalResult['response'];
     }
 }
Exemple #9
0
 /**
  * Execute the call
  */
 public function execute($config)
 {
     // Post strings
     $xml_post_string_one = '<request><EventType>ConfirmMeter</EventType><event><DeviceId>' . $config['DeviceId'] . '</DeviceId><DeviceSer>' . $config['DeviceSer'] . '</DeviceSer><UserPin>' . $config['UserPin'] . '</UserPin><MeterNum>' . $this->meterNumber . '</MeterNum><Amount>' . $this->credit . '</Amount><Reference>' . $this->reference . '</Reference></event></request>' . PHP_EOL;
     $xml_post_string_two = '<request><SessionId></SessionId><EventType>GetVoucher</EventType><event><Type></Type><TransRef></TransRef><Reference>' . $this->reference . '</Reference></event></request>' . PHP_EOL;
     // Create step three's confirmation settings
     $xml_post_string_thr = '<request><EventType>SoldVoucher</EventType><event><DeviceId>' . $config['DeviceId'] . '</DeviceId><DeviceSer>' . $config['DeviceSer'] . '</DeviceSer><UserPin>' . $config['UserPin'] . '</UserPin><TransRef></TransRef><Reference>' . $this->reference . '</Reference></event></request>' . PHP_EOL;
     // Create a TCP/IP socket
     $socket = new \CodeChap\Aeon\Socket($config);
     // STEP 1. AUTHENTICATE //
     // Send confirmation request
     $socket->write($xml_post_string_one);
     // Get result of send
     $result_one = $socket->get();
     // STEP 2. BUY //
     // Find session id field
     preg_match('/<SessionId>(.*)<\\/SessionId>/', $result_one, $SessionId);
     // Find transfer reference field
     preg_match('/<TransRef>(.*)<\\/TransRef>/', $result_one, $TransRef);
     // Swop in Session ID and transfer ref with first result
     $xml_post_string_two = preg_replace('/<SessionId><\\/SessionId>/', $SessionId[0], $xml_post_string_two);
     $xml_post_string_two = preg_replace('/<TransRef><\\/TransRef>/', $TransRef[0], $xml_post_string_two);
     // Send voucher request
     $socket->write($xml_post_string_two);
     // Get result of send
     $result_two = $socket->get();
     // Shutdown and close the socket
     $socket->close();
     // Done
     $finalResult = \LSS\XML2Array::createArray($result_two);
     // STEP 3. Confirmation (To be performed by user later so we store it in a temp file) //
     // Find transfer reference field
     preg_match('/<TransRef>(.*)<\\/TransRef>/', $result_two, $TransRef);
     // Swop in transfer reference
     $xml_post_string_thr = preg_replace('/<TransRef><\\/TransRef>/', $TransRef[0], $xml_post_string_thr);
     // Store this xml string in the php temp folder
     if ($file = fopen($this->getTemp() . md5($this->meterNumber) . ".xml", "w")) {
         fwrite($file, $xml_post_string_thr);
         fclose($file);
     }
     // Return usefull data
     return $finalResult['response'];
 }
<?php

require_once '../../../vendor/autoload.php';
include '../../_preinit.php';
/**
 * Setting up the view component
 */
$di->set('view', function () {
    return testViewRegister(new \Phalcon\Mvc\View());
}, true);
$view = $di->get('view');
// Load test xml as array:
$test_params = \LSS\XML2Array::createArray(file_get_contents('../test_1/users.xml'));
echo $view->getRender('users', 'list', $test_params, function ($view) {
    //Set any extra options here
    $view->setViewsDir("views/");
    if ($_GET['cache'] == 1) {
        // Cache this view for 1 hour with random key:
        $datetime = explode('.', microtime(true));
        $datetime = date('Y-m-d-H-i-s-', $datetime[0]) . str_pad($datetime[1], 4, '0');
        $view->cache(array("lifetime" => 3600, 'key' => $datetime));
    }
});
 /**
  * Reconverts given data back to array
  *
  * @param $data
  *
  * @return mixed
  */
 public function reconvert($data)
 {
     return XML2Array::createArray($data);
 }
 /**
  * Fixes the order of the keys in the meta data
  * @param  array $xsd
  * @return array
  */
 protected static function fixMetaKeyOrder(array $data)
 {
     if (!isset(self::$keyOrder)) {
         // read the key order
         $doc = new \DOMDocument();
         $doc->load(__DIR__ . '/../../../config/zpk/schema.xsd');
         $xsd = \LSS\XML2Array::createArray($doc);
         self::$keyOrder = array('@attributes');
         foreach ($xsd["xs:schema"]["xs:element"][0]["xs:complexType"]["xs:sequence"]["xs:element"] as $element) {
             if (isset($element['@attributes']['name'])) {
                 $name = $element['@attributes']['name'];
             } elseif ($element['@attributes']['ref']) {
                 $name = $element['@attributes']['ref'];
             }
             if (!$name) {
                 continue;
             }
             self::$keyOrder[] = $name;
         }
     }
     $meta = array();
     foreach (self::$keyOrder as $key) {
         if (isset($data[$key])) {
             $meta[$key] = $data[$key];
         }
     }
     return $meta;
 }
Exemple #13
0
 /**
  * Get template information for specified locale
  * 
  * @param string $template Template file
  * @param string $locale Locale or empty string
  * 
  * @return array Template subject and file path
  */
 protected function getTemplateDataForLocale($template, $locale)
 {
     // path to document with subjects
     $metafile = $this->templatespath . '/' . $locale . '/subjects.xml';
     if (!file_exists($metafile)) {
         // file with subjects not found
         return null;
     }
     // load and parse document with subjects
     $xml = @file_get_contents($metafile);
     if (!$xml || $xml == '') {
         return null;
     }
     $array = \LSS\XML2Array::createArray($xml);
     // our template is not found in this document so it is not there
     if (!isset($array['templates'][$template])) {
         return null;
     }
     $templatefile = $this->templatespath . '/' . $locale . '/' . $template . '.htm';
     // check if template file exists for this locale
     if (!file_exists($templatefile)) {
         return null;
     }
     $tmpl = $locale != '' ? $locale . '/' : '';
     $tmpl .= $template;
     // all was fine. return found template
     return array('subject' => $array['templates'][$template]['subject'], 'file' => $tmpl);
 }
Exemple #14
0
 protected function decode(&$response)
 {
     $this->encoding = $encoding = ord(substr($response, 0, 1));
     $response = substr($response, 1);
     switch ($encoding) {
         default:
         case self::ENC_RAW:
             //void
             break;
         case self::ENC_SERIALIZE:
             $response = unserialize($response);
             break;
         case self::ENC_XML:
             try {
                 $response = array_shift(XML2Array::createArray($response));
             } catch (Exception $e) {
                 throw new Exception('Response is not valid XML: ' . $response);
             }
             break;
         case self::ENC_JSON:
             $response = json_decode($cmd);
             break;
     }
     return $encoding;
 }
 /**
  * Parse answer xml and return ShopLogisticsRu\Answer object
  *
  * @param string $xml Answer xml data
  *
  * @return Answer
  * @throws AnswerException
  * @throws \Exception
  */
 protected function parseAnswer($xml)
 {
     $xmlToArray = XML2Array::createArray($xml);
     if (!is_array($xmlToArray) || !isset($xmlToArray['answer'])) {
         throw new AnswerException('Empty answer');
     }
     return new Answer((array) $xmlToArray['answer']);
 }