Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Serializer/Mapping/Loader/XmlFileLoader.php
Строк: 65
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentSerializerMappingLoader;

use 
SymfonyComponentConfigUtilXmlUtils;
use 
SymfonyComponentSerializerExceptionMappingException;
use 
SymfonyComponentSerializerMappingClassMetadata;

/**
 * Loads XML mapping files.
 *
 * @author Kévin Dunglas <dunglas@gmail.com>
 */
class XmlFileLoader extends FileLoader
{
    
/**
     * An array of SimpleXMLElement instances.
     *
     * @var SimpleXMLElement[]|null
     */
    
private $classes;

    
/**
     * {@inheritdoc}
     */
    
public function loadClassMetadata(ClassMetadata $metadata)
    {
        if (
null === $this->classes) {
            
$this->classes = array();
            
$xml $this->parseFile($this->file);

            foreach (
$xml->class as $class) {
                
$this->classes[(string) $class['name']] = $class;
            }
        }

        if (isset(
$this->classes[$metadata->getClassName()])) {
            
$xml $this->classes[$metadata->getClassName()];

            foreach (
$xml->attribute as $attribute) {
                foreach (
$attribute->group as $group) {
                    
$metadata->addAttributeGroup((string) $attribute['name'], (string) $group);
                }
            }

            return 
true;
        }

        return 
false;
    }

    
/**
     * Parse 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);
    }
}
Онлайн: 4
Реклама