当前位置: 首页>>代码示例>>PHP>>正文


PHP XmlUtils::loadFile方法代码示例

本文整理汇总了PHP中Symfony\Component\Config\Util\XmlUtils::loadFile方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlUtils::loadFile方法的具体用法?PHP XmlUtils::loadFile怎么用?PHP XmlUtils::loadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Config\Util\XmlUtils的用法示例。


在下文中一共展示了XmlUtils::loadFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     try {
         $dom = XmlUtils::loadFile($resource);
     } catch (\InvalidArgumentException $e) {
         throw new InvalidResourceException(sprintf('Unable to load "%s".', $resource), $e->getCode(), $e);
     }
     $internalErrors = libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xpath = new \DOMXPath($dom);
     $nodes = $xpath->evaluate('//TS/context/name[text()="' . $domain . '"]');
     $catalogue = new MessageCatalogue($locale);
     if ($nodes->length == 1) {
         $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message');
         foreach ($translations as $translation) {
             $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue;
             if (!empty($translationValue)) {
                 $catalogue->set((string) $translation->getElementsByTagName('source')->item(0)->nodeValue, $translationValue, $domain);
             }
             $translation = $translation->nextSibling;
         }
         $catalogue->addResource(new FileResource($resource));
     }
     libxml_use_internal_errors($internalErrors);
     return $catalogue;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:37,代码来源:QtFileLoader.php

示例2: parseFile

 /**
  * Validates and parses the given file into a SimpleXMLElement
  *
  * @param string $file
  *
  * @throws \RuntimeException
  *
  * @return \SimpleXMLElement
  *
  * @throws InvalidResourceException
  */
 private function parseFile($file)
 {
     try {
         $dom = XmlUtils::loadFile($file);
     } catch (\InvalidArgumentException $e) {
         throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $file, $e->getMessage()), $e->getCode(), $e);
     }
     $internalErrors = libxml_use_internal_errors(true);
     $location = str_replace('\\', '/', __DIR__) . '/schema/dic/xliff-core/xml.xsd';
     $parts = explode('/', $location);
     if (0 === stripos($location, 'phar://')) {
         $tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
         if ($tmpfile) {
             copy($location, $tmpfile);
             $parts = explode('/', str_replace('\\', '/', $tmpfile));
         }
     }
     $drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts) . '/' : '';
     $location = 'file:///' . $drive . implode('/', array_map('rawurlencode', $parts));
     $source = file_get_contents(__DIR__ . '/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
     $source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);
     if (!@$dom->schemaValidateSource($source)) {
         throw new InvalidResourceException(implode("\n", $this->getXmlErrors($internalErrors)));
     }
     $dom->normalizeDocument();
     libxml_clear_errors();
     libxml_use_internal_errors($internalErrors);
     return array(simplexml_import_dom($dom), strtoupper($dom->encoding));
 }
开发者ID:peintune,项目名称:Ternado,代码行数:40,代码来源:XliffFileLoader.php

示例3: load

 /**
  * 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;
 }
开发者ID:bosonsymfony,项目名称:excepciones-bundle,代码行数:15,代码来源:XmlFileLoader.php

示例4: provideFullConfiguration

 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));
 }
开发者ID:Wizkunde,项目名称:DoctrineMongoDBBundle,代码行数:8,代码来源:ConfigurationTest.php

示例5: loadFile

 /**
  * Loads internal.
  *
  * @param string $file
  *
  * @return \SimpleXMLElement
  */
 protected function loadFile($file)
 {
     try {
         $dom = XmlUtils::loadFile($file);
     } catch (\Exception $e) {
         throw new \Exception(sprintf('Unable to parse file "%s".', $file), $e->getCode());
     }
     return simplexml_import_dom($dom);
 }
开发者ID:yahoojapan,项目名称:ConfigCacheBundle,代码行数:16,代码来源:XmlFileLoader.php

