Ejemplo n.º 1
0
 /**
  * Load labels
  *
  * @param string $filename
  * @throws \Exception
  *
  * @return void
  */
 public function loadLabels($filename)
 {
     if (!is_readable($filename)) {
         throw new \Exception("Labels file `{$filename}` is not readable or does not exists.");
     }
     $parser = new \Mage_Xml_Parser();
     $this->_labels = $parser->load($filename)->xmlToArray();
 }
 /**
  * Constructor
  *
  * @param string $filename
  * @throws \Exception
  */
 public function __construct($filename)
 {
     if (!is_readable($filename)) {
         throw new \Exception("Fixtures set file `{$filename}` is not readable or does not exists.");
     }
     $parser = new \Mage_Xml_Parser();
     $this->_fixtures = $parser->load($filename)->xmlToArray();
 }
Ejemplo n.º 3
0
 /**
  * Convert XML document into array.
  *
  * @param string $xmlRequestBody XML document
  * @return array Data converted from XML document to array. Root node is excluded from response.
  * @throws InvalidArgumentException In case of invalid argument type.
  * @throws Mage_Webapi_Exception If decoding error occurs.
  */
 public function interpret($xmlRequestBody)
 {
     if (!is_string($xmlRequestBody)) {
         throw new InvalidArgumentException(sprintf('Invalid data type "%s". String is expected.', gettype($xmlRequestBody)));
     }
     /** Disable external entity loading to prevent possible vulnerability */
     $previousLoaderState = libxml_disable_entity_loader(true);
     set_error_handler(array($this, 'handleErrors'));
     $this->_xmlParser->loadXML($xmlRequestBody);
     restore_error_handler();
     libxml_disable_entity_loader($previousLoaderState);
     /** Process errors during XML parsing. */
     if ($this->_errorMessage !== null) {
         if (!$this->_app->isDeveloperMode()) {
             $exceptionMessage = $this->_helper->__('Decoding error.');
         } else {
             $exceptionMessage = 'Decoding Error: ' . $this->_errorMessage;
         }
         throw new Mage_Webapi_Exception($exceptionMessage, Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     }
     $data = $this->_xmlParser->xmlToArray();
     /** Data will always have exactly one element so it is safe to call reset here. */
     return reset($data);
 }