private function XmlFileLoader::parseDefinition in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php \Symfony\Component\DependencyInjection\Loader\XmlFileLoader::parseDefinition()
Parses an individual Definition.
Parameters
\DOMElement $service:
string $file:
Return value
Definition|null
2 calls to XmlFileLoader::parseDefinition()
- XmlFileLoader::parseDefinitions in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Loader/ XmlFileLoader.php - Parses multiple definitions.
- XmlFileLoader::processAnonymousServices in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Loader/ XmlFileLoader.php - Processes anonymous services.
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Loader/ XmlFileLoader.php, line 133
Class
- XmlFileLoader
- XmlFileLoader loads XML files service definitions.
Namespace
Symfony\Component\DependencyInjection\LoaderCode
private function parseDefinition(\DOMElement $service, $file) {
if ($alias = $service
->getAttribute('alias')) {
$public = true;
if ($publicAttr = $service
->getAttribute('public')) {
$public = XmlUtils::phpize($publicAttr);
}
$this->container
->setAlias((string) $service
->getAttribute('id'), new Alias($alias, $public));
return;
}
if ($parent = $service
->getAttribute('parent')) {
$definition = new DefinitionDecorator($parent);
}
else {
$definition = new Definition();
}
foreach (array(
'class',
'scope',
'public',
'factory-class',
'factory-method',
'factory-service',
'synthetic',
'lazy',
'abstract',
) as $key) {
if ($value = $service
->getAttribute($key)) {
if (in_array($key, array(
'factory-class',
'factory-method',
'factory-service',
))) {
trigger_error(sprintf('The "%s" attribute in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, $file), E_USER_DEPRECATED);
}
$method = 'set' . str_replace('-', '', $key);
$definition
->{$method}(XmlUtils::phpize($value));
}
}
if ($value = $service
->getAttribute('synchronized')) {
$triggerDeprecation = 'request' !== (string) $service
->getAttribute('id');
if ($triggerDeprecation) {
trigger_error(sprintf('The "synchronized" attribute in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $file), E_USER_DEPRECATED);
}
$definition
->setSynchronized(XmlUtils::phpize($value), $triggerDeprecation);
}
if ($files = $this
->getChildren($service, 'file')) {
$definition
->setFile($files[0]->nodeValue);
}
$definition
->setArguments($this
->getArgumentsAsPhp($service, 'argument'));
$definition
->setProperties($this
->getArgumentsAsPhp($service, 'property'));
if ($factories = $this
->getChildren($service, 'factory')) {
$factory = $factories[0];
if ($function = $factory
->getAttribute('function')) {
$definition
->setFactory($function);
}
else {
$factoryService = $this
->getChildren($factory, 'service');
if (isset($factoryService[0])) {
$class = $this
->parseDefinition($factoryService[0], $file);
}
elseif ($childService = $factory
->getAttribute('service')) {
$class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
}
else {
$class = $factory
->getAttribute('class');
}
$definition
->setFactory(array(
$class,
$factory
->getAttribute('method'),
));
}
}
if ($configurators = $this
->getChildren($service, 'configurator')) {
$configurator = $configurators[0];
if ($function = $configurator
->getAttribute('function')) {
$definition
->setConfigurator($function);
}
else {
$configuratorService = $this
->getChildren($configurator, 'service');
if (isset($configuratorService[0])) {
$class = $this
->parseDefinition($configuratorService[0], $file);
}
elseif ($childService = $configurator
->getAttribute('service')) {
$class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
}
else {
$class = $configurator
->getAttribute('class');
}
$definition
->setConfigurator(array(
$class,
$configurator
->getAttribute('method'),
));
}
}
foreach ($this
->getChildren($service, 'call') as $call) {
$definition
->addMethodCall($call
->getAttribute('method'), $this
->getArgumentsAsPhp($call, 'argument'));
}
foreach ($this
->getChildren($service, 'tag') as $tag) {
$parameters = array();
foreach ($tag->attributes as $name => $node) {
if ('name' === $name) {
continue;
}
if (false !== strpos($name, '-') && false === strpos($name, '_') && !array_key_exists($normalizedName = str_replace('-', '_', $name), $parameters)) {
$parameters[$normalizedName] = XmlUtils::phpize($node->nodeValue);
}
// keep not normalized key for BC too
$parameters[$name] = XmlUtils::phpize($node->nodeValue);
}
$definition
->addTag($tag
->getAttribute('name'), $parameters);
}
if ($value = $service
->getAttribute('decorates')) {
$renameId = $service
->hasAttribute('decoration-inner-name') ? $service
->getAttribute('decoration-inner-name') : null;
$definition
->setDecoratedService($value, $renameId);
}
return $definition;
}