class XmlFileLoader in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/routing/Loader/XmlFileLoader.php \Symfony\Component\Routing\Loader\XmlFileLoader
- 8 vendor/symfony/dependency-injection/Loader/XmlFileLoader.php \Symfony\Component\DependencyInjection\Loader\XmlFileLoader
- 8 vendor/symfony/validator/Mapping/Loader/XmlFileLoader.php \Symfony\Component\Validator\Mapping\Loader\XmlFileLoader
- 8 vendor/symfony/serializer/Mapping/Loader/XmlFileLoader.php \Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader
Same name and namespace in other branches
- 8.0 vendor/symfony/serializer/Mapping/Loader/XmlFileLoader.php \Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader
Loads XML mapping files.
@author Kévin Dunglas <dunglas@gmail.com>
Hierarchy
- class \Symfony\Component\Serializer\Mapping\Loader\FileLoader implements LoaderInterface
- class \Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader
Expanded class hierarchy of XmlFileLoader
1 file declares its use of XmlFileLoader
- XmlFileLoaderTest.php in vendor/
symfony/ serializer/ Tests/ Mapping/ Loader/ XmlFileLoaderTest.php
File
- vendor/
symfony/ serializer/ Mapping/ Loader/ XmlFileLoader.php, line 24
Namespace
Symfony\Component\Serializer\Mapping\LoaderView source
class XmlFileLoader extends FileLoader {
/**
* An array of {@class \SimpleXMLElement} instances.
*
* @var \SimpleXMLElement[]|null
*/
private $classes;
/**
* {@inheritdoc}
*/
public function loadClassMetadata(ClassMetadataInterface $classMetadata) {
if (null === $this->classes) {
$this->classes = array();
$xml = $this
->parseFile($this->file);
foreach ($xml->class as $class) {
$this->classes[(string) $class['name']] = $class;
}
}
$attributesMetadata = $classMetadata
->getAttributesMetadata();
if (isset($this->classes[$classMetadata
->getName()])) {
$xml = $this->classes[$classMetadata
->getName()];
foreach ($xml->attribute as $attribute) {
$attributeName = (string) $attribute['name'];
if (isset($attributesMetadata[$attributeName])) {
$attributeMetadata = $attributesMetadata[$attributeName];
}
else {
$attributeMetadata = new AttributeMetadata($attributeName);
$classMetadata
->addAttributeMetadata($attributeMetadata);
}
foreach ($attribute->group as $group) {
$attributeMetadata
->addGroup((string) $group);
}
}
return true;
}
return false;
}
/**
* 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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileLoader:: |
protected | property | ||
FileLoader:: |
public | function | Constructor. | |
XmlFileLoader:: |
private | property | An array of {@class \SimpleXMLElement} instances. | |
XmlFileLoader:: |
public | function |
Load class metadata. Overrides LoaderInterface:: |
|
XmlFileLoader:: |
private | function | Parses a XML File. |