Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -28,6 +28,7 @@ class AutowirePass implements CompilerPassInterface
private $definedTypes = array();
private $types;
private $notGuessableTypes = array();
private $autowired = array();
/**
* {@inheritdoc}
@ -56,6 +57,7 @@ class AutowirePass implements CompilerPassInterface
$this->definedTypes = array();
$this->types = null;
$this->notGuessableTypes = array();
$this->autowired = array();
if (isset($e)) {
throw $e;
@ -72,6 +74,10 @@ class AutowirePass implements CompilerPassInterface
*/
private function completeDefinition($id, Definition $definition)
{
if ($definition->getFactory() || $definition->getFactoryClass(false) || $definition->getFactoryService(false)) {
throw new RuntimeException(sprintf('Service "%s" can use either autowiring or a factory, not both.', $id));
}
if (!$reflectionClass = $this->getReflectionClass($id, $definition)) {
return;
}
@ -81,15 +87,23 @@ class AutowirePass implements CompilerPassInterface
if (!$constructor = $reflectionClass->getConstructor()) {
return;
}
$parameters = $constructor->getParameters();
if (method_exists('ReflectionMethod', 'isVariadic') && $constructor->isVariadic()) {
array_pop($parameters);
}
$arguments = $definition->getArguments();
foreach ($constructor->getParameters() as $index => $parameter) {
foreach ($parameters as $index => $parameter) {
if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
continue;
}
try {
if (!$typeHint = $parameter->getClass()) {
if (isset($arguments[$index])) {
continue;
}
// no default value? Then fail
if (!$parameter->isOptional()) {
throw new RuntimeException(sprintf('Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.', $index, $parameter->name, $id));
@ -101,6 +115,10 @@ class AutowirePass implements CompilerPassInterface
continue;
}
if (isset($this->autowired[$typeHint->name])) {
return $this->autowired[$typeHint->name] ? new Reference($this->autowired[$typeHint->name]) : null;
}
if (null === $this->types) {
$this->populateAvailableTypes();
}
@ -111,13 +129,14 @@ class AutowirePass implements CompilerPassInterface
try {
$value = $this->createAutowiredDefinition($typeHint, $id);
} catch (RuntimeException $e) {
if ($parameter->allowsNull()) {
$value = null;
} elseif ($parameter->isDefaultValueAvailable()) {
if ($parameter->isDefaultValueAvailable()) {
$value = $parameter->getDefaultValue();
} elseif ($parameter->allowsNull()) {
$value = null;
} else {
throw $e;
}
$this->autowired[$typeHint->name] = false;
}
}
} catch (\ReflectionException $e) {
@ -133,6 +152,16 @@ class AutowirePass implements CompilerPassInterface
$arguments[$index] = $value;
}
if ($parameters && !isset($arguments[++$index])) {
while (0 <= --$index) {
$parameter = $parameters[$index];
if (!$parameter->isDefaultValueAvailable() || $parameter->getDefaultValue() !== $arguments[$index]) {
break;
}
unset($arguments[$index]);
}
}
// it's possible index 1 was set, then index 0, then 2, etc
// make sure that we re-order so they're injected as expected
ksort($arguments);
@ -167,6 +196,7 @@ class AutowirePass implements CompilerPassInterface
foreach ($definition->getAutowiringTypes() as $type) {
$this->definedTypes[$type] = true;
$this->types[$type] = $id;
unset($this->notGuessableTypes[$type]);
}
if (!$reflectionClass = $this->getReflectionClass($id, $definition)) {
@ -236,13 +266,11 @@ class AutowirePass implements CompilerPassInterface
throw new RuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeHint->name, $id, $classOrInterface));
}
$argumentId = sprintf('autowired.%s', $typeHint->name);
$this->autowired[$typeHint->name] = $argumentId = sprintf('autowired.%s', $typeHint->name);
$argumentDefinition = $this->container->register($argumentId, $typeHint->name);
$argumentDefinition->setPublic(false);
$this->populateAvailableType($argumentId, $argumentDefinition);
try {
$this->completeDefinition($argumentId, $argumentDefinition);
} catch (RuntimeException $e) {

View file

@ -60,7 +60,6 @@ class CheckCircularReferencesPass implements CompilerPassInterface
$id = $node->getId();
if (empty($this->checkedNodes[$id])) {
// don't check circular dependencies for lazy services
if (!$node->getValue() || !$node->getValue()->isLazy()) {
$searchKey = array_search($id, $this->currentPath);

View file

@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
/**
@ -47,6 +48,9 @@ class MergeExtensionConfigurationPass implements CompilerPassInterface
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->setResourceTracking($container->isTrackingResources());
$tmpContainer->addObjectResource($extension);
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
$tmpContainer->addObjectResource($configuration);
}
foreach ($exprLangProviders as $provider) {
$tmpContainer->addExpressionLanguageProvider($provider);

View file

@ -51,7 +51,7 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
if (isset($replacements[$targetId])) {
$container->setAlias($definitionId, $replacements[$targetId]);
}
// No neeed to process the same target twice
// No need to process the same target twice
if (isset($seenAliasTargets[$targetId])) {
continue;
}

View file

@ -26,6 +26,7 @@ use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
@ -73,7 +74,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
private $compiler;
private $trackResources = true;
private $trackResources;
/**
* @var InstantiatorInterface|null
@ -90,6 +91,13 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
private $expressionLanguageProviders = array();
public function __construct(ParameterBagInterface $parameterBag = null)
{
parent::__construct($parameterBag);
$this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface');
}
/**
* @var string[] with tag names used by findTaggedServiceIds
*/

View file

@ -164,7 +164,7 @@ class Definition
}
/**
* Gets the service that decorates this service.
* Gets the service that this service is decorating.
*
* @return null|array An array composed of the decorated service id, the new id for it and the priority of decoration, null if no service is decorated
*/
@ -308,6 +308,10 @@ class Definition
*/
public function replaceArgument($index, $argument)
{
if (0 === count($this->arguments)) {
throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.');
}
if ($index < 0 || $index > count($this->arguments) - 1) {
throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
}

View file

@ -628,7 +628,7 @@ EOF;
}
if ($definition->isAutowired()) {
$doc = <<<EOF
$doc .= <<<EOF
*
* This service is autowired.
@ -1029,11 +1029,7 @@ EOF;
private function addAliases()
{
if (!$aliases = $this->container->getAliases()) {
if ($this->container->isFrozen()) {
return "\n \$this->aliases = array();\n";
} else {
return '';
}
return $this->container->isFrozen() ? "\n \$this->aliases = array();\n" : '';
}
$code = " \$this->aliases = array(\n";
@ -1402,9 +1398,9 @@ EOF;
$service = $this->dumpValue($value->getFactoryService(false));
return sprintf('%s->%s(%s)', 0 === strpos($service, '$') ? sprintf('$this->get(%s)', $service) : $this->getServiceCall($value->getFactoryService(false)), $value->getFactoryMethod(false), implode(', ', $arguments));
} else {
throw new RuntimeException('Cannot dump definitions which have factory method without factory service or factory class.');
}
throw new RuntimeException('Cannot dump definitions which have factory method without factory service or factory class.');
}
$class = $value->getClass();
@ -1442,9 +1438,9 @@ EOF;
}
} elseif (is_object($value) || is_resource($value)) {
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
} else {
return $this->export($value);
}
return $this->export($value);
}
/**
@ -1513,13 +1509,13 @@ EOF;
if (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id);
} else {
if ($this->container->hasAlias($id)) {
$id = (string) $this->container->getAlias($id);
}
return sprintf('$this->get(\'%s\')', $id);
}
if ($this->container->hasAlias($id)) {
$id = (string) $this->container->getAlias($id);
}
return sprintf('$this->get(\'%s\')', $id);
}
/**

View file

@ -85,7 +85,7 @@ class YamlFileLoader extends FileLoader
* @param array $content
* @param string $file
*/
private function parseImports($content, $file)
private function parseImports(array $content, $file)
{
if (!isset($content['imports'])) {
return;
@ -112,7 +112,7 @@ class YamlFileLoader extends FileLoader
* @param array $content
* @param string $file
*/
private function parseDefinitions($content, $file)
private function parseDefinitions(array $content, $file)
{
if (!isset($content['services'])) {
return;
@ -130,9 +130,9 @@ class YamlFileLoader extends FileLoader
/**
* Parses a definition.
*
* @param string $id
* @param array $service
* @param string $file
* @param string $id
* @param array|string $service
* @param string $file
*
* @throws InvalidArgumentException When tags are invalid
*/
@ -353,7 +353,7 @@ class YamlFileLoader extends FileLoader
}
if (!file_exists($file)) {
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
}
if (null === $this->yamlParser) {
@ -454,7 +454,7 @@ class YamlFileLoader extends FileLoader
*
* @param array $content
*/
private function loadFromExtensions($content)
private function loadFromExtensions(array $content)
{
foreach ($content as $namespace => $values) {
if (in_array($namespace, array('imports', 'parameters', 'services'))) {