[DI] Remove remaining deprecated features

This commit is contained in:
Nicolas Grekas 2017-07-12 12:01:37 +02:00
parent a55cbf83c0
commit 4bd7b921f4
25 changed files with 40 additions and 944 deletions

View File

@ -19,6 +19,7 @@ CHANGELOG
* Removed absolute template paths support in the template name parser
* Removed support of the `KERNEL_DIR` environment variable with `KernelTestCase::getKernelClass()`.
* Removed the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods.
* Removed the "framework.validation.cache" configuration option. Configure the "cache.validator" service under "framework.cache.pools" instead.
3.4.0
-----

View File

@ -1050,16 +1050,7 @@ class FrameworkExtension extends Extension
}
}
if (isset($config['cache']) && $config['cache']) {
@trigger_error('The "framework.validation.cache" option is deprecated since Symfony 3.2 and will be removed in 4.0. Configure the "cache.validator" service under "framework.cache.pools" instead.', E_USER_DEPRECATED);
$container->setParameter(
'validator.mapping.cache.prefix',
'validator_'.$this->getKernelRootHash($container)
);
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
} elseif (!$container->getParameter('kernel.debug')) {
if (!$container->getParameter('kernel.debug')) {
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference('validator.mapping.cache.symfony')));
}
}

View File

@ -4,6 +4,7 @@ CHANGELOG
4.0.0
-----
* removed autowiring services based on the types they implement
* added a third `$methodName` argument to the `getProxyFactoryCode()` method
of the `DumperInterface`
* removed support for autowiring types
@ -11,6 +12,13 @@ CHANGELOG
* removed support for dumping an ucompiled container in `PhpDumper`
* removed support for generating a dumped `Container` without populating the method map
* removed support for case insensitive service identifiers
* removed the `DefinitionDecorator` class, replaced by `ChildDefinition`
* removed the `AutowireServiceResource` class and related `AutowirePass::createResourceForClass()` method
* removed `LoggingFormatter`, `Compiler::getLoggingFormatter()` and `addLogMessage()` class and methods, use the `ContainerBuilder::log()` method instead
* removed `FactoryReturnTypePass`
* removed `ContainerBuilder::addClassResource()`, use the `addObjectResource()` or the `getReflectionClass()` method instead.
* removed support for top-level anonymous services
* removed silent behavior for unused attributes and elements
3.4.0
-----

View File