示例6: parseFile

 /**
  * Parses a XML File.
  *
  * @param string $file Path of file
  *
  * @return \SimpleXMLElement
  *
  * @throws MappingException
  */
 private function parseFile($file)
 {
     try {
         $dom = XmlUtils::loadFile($file, __DIR__ . '/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd');
     } catch (\Exception $e) {
         throw new MappingException($e->getMessage(), $e->getCode(), $e);
     }
     return simplexml_import_dom($dom);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:18,代码来源:XmlFileLoader.php

示例7: load

 /**
  * 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;
 }
开发者ID:bosonsymfony,项目名称:excepciones-bundle,代码行数:17,代码来源:XmlFileReader.php

示例8: extractPath

 /**
  * {@inheritdoc}
  */
 protected function extractPath(string $path)
 {
     try {
         $xml = simplexml_import_dom(XmlUtils::loadFile($path, self::RESOURCE_SCHEMA));
     } catch (\InvalidArgumentException $e) {
         throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
     }
     foreach ($xml->resource as $resource) {
         $resourceClass = (string) $resource['class'];
         $this->resources[$resourceClass] = ['shortName' => $this->phpize($resource, 'shortName', 'string'), 'description' => $this->phpize($resource, 'description', 'string'), 'iri' => $this->phpize($resource, 'iri', 'string'), 'itemOperations' => $this->getAttributes($resource, 'itemOperation') ?: null, 'collectionOperations' => $this->getAttributes($resource, 'collectionOperation') ?: null, 'attributes' => $this->getAttributes($resource, 'attribute') ?: null, 'properties' => $this->getProperties($resource) ?: null];
     }
 }
开发者ID:api-platform,项目名称:core,代码行数:15,代码来源:XmlExtractor.php

示例9: loadMetadataFromFile

 /**
  * {@inheritdoc}
  */
 protected function loadMetadataFromFile(\ReflectionClass $class, $file)
 {
     $classMetadata = new MergeableClassMetadata($class->getName());
     // load xml file
     // TODO xsd validation
     $xmlDoc = XmlUtils::loadFile($file);
     $xpath = new \DOMXPath($xmlDoc);
     $xpath->registerNamespace('x', 'http://schemas.sulu.io/class/general');
     $xpath->registerNamespace('list', 'http://schemas.sulu.io/class/list');
     foreach ($xpath->query('/x:class/x:properties/x:*') as $propertyNode) {
         $classMetadata->addPropertyMetadata($this->getPropertyMetadata($xpath, $propertyNode, $class->getName()));
     }
     return $classMetadata;
 }
开发者ID:sulu,项目名称:sulu,代码行数:17,代码来源:XmlDriver.php

示例10: supports

 /**
  * {@inheritdoc}
  */
 public function supports($resource, $type = null)
 {
     if (!is_string($resource) || 'xml' !== pathinfo($resource, PATHINFO_EXTENSION)) {
         return false;
     }
     $document = XmlUtils::loadFile($resource);
     $namespaces = $document->documentElement->attributes->getNamedItem('schemaLocation')->nodeValue;
     $start = strpos($namespaces, static::SCHEMA_IDENTIFIER) + strlen(static::SCHEMA_IDENTIFIER) + 1;
     $namespace = substr($namespaces, $start);
     $end = strpos($namespace, ' ');
     if ($end !== false) {
         $namespace = substr($namespace, 0, $end);
     }
     return $namespace === static::SCHEMA_URI;
 }
开发者ID:sulu,项目名称:sulu,代码行数:18,代码来源:BaseXmlFileLoader.php

示例11: extract

 private function extract($resource, MessageCatalogue $catalogue, $domain)
 {
     try {
         $dom = XmlUtils::loadFile($resource);
     } catch (\InvalidArgumentException $e) {
         throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $resource, $e->getMessage()), $e->getCode(), $e);
     }
     $xliffVersion = $this->getVersionNumber($dom);
     $this->validateSchema($xliffVersion, $dom, $this->getSchema($xliffVersion));
     if ('1.2' === $xliffVersion) {
         $this->extractXliff1($dom, $catalogue, $domain);
     }
     if ('2.0' === $xliffVersion) {
         $this->extractXliff2($dom, $catalogue, $domain);
     }
 }
开发者ID:ayoah,项目名称:symfony,代码行数:16,代码来源:XliffFileLoader.php

示例12: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = 'page')
 {
     // init running vars
     $tags = [];
     $schemaPath = __DIR__ . static::SCHEME_PATH;
     // read file
     $xmlDocument = XmlUtils::loadFile($resource, function (\DOMDocument $dom) use($resource, $schemaPath) {
         $dom->documentURI = $resource;
         $dom->xinclude();
         return @$dom->schemaValidate($schemaPath);
     });
     // generate xpath for file
     $xpath = new \DOMXPath($xmlDocument);
     $xpath->registerNamespace('x', 'http://schemas.sulu.io/template/template');
     // init result
     $result = $this->loadTemplateAttributes($resource, $xpath, $type);
     // load properties
     $result['properties'] = $this->loadProperties($result['key'], '/x:template/x:properties/x:*', $tags, $xpath);
     // check if required properties are existing
     foreach ($this->requiredPropertyNames as $requiredPropertyName) {
         $requiredPropertyNameFound = false;
         if (array_key_exists($requiredPropertyName, $result['properties'])) {
             $requiredPropertyNameFound = true;
         }
         // check all section properties as well
         foreach ($result['properties'] as $property) {
             if (!$requiredPropertyNameFound && $property['type'] == 'section' && array_key_exists($requiredPropertyName, $property['properties'])) {
                 $requiredPropertyNameFound = true;
             }
         }
         if (!$requiredPropertyNameFound) {
             throw new RequiredPropertyNameNotFoundException($result['key'], $requiredPropertyName);
         }
     }
     // FIXME until excerpt-template is no page template anymore
     // - https://github.com/sulu-io/sulu/issues/1220#issuecomment-110704259
     if (!array_key_exists('internal', $result) || !$result['internal']) {
         if (isset($this->requiredTagNames[$type])) {
             foreach ($this->requiredTagNames[$type] as $requiredTagName) {
                 if (!array_key_exists($requiredTagName, $tags)) {
                     throw new RequiredTagNotFoundException($result['key'], $requiredTagName);
                 }
             }
         }
     }
     return $result;
 }
