/**
  * Carga un recurso de tipo Xml
  *
  * @param mixed $file
  * @param null $type
  * @return array
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     $dom = XmlUtils::loadFile($path);
     $arrayXml = XmlUtils::convertDomElementToArray($dom->documentElement);
     $this->container->addResource(new FileResource($path));
     return $arrayXml;
 }
 public function provideFullConfiguration()
 {
     $yaml = Yaml::parse(__DIR__ . '/Fixtures/config/yml/full.yml');
     $yaml = $yaml['doctrine_mongodb'];
     $xml = XmlUtils::loadFile(__DIR__ . '/Fixtures/config/xml/full.xml');
     $xml = XmlUtils::convertDomElementToArray($xml->getElementsByTagName('config')->item(0));
     return array(array($yaml), array($xml));
 }
 /**
  * Lee el contenido de un fichero XML.
  *
  * @param string $type The resource type
  * @return array.
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     try {
         $dom = XmlUtils::loadFile($path);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
     }
     $arrayXml = XmlUtils::convertDomElementToArray($dom->documentElement);
     return $arrayXml;
 }
 /**
  * Converts a \DomElement object to a PHP array.
  *
  * The following rules applies during the conversion:
  *
  *  * Each tag is converted to a key value or an array
  *    if there is more than one "value"
  *
  *  * The content of a tag is set under a "value" key (<foo>bar</foo>)
  *    if the tag also has some nested tags
  *
  *  * The attributes are converted to keys (<foo foo="bar"/>)
  *
  *  * The nested-tags are converted to keys (<foo><foo>bar</foo></foo>)
  *
  * @param \DomElement $element A \DomElement instance
  *
  * @return array A PHP array
  */
 public static function convertDomElementToArray(\DomElement $element)
 {
     return XmlUtils::convertDomElementToArray($element);
 }
예제 #5
0
 /**
  * @dataProvider getDataForConvertDomToArray
  */
 public function testConvertDomToArray($expected, $xml, $root = false, $checkPrefix = true)
 {
     $dom = new \DOMDocument();
     $dom->loadXML($root ? $xml : '<root>' . $xml . '</root>');
     $this->assertSame($expected, XmlUtils::convertDomElementToArray($dom->documentElement, $checkPrefix));
 }
 /**
  * Obtiene un arreglo de excepciones dado un path del fichero de excepciones y el formato  con su traducción.
  *
  * @param $file
  * @param $extension
  * @return mixed
  */
 public function obtener($file, $extension)
 {
     if ($extension == 'yml') {
         $trasDir = str_replace("config" . DIRECTORY_SEPARATOR . "excepciones.yml", "translations", $file);
         $traducciones = $this->getTranslationByRoute($trasDir);
         $values = Yaml::parse($file);
         $respuesta = $this->getExceptionsWithTrans($traducciones, $values['excepciones']);
         return $respuesta;
     } else {
         if ($extension == 'xml') {
             $trasDir = str_replace("config" . DIRECTORY_SEPARATOR . "excepciones.xml", "translations", $file);
             $traducciones = $this->getTranslationByRoute($trasDir);
             $xml = XmlUtils::loadFile($file);
             $values = XmlUtils::convertDomElementToArray($xml->documentElement);
             $respuesta = $this->getExceptionsWithTrans($traducciones, $values);
             return $respuesta;
         }
     }
     return false;
 }
 public function provideExceptionConfiguration()
 {
     $yaml = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/config/yml/exception.yml'));
     $yaml = $yaml['doctrine_mongodb'];
     $xml = XmlUtils::loadFile(__DIR__ . '/Fixtures/config/xml/exception.xml');
     $xml = XmlUtils::convertDomElementToArray($xml->getElementsByTagName('config')->item(0));
     return [[$yaml], [$xml]];
 }