@ -121,5 +121,3 @@ class ChildDefinition extends Definition
throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.');
}
}
class_alias(ChildDefinition::class, DefinitionDecorator::class);

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Config\AutowireServiceResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
@ -67,30 +66,6 @@ class AutowirePass extends AbstractRecursivePass
}
}
/**
* Creates a resource to help know if this service has changed.
*
* @param \ReflectionClass $reflectionClass
*
* @return AutowireServiceResource
*
* @deprecated since version 3.3, to be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.
*/
public static function createResourceForClass(\ReflectionClass $reflectionClass)
{
@trigger_error('The '.__METHOD__.'() method is deprecated since version 3.3 and will be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.', E_USER_DEPRECATED);
$metadata = array();
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
if (!$reflectionMethod->isStatic()) {
$metadata[$reflectionMethod->name] = self::getResourceMetadataForMethod($reflectionMethod);
}
}
return new AutowireServiceResource($reflectionClass->name, $reflectionClass->getFileName(), $metadata);
}
/**
* {@inheritdoc}
*/
@ -323,24 +298,15 @@ class AutowirePass extends AbstractRecursivePass
return $reference;
}
if (!$reference->canBeAutoregistered()) {
return;
}
if (null === $this->types) {
$this->populateAvailableTypes();
}
if (isset($this->types[$type])) {
$message = 'Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0.';
if ($aliasSuggestion = $this->getAliasesSuggestionForType($type = $reference->getType(), $deprecationMessage)) {
$message .= ' '.$aliasSuggestion;
} else {
$message .= sprintf(' You should %s the "%s" service to "%s" instead.', isset($this->types[$this->types[$type]]) ? 'alias' : 'rename (or alias)', $this->types[$type], $type);
}
@trigger_error($message, E_USER_DEPRECATED);
return new TypedReference($this->types[$type], $type);
}
if (!$reference->canBeAutoregistered() || isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) {
if (isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) {
return;
}
@ -499,30 +465,6 @@ class AutowirePass extends AbstractRecursivePass
return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message);
}
/**
* @deprecated since version 3.3, to be removed in 4.0.
*/
private static function getResourceMetadataForMethod(\ReflectionMethod $method)
{
$methodArgumentsMetadata = array();
foreach ($method->getParameters() as $parameter) {
try {
$class = $parameter->getClass();
} catch (\ReflectionException $e) {
// type-hint is against a non-existent class
$class = false;
}
$methodArgumentsMetadata[] = array(
'class' => $class,
'isOptional' => $parameter->isOptional(),
'defaultValue' => ($parameter->isOptional() && !$parameter->isVariadic()) ? $parameter->getDefaultValue() : null,
);
}
return $methodArgumentsMetadata;
}
private function getAliasesSuggestionForType($type, $extraContext = null)
{
$aliases = array();

View File

@ -52,24 +52,6 @@ class Compiler
return $this->serviceReferenceGraph;
}
/**
* Returns the logging formatter which can be used by compilation passes.
*
* @return LoggingFormatter
*
* @deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead.
*/
public function getLoggingFormatter()
{
if (null === $this->loggingFormatter) {
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED);
$this->loggingFormatter = new LoggingFormatter();
}
return $this->loggingFormatter;
}
/**
* Adds a pass to the PassConfig.
*
@ -82,20 +64,6 @@ class Compiler
$this->passConfig->addPass($pass, $type, $priority);
}
/**
* Adds a log message.
*
* @param string $string The log message
*
* @deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead.
*/
public function addLogMessage($string)
{
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', __METHOD__), E_USER_DEPRECATED);
$this->log[] = $string;
}
/**
* @final
*/

View File

@ -1,108 +0,0 @@
<?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 Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
/**
* @author Guilhem N. <egetick@gmail.com>
*
* @deprecated since version 3.3, to be removed in 4.0.
*/
class FactoryReturnTypePass implements CompilerPassInterface
{
private $resolveClassPass;
public function __construct(ResolveClassPass $resolveClassPass = null)
{
if (null === $resolveClassPass) {
@trigger_error('The '.__CLASS__.' class is deprecated since version 3.3 and will be removed in 4.0.', E_USER_DEPRECATED);
}
$this->resolveClassPass = $resolveClassPass;
}
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$resolveClassPassChanges = null !== $this->resolveClassPass ? $this->resolveClassPass->getChanges() : array();
foreach ($container->getDefinitions() as $id => $definition) {
$this->updateDefinition($container, $id, $definition, $resolveClassPassChanges);
}
}
private function updateDefinition(ContainerBuilder $container, $id, Definition $definition, array $resolveClassPassChanges, array $previous = array())
{
// circular reference
$lcId = strtolower($id);
if (isset($previous[$lcId])) {
return;
}
$factory = $definition->getFactory();
if (null === $factory || (!isset($resolveClassPassChanges[$lcId]) && null !== $definition->getClass())) {
return;
}
$class = null;
if (is_string($factory)) {
try {
$m = new \ReflectionFunction($factory);
if (false !== $m->getFileName() && file_exists($m->getFileName())) {
$container->fileExists($m->getFileName());
}
} catch (\ReflectionException $e) {
return;
}
} else {
if ($factory[0] instanceof Reference) {
$previous[$lcId] = true;
$factoryDefinition = $container->findDefinition((string) $factory[0]);
$this->updateDefinition($container, $factory[0], $factoryDefinition, $resolveClassPassChanges, $previous);
$class = $factoryDefinition->getClass();
} else {
$class = $factory[0];
}
if (!$m = $container->getReflectionClass($class)) {
return;
}
try {
$m = $m->getMethod($factory[1]);
} catch (\ReflectionException $e) {
return;
}
}
$returnType = $m->getReturnType();
if (null !== $returnType && !$returnType->isBuiltin()) {
$returnType = $returnType->getName();
if (null !== $class) {
$declaringClass = $m->getDeclaringClass()->getName();
if ('self' === strtolower($returnType)) {
$returnType = $declaringClass;
} elseif ('parent' === strtolower($returnType)) {
$returnType = get_parent_class($declaringClass) ?: null;
}
}
if (null !== $returnType && (!isset($resolveClassPassChanges[$lcId]) || $returnType !== $resolveClassPassChanges[$lcId])) {
@trigger_error(sprintf('Relying on its factory\'s return-type to define the class of service "%s" is deprecated since Symfony 3.3 and won\'t work in 4.0. Set the "class" attribute to "%s" on the service definition instead.', $id, $returnType), E_USER_DEPRECATED);
}
$definition->setClass($returnType);
}
}
}