开发者ID:sulu,项目名称:sulu,代码行数:50,代码来源:XmlLegacyLoader.php

示例13: parseXml

 private function parseXml($path)
 {
     // load xml file
     $xmlDoc = XmlUtils::loadFile($path);
     $xpath = new \DOMXPath($xmlDoc);
     $result = [];
     foreach ($xpath->query('/replacers/item') as $node) {
         $locale = strtolower($xpath->query('column[@name="locale"]', $node)->item(0)->nodeValue);
         $from = $xpath->query('column[@name="from"]', $node)->item(0)->nodeValue;
         $to = $xpath->query('column[@name="to"]', $node)->item(0)->nodeValue;
         if (!isset($result[$locale])) {
             $result[$locale] = [];
         }
         $result[$locale][$from] = $to;
     }
     return $result;
 }
开发者ID:ollietb,项目名称:sulu,代码行数:17,代码来源:ReplacerXmlLoader.php

示例14: import

 public function import($fileName)
 {
     $this->handleSession($this->session, $fileName);
     $this->handleSession($this->liveSession, $fileName);
     $doc = XmlUtils::loadFile($fileName);
     $xpath = new \DOMXPath($doc);
     $xpath->registerNamespace('sv', 'http://www.jcp.org/jcr/sv/1.0');
     $data = [];
     /** @var \DOMNode $node */
     foreach ($xpath->query('//sv:value[text()="sulu:page"]/../..') as $node) {
         $parent = $node;
         $path = '';
         do {
             $path = '/' . XmlUtil::getValueFromXPath('@sv:name', $xpath, $parent) . $path;
             $parent = $parent->parentNode;
         } while (XmlUtil::getValueFromXPath('@sv:name', $xpath, $parent) !== 'contents');
         $data[] = ['id' => XmlUtil::getValueFromXPath('sv:property[@sv:name="jcr:uuid"]/sv:value', $xpath, $node), 'path' => $path, 'title' => XmlUtil::getValueFromXPath('sv:property[@sv:name="i18n:en-title"]/sv:value', $xpath, $node), 'template' => XmlUtil::getValueFromXPath('sv:property[@sv:name="i18n:en-template"]/sv:value', $xpath, $node), 'url' => XmlUtil::getValueFromXPath('sv:property[@sv:name="i18n:en-url"]/sv:value', $xpath, $node), 'article' => XmlUtil::getValueFromXPath('sv:property[@sv:name="i18n:en-article"]/sv:value', $xpath, $node)];
     }
     return $data;
 }
开发者ID:sulu,项目名称:sulu,代码行数:20,代码来源:PHPCRImporter.php

示例15: load

 /**
  * Loads an XML File.
  *
  * @param string      $path An XML file path
  * @param string|null $type
  *
  * @return MappingData[]
  *
  * @throws \InvalidArgumentException When the $file cannot be parsed
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     if (!stream_is_local($path)) {
         throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
     }
     if (!file_exists($path)) {
         throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
     }
     // empty file
     if ('' === trim(file_get_contents($path))) {
         return;
     }
     $xml = XmlUtils::loadFile($path, __DIR__ . static::SCHEMA_FILE);
     $metadatas = array();
     foreach ($xml->documentElement->getElementsByTagNameNS(self::NAMESPACE_URI, 'mapping') as $mappingNode) {
         $metadatas[] = $this->parseMappingNode($mappingNode, $path);
     }
     return $metadatas;
 }
开发者ID:viral810,项目名称:ngSimpleCMS,代码行数:30,代码来源:XmlFileLoader.php


注:本文中的Symfony\Component\Config\Util\XmlUtils::loadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。