private function parseDefinition(\DOMElement $service, $file)
{
if ($alias = $service->getAttribute('alias')) {
+ $this->validateAlias($service, $file);
+
$public = true;
if ($publicAttr = $service->getAttribute('public')) {
$public = XmlUtils::phpize($publicAttr);
$definition = new Definition();
}
- foreach (array('class', 'shared', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) {
+ foreach (array('class', 'shared', 'public', '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 of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
- }
- $method = 'set'.str_replace('-', '', $key);
+ $method = 'set'.$key;
$definition->$method(XmlUtils::phpize($value));
}
}
$definition->setAutowired(XmlUtils::phpize($value));
}
- if ($value = $service->getAttribute('scope')) {
- $triggerDeprecation = 'request' !== (string) $service->getAttribute('id');
-
- if ($triggerDeprecation) {
- @trigger_error(sprintf('The "scope" attribute of service "%s" in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
- }
-
- $definition->setScope(XmlUtils::phpize($value), false);
- }
-
- if ($value = $service->getAttribute('synchronized')) {
- $triggerDeprecation = 'request' !== (string) $service->getAttribute('id');
-
- if ($triggerDeprecation) {
- @trigger_error(sprintf('The "synchronized" attribute of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
- }
-
- $definition->setSynchronized(XmlUtils::phpize($value), $triggerDeprecation);
- }
-
if ($files = $this->getChildren($service, 'file')) {
$definition->setFile($files[0]->nodeValue);
}
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);
+ $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
} else {
$class = $factory->getAttribute('class');
}
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);
+ $class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
} else {
$class = $configurator->getAttribute('class');
}
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
+ // keep not normalized key
$parameters[$name] = XmlUtils::phpize($node->nodeValue);
}
// resolve definitions
krsort($definitions);
- foreach ($definitions as $id => $def) {
- list($domElement, $file, $wild) = $def;
-
+ foreach ($definitions as $id => list($domElement, $file, $wild)) {
if (null !== $definition = $this->parseDefinition($domElement, $file)) {
$this->container->setDefinition($id, $definition);
}
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
}
- if ($strict = $arg->getAttribute('strict')) {
- $strict = XmlUtils::phpize($strict);
- } else {
- $strict = true;
- }
-
- $arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior, $strict);
+ $arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior);
break;
case 'expression':
$arguments[$key] = new Expression($arg->nodeValue);
return $valid;
}
+ /**
+ * Validates an alias.
+ *
+ * @param \DOMElement $alias
+ * @param string $file
+ */
+ private function validateAlias(\DOMElement $alias, $file)
+ {
+ foreach ($alias->attributes as $name => $node) {
+ if (!in_array($name, array('alias', 'id', 'public'))) {
+ @trigger_error(sprintf('Using the attribute "%s" is deprecated for the service "%s" which is defined as an alias in "%s". Allowed attributes for service aliases are "alias", "id" and "public". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $name, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
+ }
+ }
+
+ foreach ($alias->childNodes as $child) {
+ if ($child instanceof \DOMElement && $child->namespaceURI === self::NS) {
+ @trigger_error(sprintf('Using the element "%s" is deprecated for the service "%s" which is defined as an alias in "%s". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported elements.', $child->localName, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
+ }
+ }
+ }
+
/**
* Validates an extension.
*