View File

@ -1,54 +0,0 @@
<?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 Symfony\Component\DependencyInjection\Compiler;
@trigger_error('The '.__NAMESPACE__.'\LoggingFormatter class is deprecated since version 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.', E_USER_DEPRECATED);
/**
* Used to format logging messages during the compilation.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @deprecated since version 3.3, to be removed in 4.0. Use the ContainerBuilder::log() method instead.
*/
class LoggingFormatter
{
public function formatRemoveService(CompilerPassInterface $pass, $id, $reason)
{
return $this->format($pass, sprintf('Removed service "%s"; reason: %s.', $id, $reason));
}
public function formatInlineService(CompilerPassInterface $pass, $id, $target)
{
return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target));
}
public function formatUpdateReference(CompilerPassInterface $pass, $serviceId, $oldDestId, $newDestId)
{
return $this->format($pass, sprintf('Changed reference of service "%s" previously pointing to "%s" to "%s".', $serviceId, $oldDestId, $newDestId));
}
public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId)
{
return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId));
}
public function formatUnusedAutowiringPatterns(CompilerPassInterface $pass, $id, array $patterns)
{
return $this->format($pass, sprintf('Autowiring\'s patterns "%s" for service "%s" don\'t match any method.', implode('", "', $patterns), $id));
}
public function format(CompilerPassInterface $pass, $message)
{
return sprintf('%s: %s', get_class($pass), $message);
}
}

View File

@ -41,7 +41,7 @@ class PassConfig
$this->beforeOptimizationPasses = array(
100 => array(
$resolveClassPass = new ResolveClassPass(),
new ResolveClassPass(),
new ResolveInstanceofConditionalsPass(),
),
);
@ -53,7 +53,6 @@ class PassConfig
new DecoratorServicePass(),
new ResolveParameterPlaceHoldersPass(false),
new ResolveFactoryClassPass(),
new FactoryReturnTypePass($resolveClassPass),
new CheckDefinitionValidityPass(),
new RegisterServiceSubscribersPass(),
new ResolveNamedArgumentsPass(),

View File

@ -20,8 +20,6 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
*/
class ResolveClassPass implements CompilerPassInterface
{
private $changes = array();
/**
* {@inheritdoc}
*/
@ -35,22 +33,8 @@ class ResolveClassPass implements CompilerPassInterface
if ($definition instanceof ChildDefinition && !class_exists($id)) {
throw new InvalidArgumentException(sprintf('Service definition "%s" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.', $id));
}
$this->changes[strtolower($id)] = $id;
$definition->setClass($id);
}
}
}
/**
* @internal
*
* @deprecated since 3.3, to be removed in 4.0.
*/
public function getChanges()
{
$changes = $this->changes;
$this->changes = array();
return $changes;
}
}

View File

@ -1,78 +0,0 @@
<?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 Symfony\Component\DependencyInjection\Config;
@trigger_error('The '.__NAMESPACE__.'\AutowireServiceResource class is deprecated since version 3.3 and will be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.', E_USER_DEPRECATED);
use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
/**
* @deprecated since version 3.3, to be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.
*/
class AutowireServiceResource implements SelfCheckingResourceInterface, \Serializable
{
private $class;
private $filePath;
private $autowiringMetadata = array();
public function __construct($class, $path, array $autowiringMetadata)
{
$this->class = $class;
$this->filePath = $path;
$this->autowiringMetadata = $autowiringMetadata;
}
public function isFresh($timestamp)
{
if (!file_exists($this->filePath)) {
return false;
}
// has the file *not* been modified? Definitely fresh
if (@filemtime($this->filePath) <= $timestamp) {
return true;
}
try {
$reflectionClass = new \ReflectionClass($this->class);
} catch (\ReflectionException $e) {
// the class does not exist anymore!
return false;
}
return (array) $this === (array) AutowirePass::createResourceForClass($reflectionClass);
}
public function __toString()
{
return 'service.autowire.'.$this->class;
}
public function serialize()
{
return serialize(array($this->class, $this->filePath, $this->autowiringMetadata));
}
public function unserialize($serialized)
{
list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false));
}
/**
* @deprecated Implemented for compatibility with Symfony 2.8
*/
public function getResource()
{
return $this->filePath;
}
}

View File

@ -316,22 +316,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
return $this;
}
/**
* Adds the given class hierarchy as resources.
*
* @param \ReflectionClass $class
*
* @return $this
*
* @deprecated since version 3.3, to be removed in 4.0. Use addObjectResource() or getReflectionClass() instead.
*/
public function addClassResource(\ReflectionClass $class)
{
@trigger_error('The '.__METHOD__.'() method is deprecated since version 3.3 and will be removed in 4.0. Use the addObjectResource() or the getReflectionClass() method instead.', E_USER_DEPRECATED);
return $this->addObjectResource($class->name);
}
/**
* Retrieves the requested reflection class and registers it for resource tracking.
*

View File

@ -1,29 +0,0 @@
<?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 Symfony\Component\DependencyInjection;
@trigger_error('The '.__NAMESPACE__.'\DefinitionDecorator class is deprecated since version 3.3 and will be removed in 4.0. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead.', E_USER_DEPRECATED);
class_exists(ChildDefinition::class);
if (false) {
/**
* This definition decorates another definition.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @deprecated The DefinitionDecorator class is deprecated since version 3.3 and will be removed in 4.0. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead.
*/
class DefinitionDecorator extends Definition
{
}
}

View File

@ -395,7 +395,7 @@ class XmlFileLoader extends FileLoader
$node->setAttribute('id', $id);
$node->setAttribute('service', $id);
$definitions[$id] = array($services[0], $file, false);
$definitions[$id] = array($services[0], $file);
$services[0]->setAttribute('id', $id);
// anonymous services are always private
@ -408,27 +408,16 @@ class XmlFileLoader extends FileLoader
// anonymous services "in the wild"
if (false !== $nodes = $xpath->query('//container:services/container:service[not(@id)]')) {
foreach ($nodes as $node) {
@trigger_error(sprintf('Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %s at line %d.', $file, $node->getLineNo()), E_USER_DEPRECATED);
// give it a unique name
$id = sprintf('%d_%s', ++$count, hash('sha256', $file));
$node->setAttribute('id', $id);
$definitions[$id] = array($node, $file, true);
throw new InvalidArgumentException(sprintf('Top-level services must have "id" attribute, none found in %s at line %d.', $file, $node->getLineNo()));
}
}
// resolve definitions
uksort($definitions, 'strnatcmp');
foreach (array_reverse($definitions) as $id => list($domElement, $file, $wild)) {
if (null !== $definition = $this->parseDefinition($domElement, $file, $wild ? $defaults : array())) {
foreach (array_reverse($definitions) as $id => list($domElement, $file)) {
if (null !== $definition = $this->parseDefinition($domElement, $file, array())) {
$this->setDefinition($id, $definition);
}
if (true === $wild) {
$tmpDomElement = new \DOMElement('_services', null, self::NS);
$domElement->parentNode->replaceChild($tmpDomElement, $domElement);
$tmpDomElement->setAttribute('id', $id);
}
}
}
@ -481,9 +470,6 @@ class XmlFileLoader extends FileLoader
if (!$arg->getAttribute('id')) {
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="service" has no or empty "id" attribute in "%s".', $name, $file));
}
if ($arg->hasAttribute('strict')) {
@trigger_error(sprintf('The "strict" attribute used when referencing the "%s" service is deprecated since version 3.3 and will be removed in 4.0.', $arg->getAttribute('id')), E_USER_DEPRECATED);
}
$arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior);
break;
@ -619,13 +605,13 @@ EOF
{
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);
throw new InvalidArgumentException(sprintf('Invalid attribute "%s" defined for alias "%s" in "%s".', $name, $alias->getAttribute('id'), $file));
}
}
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);
throw new InvalidArgumentException(sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $alias->getAttribute('id'), $file));
}
}
}

View File

@ -203,7 +203,6 @@
<xsd:attribute name="key" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="on-invalid" type="invalid_sequence" />
<xsd:attribute name="strict" type="boolean" />
</xsd:complexType>
<xsd:complexType name="argument" mixed="true">
@ -216,7 +215,6 @@
<xsd:attribute name="key" type="xsd:string" />
<xsd:attribute name="index" type="xsd:integer" />
<xsd:attribute name="on-invalid" type="invalid_sequence" />
<xsd:attribute name="strict" type="boolean" />
</xsd:complexType>
<xsd:complexType name="call">

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\DependencyInjection\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
class ChildDefinitionTest extends TestCase
{
@ -132,11 +131,6 @@ class ChildDefinitionTest extends TestCase
$def->getArgument(1);
}
public function testDefinitionDecoratorAliasExistsForBackwardsCompatibility()
{
$this->assertInstanceOf(ChildDefinition::class, new DefinitionDecorator('foo'));
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
*/

View File

@ -55,10 +55,8 @@ class AutowirePassTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\B" service to "Symfony\Component\DependencyInjection\Tests\Compiler\A" instead.
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.
*/
public function testProcessAutowireParent()
{
@ -76,32 +74,8 @@ class AutowirePassTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead.
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.
*/
public function testProcessLegacyAutowireWithAvailableInterface()
{
$container = new ContainerBuilder();
$container->setAlias(AInterface::class, B::class);
$container->register(B::class);
$cDefinition = $container->register('c', __NAMESPACE__.'\C');
$cDefinition->setAutowired(true);
(new ResolveClassPass())->process($container);
(new AutowirePass())->process($container);
$this->assertCount(1, $container->getDefinition('c')->getArguments());
$this->assertEquals(B::class, (string) $container->getDefinition('c')->getArgument(0));
}
/**
* @group legacy
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\F" service to "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" instead.
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessageInSymfony4 Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service.
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service.
*/
public function testProcessAutowireInterface()
{
@ -385,10 +359,8 @@ class AutowirePassTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead.
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service.
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessage Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service.
*/
public function testDontUseAbstractServices()
{
@ -590,32 +562,6 @@ class AutowirePassTest extends TestCase
$this->assertSame(A::class, $container->getDefinition('autowired.'.A::class)->getClass());
}
/**
* @dataProvider getCreateResourceTests
* @group legacy
*/
public function testCreateResourceForClass($className, $isEqual)
{
$startingResource = AutowirePass::createResourceForClass(
new \ReflectionClass(__NAMESPACE__.'\ClassForResource')
);
$newResource = AutowirePass::createResourceForClass(
new \ReflectionClass(__NAMESPACE__.'\\'.$className)
);
// hack so the objects don't differ by the class name
$startingReflObject = new \ReflectionObject($startingResource);
$reflProp = $startingReflObject->getProperty('class');
$reflProp->setAccessible(true);
$reflProp->setValue($startingResource, __NAMESPACE__.'\\'.$className);
if ($isEqual) {
$this->assertEquals($startingResource, $newResource);
} else {
$this->assertNotEquals($startingResource, $newResource);
}
}
public function getCreateResourceTests()
{
return array(
@ -657,10 +603,8 @@ class AutowirePassTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead.
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessage Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.
*/
public function testProcessDoesNotTriggerDeprecations()
{
@ -748,10 +692,8 @@ class AutowirePassTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessageInSymfony4 Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
*/
public function testByIdAlternative()
{
@ -766,25 +708,6 @@ class AutowirePassTest extends TestCase
$pass->process($container);
}
/**
* @group legacy
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for "Symfony\Component\DependencyInjection\Tests\Compiler\A" in "Symfony\Component\DependencyInjection\Tests\Compiler\Bar" to "Symfony\Component\DependencyInjection\Tests\Compiler\AInterface" instead.
*/
public function testTypedReferenceDeprecationNotice()
{
$container = new ContainerBuilder();
$container->register('aClass', A::class);
$container->setAlias(AInterface::class, 'aClass');
$container
->register('bar', Bar::class)
->setProperty('a', array(new TypedReference(A::class, A::class, Bar::class)))
;
$pass = new AutowirePass();
$pass->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
* @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.

View File

@ -1,109 +0,0 @@
<?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 Symfony\Component\DependencyInjection\Tests\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Compiler\FactoryReturnTypePass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\factoryFunction;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryParent;
/**
* @author Guilhem N. <egetick@gmail.com>
*
* @group legacy
*/
class FactoryReturnTypePassTest extends TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$factory = $container->register('factory');
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
$container->setAlias('alias_factory', 'factory');
$foo = $container->register('foo');
$foo->setFactory(array(new Reference('alias_factory'), 'create'));
$bar = $container->register('bar', __CLASS__);
$bar->setFactory(array(new Reference('factory'), 'create'));
$pass = new FactoryReturnTypePass();
$pass->process($container);
$this->assertEquals(FactoryDummy::class, $factory->getClass());
$this->assertEquals(\stdClass::class, $foo->getClass());
$this->assertEquals(__CLASS__, $bar->getClass());
}
/**
* @dataProvider returnTypesProvider
*/
public function testReturnTypes($factory, $returnType)
{
$container = new ContainerBuilder();
$service = $container->register('service');
$service->setFactory($factory);
$pass = new FactoryReturnTypePass();
$pass->process($container);
$this->assertEquals($returnType, $service->getClass());
}
public function returnTypesProvider()
{
return array(
// must be loaded before the function as they are in the same file
array(array(FactoryDummy::class, 'createBuiltin'), null),
array(array(FactoryDummy::class, 'createParent'), FactoryParent::class),
array(array(FactoryDummy::class, 'createSelf'), FactoryDummy::class),
array(factoryFunction::class, FactoryDummy::class),
);
}
public function testCircularReference()
{
$container = new ContainerBuilder();
$factory = $container->register('factory');
$factory->setFactory(array(new Reference('factory2'), 'createSelf'));
$factory2 = $container->register('factory2');
$factory2->setFactory(array(new Reference('factory'), 'create'));
$pass = new FactoryReturnTypePass();
$pass->process($container);
$this->assertNull($factory->getClass());
$this->assertNull($factory2->getClass());
}
/**
* @expectedDeprecation Relying on its factory's return-type to define the class of service "factory" is deprecated since Symfony 3.3 and won't work in 4.0. Set the "class" attribute to "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy" on the service definition instead.
*/
public function testCompile()
{
$container = new ContainerBuilder();
$factory = $container->register('factory');
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
$container->compile();
$this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass());
}
}

View File

@ -1,124 +0,0 @@
<?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 Symfony\Component\DependencyInjection\Tests\Config;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
use Symfony\Component\DependencyInjection\Config\AutowireServiceResource;
/**
* @group legacy
*/
class AutowireServiceResourceTest extends TestCase
{
/**
* @var AutowireServiceResource
*/
private $resource;
private $file;
private $class;
private $time;
protected function setUp()
{
$this->file = realpath(sys_get_temp_dir()).'/tmp.php';
$this->time = time();
touch($this->file, $this->time);
$this->class = __NAMESPACE__.'\Foo';
$this->resource = new AutowireServiceResource(
$this->class,
$this->file,
array()
);
}
public function testToString()
{
$this->assertSame('service.autowire.'.$this->class, (string) $this->resource);
}
public function testSerializeUnserialize()
{
$unserialized = unserialize(serialize($this->resource));
$this->assertEquals($this->resource, $unserialized);
}
public function testIsFresh()
{
$this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
$this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
$this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
}
public function testIsFreshForDeletedResources()
{
unlink($this->file);
$this->assertFalse($this->resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the resource does not exist');
}
public function testIsNotFreshChangedResource()
{
$oldResource = new AutowireServiceResource(
$this->class,
$this->file,
array('will_be_different')
);
// test with a stale file *and* a resource that *will* be different than the actual
$this->assertFalse($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed');
}
public function testIsFreshSameConstructorArgs()
{
$oldResource = AutowirePass::createResourceForClass(
new \ReflectionClass(__NAMESPACE__.'\Foo')
);
// test with a stale file *but* the resource will not be changed
$this->assertTrue($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed');
}
public function testNotFreshIfClassNotFound()
{
$resource = new AutowireServiceResource(
'Some\Non\Existent\Class',
$this->file,
array()
);
$this->assertFalse($resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the class no longer exists');
}
protected function tearDown()
{
if (!file_exists($this->file)) {
return;
}
unlink($this->file);
}
private function getStaleFileTime()
{
return $this->time - 10;
}
}
class Foo
{
public function __construct($foo)
{
}
}

View File

@ -712,32 +712,6 @@ class ContainerBuilderTest extends TestCase
$this->assertSame(realpath(__DIR__.'/Fixtures/includes/classes.php'), realpath($resource->getResource()));
}
/**
* @group legacy
*/
public function testAddClassResource()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->addClassResource(new \ReflectionClass('BarClass'));
$this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
$container->setResourceTracking(true);
$container->addClassResource(new \ReflectionClass('BarClass'));
$resources = $container->getResources();
$this->assertCount(2, $resources, '2 resources were registered');
/* @var $resource \Symfony\Component\Config\Resource\FileResource */
$resource = end($resources);
$this->assertInstanceOf('Symfony\Component\Config\Resource\FileResource', $resource);
$this->assertSame(realpath(__DIR__.'/Fixtures/includes/classes.php'), realpath($resource->getResource()));
}
public function testGetReflectionClass()
{
$container = new ContainerBuilder();

View File

@ -1,132 +0,0 @@
<?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 Symfony\Component\DependencyInjection\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
/**
* @group legacy
*/
class DefinitionDecoratorTest extends TestCase
{
public function testConstructor()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals('foo', $def->getParent());
$this->assertEquals(array(), $def->getChanges());
}
/**
* @dataProvider getPropertyTests
*/
public function testSetProperty($property, $changeKey)
{
$def = new DefinitionDecorator('foo');
$getter = 'get'.ucfirst($property);
$setter = 'set'.ucfirst($property);
$this->assertNull($def->$getter());
$this->assertSame($def, $def->$setter('foo'));
$this->assertEquals('foo', $def->$getter());
$this->assertEquals(array($changeKey => true), $def->getChanges());
}
public function getPropertyTests()
{
return array(
array('class', 'class'),
array('factory', 'factory'),
array('configurator', 'configurator'),
array('file', 'file'),
);
}
public function testSetPublic()
{
$def = new DefinitionDecorator('foo');
$this->assertTrue($def->isPublic());
$this->assertSame($def, $def->setPublic(false));
$this->assertFalse($def->isPublic());
$this->assertEquals(array('public' => true), $def->getChanges());
}
public function testSetLazy()
{
$def = new DefinitionDecorator('foo');
$this->assertFalse($def->isLazy());
$this->assertSame($def, $def->setLazy(false));
$this->assertFalse($def->isLazy());
$this->assertEquals(array('lazy' => true), $def->getChanges());
}
public function testSetAutowired()
{
$def = new DefinitionDecorator('foo');
$this->assertFalse($def->isAutowired());
$this->assertSame($def, $def->setAutowired(true));
$this->assertTrue($def->isAutowired());
$this->assertSame(array('autowired' => true), $def->getChanges());
}
public function testSetArgument()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals(array(), $def->getArguments());
$this->assertSame($def, $def->replaceArgument(0, 'foo'));
$this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testReplaceArgumentShouldRequireIntegerIndex()
{
$def = new DefinitionDecorator('foo');
$def->replaceArgument('0', 'foo');
}
public function testReplaceArgument()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo', 1 => 'bar'));
$this->assertEquals('foo', $def->getArgument(0));
$this->assertEquals('bar', $def->getArgument(1));
$this->assertSame($def, $def->replaceArgument(1, 'baz'));
$this->assertEquals('foo', $def->getArgument(0));
$this->assertEquals('baz', $def->getArgument(1));
$this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
}
/**
* @expectedException \OutOfBoundsException
*/
public function testGetArgumentShouldCheckBounds()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo'));
$def->replaceArgument(0, 'foo');
$def->getArgument(1);
}
}

View File

@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="foo" class="Foo" />
<service id="bar" alias="foo" class="Foo">
<tag name="foo.bar" />
<factory service="foobar" method="getBar" />
</service>
<service id="bar" alias="foo" class="Foo" />
</services>
</container>

View File

@ -18,8 +18,5 @@
</property>
</service>
<service id="bar" parent="foo" />
<service id="biz" class="BizClass">
<tag name="biz_tag" />
</service>
</services>
</container>

View File

@ -183,7 +183,7 @@ class XmlFileLoaderTest extends TestCase
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services5.xml');
$services = $container->getDefinitions();
$this->assertCount(7, $services, '->load() attributes unique ids to anonymous services');
$this->assertCount(6, $services, '->load() attributes unique ids to anonymous services');
// anonymous service as an argument
$args = $services['foo']->getArguments();
@ -212,16 +212,6 @@ class XmlFileLoaderTest extends TestCase
$this->assertEquals('BuzClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
$this->assertFalse($inner->isPublic());
// "wild" service
$service = $container->findTaggedServiceIds('biz_tag');
$this->assertCount(1, $service);
foreach ($service as $id => $tag) {
$service = $container->getDefinition($id);
}
$this->assertEquals('BizClass', $service->getClass(), '->load() uses the same configuration as for the anonymous ones');
$this->assertTrue($service->isPublic());
// anonymous services are shared when using decoration definitions
$container->compile();
$services = $container->getDefinitions();
@ -231,8 +221,8 @@ class XmlFileLoaderTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Top-level anonymous services are deprecated since Symfony 3.4, the "id" attribute will be required in version 4.0 in %sservices_without_id.xml at line 4.
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Top-level services must have "id" attribute, none found in
*/
public function testLoadAnonymousServicesWithoutId()
{
@ -625,17 +615,15 @@ class XmlFileLoaderTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Using the attribute "class" is deprecated for the service "bar" which is defined as an alias %s.
* @expectedDeprecation Using the element "tag" is deprecated for the service "bar" which is defined as an alias %s.
* @expectedDeprecation Using the element "factory" is deprecated for the service "bar" which is defined as an alias %s.
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid attribute "class" defined for alias "bar" in
*/
public function testAliasDefinitionContainsUnsupportedElements()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('legacy_invalid_alias_definition.xml');
$loader->load('invalid_alias_definition.xml');
$this->assertTrue($container->has('bar'));
}

View File

@ -1418,7 +1418,7 @@ class Request
{
if (!func_num_args() || func_get_arg(0)) {
// setting $andCacheable to false should be deprecated in 4.1
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.', E_USER_DEPRECATED);
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.');
}
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));