feature #22749 Remove deprecated container injections and compiler passes (chalasr)
This PR was merged into the 4.0-dev branch.
Discussion
----------
Remove deprecated container injections and compiler passes
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | ~~#21451 #21625 #21284 #22010~~ #22805
| License | MIT
| Doc PR | n/a
Commits
-------
16a2fcf
Remove deprecated container injections and compiler passes
This commit is contained in:
commit
7047b41449
@ -4,8 +4,13 @@ CHANGELOG
|
||||
4.0.0
|
||||
-----
|
||||
|
||||
* Removed `ValidateWorkflowsPass`
|
||||
* The default `type` option of the `framework.workflows.*` configuration entries is `state_machine`
|
||||
* removed `AddConsoleCommandPass`, `AddConstraintValidatorsPass`,
|
||||
`AddValidatorInitializersPass`, `CompilerDebugDumpPass`, `ConfigCachePass`,
|
||||
`ControllerArgumentValueResolverPass`, `FormPass`, `PropertyInfoPass`,
|
||||
`RoutingResolverPass`, `SerializerPass`, `ValidateWorkflowsPass`
|
||||
* made `Translator::__construct()` `$defaultLocale` argument required
|
||||
* removed `SessionListener`, `TestSessionListener`
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
@ -1,27 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
@trigger_error(sprintf('%s is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.', AddConsoleCommandPass::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass as BaseAddConsoleCommandPass;
|
||||
|
||||
/**
|
||||
* Registers console commands.
|
||||
*
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass instead.
|
||||
*/
|
||||
class AddConsoleCommandPass extends BaseAddConsoleCommandPass
|
||||
{
|
||||
}
|
@ -1,23 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass as BaseAddConstraintValidatorsPass;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', AddConstraintValidatorsPass::class, BaseAddConstraintValidatorsPass::class), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseAddConstraintValidatorsPass} instead
|
||||
*/
|
||||
class AddConstraintValidatorsPass extends BaseAddConstraintValidatorsPass
|
||||
{
|
||||
}
|
@ -1,23 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass as BaseAddValidatorsInitializerPass;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', AddValidatorInitializersPass::class, BaseAddValidatorsInitializerPass::class), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseAddValidatorInitializersPass} instead
|
||||
*/
|
||||
class AddValidatorInitializersPass extends BaseAddValidatorsInitializerPass
|
||||
{
|
||||
}
|
@ -1,46 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0.', CompilerDebugDumpPass::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class CompilerDebugDumpPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$filename = self::getCompilerLogFilename($container);
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->dumpFile($filename, implode("\n", $container->getCompiler()->getLog()), null);
|
||||
try {
|
||||
$filesystem->chmod($filename, 0666, umask());
|
||||
} catch (IOException $e) {
|
||||
// discard chmod failure (some filesystem may not support it)
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCompilerLogFilename(ContainerInterface $container)
|
||||
{
|
||||
$class = $container->getParameter('kernel.container_class');
|
||||
|
||||
return $container->getParameter('kernel.cache_dir').'/'.$class.'Compiler.log';
|
||||
}
|
||||
}
|
@ -1,28 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\Config\DependencyInjection\ConfigCachePass as BaseConfigCachePass;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Config\DependencyInjection\ConfigCachePass instead.', ConfigCachePass::class), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority.
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseConfigCachePass} instead.
|
||||
*
|
||||
* @author Matthias Pigulla <mp@webfactory.de>
|
||||
* @author Benjamin Klotz <bk@webfactory.de>
|
||||
*/
|
||||
class ConfigCachePass extends BaseConfigCachePass
|
||||
{
|
||||
}
|
@ -1,27 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass as BaseControllerArgumentValueResolverPass;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', ControllerArgumentValueResolverPass::class, BaseControllerArgumentValueResolverPass::class), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Gathers and configures the argument value resolvers.
|
||||
*
|
||||
* @author Iltar van der Berg <kjarli@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseControllerArgumentValueResolverPass}
|
||||
*/
|
||||
class ControllerArgumentValueResolverPass extends BaseControllerArgumentValueResolverPass
|
||||
{
|
||||
}
|
@ -1,88 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Form\DependencyInjection\FormPass instead.', FormPass::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Adds all services with the tags "form.type" and "form.type_guesser" as
|
||||
* arguments of the "form.extension" service.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use FormPass in the Form component instead.
|
||||
*/
|
||||
class FormPass implements CompilerPassInterface
|
||||
{
|
||||
use PriorityTaggedServiceTrait;
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('form.extension')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition('form.extension');
|
||||
|
||||
// Builds an array with fully-qualified type class names as keys and service IDs as values
|
||||
$types = array();
|
||||
|
||||
foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) {
|
||||
$serviceDefinition = $container->getDefinition($serviceId);
|
||||
if (!$serviceDefinition->isPublic()) {
|
||||
$serviceDefinition->setPublic(true);
|
||||
}
|
||||
|
||||
// Support type access by FQCN
|
||||
$types[$serviceDefinition->getClass()] = $serviceId;
|
||||
}
|
||||
|
||||
$definition->replaceArgument(1, $types);
|
||||
|
||||
$typeExtensions = array();
|
||||
|
||||
foreach ($this->findAndSortTaggedServices('form.type_extension', $container) as $reference) {
|
||||
$serviceId = (string) $reference;
|
||||
$serviceDefinition = $container->getDefinition($serviceId);
|
||||
if (!$serviceDefinition->isPublic()) {
|
||||
$serviceDefinition->setPublic(true);
|
||||
}
|
||||
|
||||
$tag = $serviceDefinition->getTag('form.type_extension');
|
||||
if (isset($tag[0]['extended_type'])) {
|
||||
$extendedType = $tag[0]['extended_type'];
|
||||
} else {
|
||||
throw new InvalidArgumentException(sprintf('Tagged form type extension must have the extended type configured using the extended_type/extended-type attribute, none was configured for the "%s" service.', $serviceId));
|
||||
}
|
||||
|
||||
$typeExtensions[$extendedType][] = $serviceId;
|
||||
}
|
||||
|
||||
$definition->replaceArgument(2, $typeExtensions);
|
||||
|
||||
// Find all services annotated with "form.type_guesser"
|
||||
$guessers = array_keys($container->findTaggedServiceIds('form.type_guesser'));
|
||||
foreach ($guessers as $serviceId) {
|
||||
$serviceDefinition = $container->getDefinition($serviceId);
|
||||
if (!$serviceDefinition->isPublic()) {
|
||||
$serviceDefinition->setPublic(true);
|
||||
}
|
||||
}
|
||||
|
||||
$definition->replaceArgument(3, $guessers);
|
||||
}
|
||||
}
|
@ -1,27 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass instead.', PropertyInfoPass::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass as BasePropertyInfoPass;
|
||||
|
||||
/**
|
||||
* Adds extractors to the property_info service.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BasePropertyInfoPass instead}.
|
||||
*/
|
||||
class PropertyInfoPass extends BasePropertyInfoPass
|
||||
{
|
||||
}
|
@ -1,27 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass as BaseRoutingResolverPass;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', RoutingResolverPass::class, BaseRoutingResolverPass::class), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Adds tagged routing.loader services to routing.resolver service.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseRoutingResolverPass}
|
||||
*/
|
||||
class RoutingResolverPass extends BaseRoutingResolverPass
|
||||
{
|
||||
}
|
@ -1,28 +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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Serializer\DependencyInjection\SerializerPass instead.', SerializerPass::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Serializer\DependencyInjection\SerializerPass as BaseSerializerPass;
|
||||
|
||||
/**
|
||||
* Adds all services with the tags "serializer.encoder" and "serializer.normalizer" as
|
||||
* encoders and normalizers to the Serializer service.
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseSerializerPass} instead.
|
||||
*
|
||||
* @author Javier Lopez <f12loalf@gmail.com>
|
||||
*/
|
||||
class SerializerPass extends BaseSerializerPass
|
||||
{
|
||||
}
|
@ -1,43 +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\Bundle\FrameworkBundle\EventListener;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\HttpKernel\EventListener\SessionListener instead.', SessionListener::class), E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Sets the session in the request.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Use Symfony\Component\HttpKernel\EventListener\SessionListener instead
|
||||
*/
|
||||
class SessionListener extends AbstractSessionListener
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getSession()
|
||||
{
|
||||
if (!$this->container->has('session')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->container->get('session');
|
||||
}
|
||||
}
|
@ -1,43 +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\Bundle\FrameworkBundle\EventListener;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\HttpKernel\EventListener\TestSessionListener instead.', TestSessionListener::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* TestSessionListener.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class TestSessionListener extends AbstractTestSessionListener
|
||||
{
|
||||
protected $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getSession()
|
||||
{
|
||||
if (!$this->container->has('session')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->container->get('session');
|
||||
}
|
||||
}
|
@ -1,129 +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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AddConsoleCommandPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider visibilityProvider
|
||||
*/
|
||||
public function testProcess($public)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
$container->setParameter('my-command.class', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
|
||||
|
||||
$definition = new Definition('%my-command.class%');
|
||||
$definition->setPublic($public);
|
||||
$definition->addTag('console.command');
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$alias = 'console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand';
|
||||
|
||||
if ($public) {
|
||||
$this->assertFalse($container->hasAlias($alias));
|
||||
$id = 'my-command';
|
||||
} else {
|
||||
$id = $alias;
|
||||
// The alias is replaced by a Definition by the ReplaceAliasByActualDefinitionPass
|
||||
// in case the original service is private
|
||||
$this->assertFalse($container->hasDefinition('my-command'));
|
||||
$this->assertTrue($container->hasDefinition($alias));
|
||||
}
|
||||
|
||||
$this->assertTrue($container->hasParameter('console.command.ids'));
|
||||
$this->assertSame(array($alias => $id), $container->getParameter('console.command.ids'));
|
||||
}
|
||||
|
||||
public function visibilityProvider()
|
||||
{
|
||||
return array(
|
||||
array(true),
|
||||
array(false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
|
||||
*/
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
|
||||
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
|
||||
$definition->addTag('console.command');
|
||||
$definition->setAbstract(true);
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".
|
||||
*/
|
||||
public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
|
||||
$definition = new Definition('SplObjectStorage');
|
||||
$definition->addTag('console.command');
|
||||
$container->setDefinition('my-command', $definition);
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testProcessPrivateServicesWithSameCommand()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$className = 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand';
|
||||
|
||||
$definition1 = new Definition($className);
|
||||
$definition1->addTag('console.command')->setPublic(false);
|
||||
|
||||
$definition2 = new Definition($className);
|
||||
$definition2->addTag('console.command')->setPublic(false);
|
||||
|
||||
$container->setDefinition('my-command1', $definition1);
|
||||
$container->setDefinition('my-command2', $definition2);
|
||||
|
||||
(new AddConsoleCommandPass())->process($container);
|
||||
|
||||
$alias1 = 'console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand';
|
||||
$alias2 = $alias1.'_my-command2';
|
||||
$this->assertTrue($container->hasAlias($alias1));
|
||||
$this->assertTrue($container->hasAlias($alias2));
|
||||
}
|
||||
}
|
||||
|
||||
class MyCommand extends Command
|
||||
{
|
||||
}
|
||||
|
||||
class ExtensionPresentBundle extends Bundle
|
||||
{
|
||||
}
|
@ -1,83 +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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class AddConstraintValidatorsPassTest extends TestCase
|
||||
{
|
||||
public function testThatConstraintValidatorServicesAreProcessed()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$validatorFactory = $container->register('validator.validator_factory')
|
||||
->addArgument(array());
|
||||
|
||||
$container->register('my_constraint_validator_service1', Validator1::class)
|
||||
->addTag('validator.constraint_validator', array('alias' => 'my_constraint_validator_alias1'));
|
||||
$container->register('my_constraint_validator_service2', Validator2::class)
|
||||
->addTag('validator.constraint_validator');
|
||||
|
||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||
$addConstraintValidatorsPass->process($container);
|
||||
|
||||
$expected = (new Definition(ServiceLocator::class, array(array(
|
||||
Validator1::class => new ServiceClosureArgument(new Reference('my_constraint_validator_service1')),
|
||||
'my_constraint_validator_alias1' => new ServiceClosureArgument(new Reference('my_constraint_validator_service1')),
|
||||
Validator2::class => new ServiceClosureArgument(new Reference('my_constraint_validator_service2')),
|
||||
))))->addTag('container.service_locator')->setPublic(false);
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "my_abstract_constraint_validator" tagged "validator.constraint_validator" must not be abstract.
|
||||
*/
|
||||
public function testAbstractConstraintValidator()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$validatorFactory = $container->register('validator.validator_factory')
|
||||
->addArgument(array());
|
||||
|
||||
$container->register('my_abstract_constraint_validator')
|
||||
->setAbstract(true)
|
||||
->addTag('validator.constraint_validator');
|
||||
|
||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||
$addConstraintValidatorsPass->process($container);
|
||||
}
|
||||
|
||||
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
|
||||
{
|
||||
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
|
||||
|
||||
$container->expects($this->never())->method('findTaggedServiceIds');
|
||||
$container->expects($this->never())->method('getDefinition');
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('hasDefinition')
|
||||
->with('validator.validator_factory')
|
||||
->will($this->returnValue(false));
|
||||
$definition->expects($this->never())->method('replaceArgument');
|
||||
|
||||
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
|
||||
$addConstraintValidatorsPass->process($container);
|
||||
}
|
||||
}
|
@ -1,56 +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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ConfigCachePassTest extends TestCase
|
||||
{
|
||||
public function testThatCheckersAreProcessedInPriorityOrder()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register('config_cache_factory')->addArgument(null);
|
||||
$container->register('checker_2')->addTag('config_cache.resource_checker', array('priority' => 100));
|
||||
$container->register('checker_1')->addTag('config_cache.resource_checker', array('priority' => 200));
|
||||
$container->register('checker_3')->addTag('config_cache.resource_checker');
|
||||
|
||||
$pass = new ConfigCachePass();
|
||||
$pass->process($container);
|
||||
|
||||
$expected = new IteratorArgument(array(
|
||||
new Reference('checker_1'),
|
||||
new Reference('checker_2'),
|
||||
new Reference('checker_3'),
|
||||
));
|
||||
$this->assertEquals($expected, $definition->getArgument(0));
|
||||
}
|
||||
|
||||
public function testThatCheckersCanBeMissing()
|
||||
{
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
|
||||
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('findTaggedServiceIds')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$pass = new ConfigCachePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
@ -1,70 +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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ControllerArgumentValueResolverPassTest extends TestCase
|
||||
{
|
||||
public function testServicesAreOrderedAccordingToPriority()
|
||||
{
|
||||
$services = array(
|
||||
'n3' => array(array()),
|
||||
'n1' => array(array('priority' => 200)),
|
||||
'n2' => array(array('priority' => 100)),
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
);
|
||||
|
||||
$definition = new Definition(ArgumentResolver::class, array(null, array()));
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('argument_resolver', $definition);
|
||||
|
||||
foreach ($services as $id => list($tag)) {
|
||||
$container->register($id)->addTag('controller.argument_value_resolver', $tag);
|
||||
}
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
$this->assertEquals($expected, $definition->getArgument(1)->getValues());
|
||||
}
|
||||
|
||||
public function testReturningEmptyArrayWhenNoService()
|
||||
{
|
||||
$definition = new Definition(ArgumentResolver::class, array(null, array()));
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('argument_resolver', $definition);
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
$this->assertEquals(array(), $definition->getArgument(1)->getValues());
|
||||
}
|
||||
|
||||
public function testNoArgumentResolver()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
(new ControllerArgumentValueResolverPass())->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('argument_resolver'));
|
||||
}
|
||||
}
|
@ -1,220 +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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class FormPassTest extends TestCase
|
||||
{
|
||||
public function testDoNothingIfFormExtensionNotLoaded()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$container->compile();
|
||||
|
||||
$this->assertFalse($container->hasDefinition('form.extension'));
|
||||
}
|
||||
|
||||
public function testAddTaggedTypes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
|
||||
$extDefinition->setArguments(array(
|
||||
new Reference('service_container'),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
));
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->register('my.type1', __CLASS__.'_Type1')->addTag('form.type');
|
||||
$container->register('my.type2', __CLASS__.'_Type2')->addTag('form.type');
|
||||
|
||||
$container->compile();
|
||||
|
||||
$extDefinition = $container->getDefinition('form.extension');
|
||||
|
||||
$this->assertEquals(array(
|
||||
__CLASS__.'_Type1' => 'my.type1',
|
||||
__CLASS__.'_Type2' => 'my.type2',
|
||||
), $extDefinition->getArgument(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider addTaggedTypeExtensionsDataProvider
|
||||
*/
|
||||
public function testAddTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', array(
|
||||
new Reference('service_container'),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
));
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
|
||||
foreach ($extensions as $serviceId => $tag) {
|
||||
$container->register($serviceId, 'stdClass')->addTag('form.type_extension', $tag);
|
||||
}
|
||||
|
||||
$container->compile();
|
||||
|
||||
$extDefinition = $container->getDefinition('form.extension');
|
||||
$this->assertSame($expectedRegisteredExtensions, $extDefinition->getArgument(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function addTaggedTypeExtensionsDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'my.type_extension1' => array('extended_type' => 'type1'),
|
||||
'my.type_extension2' => array('extended_type' => 'type1'),
|
||||
'my.type_extension3' => array('extended_type' => 'type2'),
|
||||
),
|
||||
array(
|
||||
'type1' => array('my.type_extension1', 'my.type_extension2'),
|
||||
'type2' => array('my.type_extension3'),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'my.type_extension1' => array('extended_type' => 'type1', 'priority' => 1),
|
||||
'my.type_extension2' => array('extended_type' => 'type1', 'priority' => 2),
|
||||
'my.type_extension3' => array('extended_type' => 'type1', 'priority' => -1),
|
||||
'my.type_extension4' => array('extended_type' => 'type2', 'priority' => 2),
|
||||
'my.type_extension5' => array('extended_type' => 'type2', 'priority' => 1),
|
||||
'my.type_extension6' => array('extended_type' => 'type2', 'priority' => 1),
|
||||
),
|
||||
array(
|
||||
'type1' => array('my.type_extension2', 'my.type_extension1', 'my.type_extension3'),
|
||||
'type2' => array('my.type_extension4', 'my.type_extension5', 'my.type_extension6'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage extended-type attribute, none was configured for the "my.type_extension" service
|
||||
*/
|
||||
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttribute()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', array(
|
||||
new Reference('service_container'),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
));
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->register('my.type_extension', 'stdClass')
|
||||
->addTag('form.type_extension');
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testAddTaggedGuessers()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
|
||||
$extDefinition->setArguments(array(
|
||||
new Reference('service_container'),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
));
|
||||
|
||||
$definition1 = new Definition('stdClass');
|
||||
$definition1->addTag('form.type_guesser');
|
||||
$definition2 = new Definition('stdClass');
|
||||
$definition2->addTag('form.type_guesser');
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->setDefinition('my.guesser1', $definition1);
|
||||
$container->setDefinition('my.guesser2', $definition2);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$extDefinition = $container->getDefinition('form.extension');
|
||||
|
||||
$this->assertSame(array(
|
||||
'my.guesser1',
|
||||
'my.guesser2',
|
||||
), $extDefinition->getArgument(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider privateTaggedServicesProvider
|
||||
*/
|
||||
public function testPrivateTaggedServices($id, $tagName)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new FormPass());
|
||||
|
||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
|
||||
$extDefinition->setArguments(array(
|
||||
new Reference('service_container'),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
));
|
||||
|
||||
$container->setDefinition('form.extension', $extDefinition);
|
||||
$container->register($id, 'stdClass')->setPublic(false)->addTag($tagName, array('extended_type' => 'Foo'));
|
||||
|
||||
$container->compile();
|
||||
$this->assertTrue($container->getDefinition($id)->isPublic());
|
||||
}
|
||||
|
||||
public function privateTaggedServicesProvider()
|
||||
{
|
||||
return array(
|
||||
array('my.type', 'form.type'),
|
||||
array('my.type_extension', 'form.type_extension'),
|
||||
array('my.guesser', 'form.type_guesser'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FormPassTest_Type1 extends AbstractType
|
||||
{
|
||||
}
|
||||
|
||||
class FormPassTest_Type2 extends AbstractType
|
||||
{
|
||||
}
|
@ -1,80 +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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class PropertyInfoPassTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideTags
|
||||
*/
|
||||
public function testServicesAreOrderedAccordingToPriority($index, $tag)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register('property_info')->setArguments(array(null, null, null, null));
|
||||
$container->register('n2')->addTag($tag, array('priority' => 100));
|
||||
$container->register('n1')->addTag($tag, array('priority' => 200));
|
||||
$container->register('n3')->addTag($tag);
|
||||
|
||||
$propertyInfoPass = new PropertyInfoPass();
|
||||
$propertyInfoPass->process($container);
|
||||
|
||||
$expected = new IteratorArgument(array(
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
));
|
||||
$this->assertEquals($expected, $definition->getArgument($index));
|
||||
}
|
||||
|
||||
public function provideTags()
|
||||
{
|
||||
return array(
|
||||
array(0, 'property_info.list_extractor'),
|
||||
array(1, 'property_info.type_extractor'),
|
||||
array(2, 'property_info.description_extractor'),
|
||||
array(3, 'property_info.access_extractor'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testReturningEmptyArrayWhenNoService()
|
||||
{
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
|
||||
|
||||
$container
|
||||
->expects($this->any())
|
||||
->method('findTaggedServiceIds')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$propertyInfoPass = new PropertyInfoPass();
|
||||
|
||||
$method = new \ReflectionMethod(
|
||||
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass',
|
||||
'findAndSortTaggedServices'
|
||||
);
|
||||
$method->setAccessible(true);
|
||||
|
||||
$actual = $method->invoke($propertyInfoPass, 'tag', $container);
|
||||
|
||||
$this->assertEquals(array(), $actual);
|
||||
}
|
||||
}
|
@ -1,95 +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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
|
||||
|
||||
/**
|
||||
* Tests for the SerializerPass class.
|
||||
*
|
||||
* @group legacy
|
||||
*
|
||||
* @author Javier Lopez <f12loalf@gmail.com>
|
||||
*/
|
||||
class SerializerPassTest extends TestCase
|
||||
{
|
||||
public function testThrowExceptionWhenNoNormalizers()
|
||||
{
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds'))->getMock();
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('hasDefinition')
|
||||
->with('serializer')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('findTaggedServiceIds')
|
||||
->with('serializer.normalizer')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
|
||||
|
||||
$serializerPass = new SerializerPass();
|
||||
$serializerPass->process($container);
|
||||
}
|
||||
|
||||
public function testThrowExceptionWhenNoEncoders()
|
||||
{
|
||||
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('hasDefinition')
|
||||
->with('serializer')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$container->expects($this->any())
|
||||
->method('findTaggedServiceIds')
|
||||
->will($this->onConsecutiveCalls(
|
||||
array('n' => array('serializer.normalizer')),
|
||||
array()
|
||||
));
|
||||
|
||||
$container->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($definition));
|
||||
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
|
||||
|
||||
$serializerPass = new SerializerPass();
|
||||
$serializerPass->process($container);
|
||||
}
|
||||
|
||||
public function testServicesAreOrderedAccordingToPriority()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register('serializer')->setArguments(array(null, null));
|
||||
$container->register('n2')->addTag('serializer.normalizer', array('priority' => 100))->addTag('serializer.encoder', array('priority' => 100));
|
||||
$container->register('n1')->addTag('serializer.normalizer', array('priority' => 200))->addTag('serializer.encoder', array('priority' => 200));
|
||||
$container->register('n3')->addTag('serializer.normalizer')->addTag('serializer.encoder');
|
||||
|
||||
$serializerPass = new SerializerPass();
|
||||
$serializerPass->process($container);
|
||||
|
||||
$expected = array(
|
||||
new Reference('n1'),
|
||||
new Reference('n2'),
|
||||
new Reference('n3'),
|
||||
);
|
||||
$this->assertEquals($expected, $definition->getArgument(0));
|
||||
$this->assertEquals($expected, $definition->getArgument(1));
|
||||
}
|
||||
}
|
@ -43,157 +43,6 @@ class TranslatorTest extends TestCase
|
||||
$fs->remove($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Method Symfony\Bundle\FrameworkBundle\Translation\Translator::__construct() takes the default locale as 3rd argument since version 3.3. Not passing it is deprecated and will trigger an error in 4.0.
|
||||
*/
|
||||
public function testTransWithoutCachingOmittingLocale()
|
||||
{
|
||||
$translator = $this->getTranslator($this->getLoader(), array(), 'loader', '\Symfony\Bundle\FrameworkBundle\Translation\Translator', null);
|
||||
$translator->setLocale('fr');
|
||||
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
||||
|
||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
||||
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Method Symfony\Bundle\FrameworkBundle\Translation\Translator::__construct() takes the default locale as 3rd argument since version 3.3. Not passing it is deprecated and will trigger an error in 4.0.
|
||||
*/
|
||||
public function testTransWithCachingOmittingLocale()
|
||||
{
|
||||
// prime the cache
|
||||
$translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir), 'loader', '\Symfony\Bundle\FrameworkBundle\Translation\Translator', null);
|
||||
$translator->setLocale('fr');
|
||||
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
||||
|
||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
||||
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||
|
||||
// do it another time as the cache is primed now
|
||||
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
|
||||
$loader->expects($this->never())->method('load');
|
||||
|
||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir), 'loader', '\Symfony\Bundle\FrameworkBundle\Translation\Translator', null);
|
||||
$translator->setLocale('fr');
|
||||
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
||||
|
||||
$this->assertEquals('foo (FR)', $translator->trans('foo'));
|
||||
$this->assertEquals('bar (EN)', $translator->trans('bar'));
|
||||
$this->assertEquals('foobar (ES)', $translator->trans('foobar'));
|
||||
$this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0));
|
||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
||||
$this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo'));
|
||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
||||
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Method Symfony\Bundle\FrameworkBundle\Translation\Translator::__construct() takes the default locale as 3rd argument since version 3.3. Not passing it is deprecated and will trigger an error in 4.0.
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testTransWithCachingWithInvalidLocaleOmittingLocale()
|
||||
{
|
||||
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
|
||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir), 'loader', '\Symfony\Bundle\FrameworkBundle\Tests\Translation\TranslatorWithInvalidLocale', null);
|
||||
|
||||
$translator->trans('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Method Symfony\Bundle\FrameworkBundle\Translation\Translator::__construct() takes the default locale as 3rd argument since version 3.3. Not passing it is deprecated and will trigger an error in 4.0.
|
||||
*/
|
||||
public function testLoadResourcesWithoutCachingOmittingLocale()
|
||||
{
|
||||
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
|
||||
$resourceFiles = array(
|
||||
'fr' => array(
|
||||
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
|
||||
),
|
||||
);
|
||||
|
||||
$translator = $this->getTranslator($loader, array('resource_files' => $resourceFiles), 'yml', '\Symfony\Bundle\FrameworkBundle\Translation\Translator', null);
|
||||
$translator->setLocale('fr');
|
||||
|
||||
$this->assertEquals('répertoire', $translator->trans('folder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Method Symfony\Bundle\FrameworkBundle\Translation\Translator::__construct() takes the default locale as 3rd argument since version 3.3. Not passing it is deprecated and will trigger an error in 4.0.
|
||||
*/
|
||||
public function testGetDefaultLocaleOmittingLocale()
|
||||
{
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('getParameter')
|
||||
->with('kernel.default_locale')
|
||||
->will($this->returnValue('en'))
|
||||
;
|
||||
$translator = new Translator($container, new MessageSelector());
|
||||
|
||||
$this->assertSame('en', $translator->getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Missing third $defaultLocale argument.
|
||||
*/
|
||||
public function testGetDefaultLocaleOmittingLocaleWithPsrContainer()
|
||||
{
|
||||
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
$translator = new Translator($container, new MessageSelector());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Method Symfony\Bundle\FrameworkBundle\Translation\Translator::__construct() takes the default locale as 3rd argument since version 3.3. Not passing it is deprecated and will trigger an error in 4.0.
|
||||
*/
|
||||
public function testWarmupOmittingLocale()
|
||||
{
|
||||
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
|
||||
$resourceFiles = array(
|
||||
'fr' => array(
|
||||
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
|
||||
),
|
||||
);
|
||||
|
||||
// prime the cache
|
||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'resource_files' => $resourceFiles), 'yml', '\Symfony\Bundle\FrameworkBundle\Translation\Translator', null);
|
||||
$translator->setFallbackLocales(array('fr'));
|
||||
$translator->warmup($this->tmpDir);
|
||||
|
||||
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
|
||||
$loader
|
||||
->expects($this->never())
|
||||
->method('load');
|
||||
|
||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'resource_files' => $resourceFiles), 'yml', '\Symfony\Bundle\FrameworkBundle\Translation\Translator', null);
|
||||
$translator->setLocale('fr');
|
||||
$translator->setFallbackLocales(array('fr'));
|
||||
$this->assertEquals('répertoire', $translator->trans('folder'));
|
||||
}
|
||||
|
||||
public function testTransWithoutCaching()
|
||||
{
|
||||
$translator = $this->getTranslator($this->getLoader());
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle\Translation;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
|
||||
use Symfony\Component\Translation\Translator as BaseTranslator;
|
||||
use Symfony\Component\Translation\MessageSelector;
|
||||
@ -50,25 +49,14 @@ class Translator extends BaseTranslator implements WarmableInterface
|
||||
*
|
||||
* @param ContainerInterface $container A ContainerInterface instance
|
||||
* @param MessageSelector $selector The message selector for pluralization
|
||||
* @param string $defaultLocale
|
||||
* @param array $loaderIds An array of loader Ids
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(ContainerInterface $container, MessageSelector $selector, $defaultLocale = null, array $loaderIds = array(), array $options = array())
|
||||
public function __construct(ContainerInterface $container, MessageSelector $selector, string $defaultLocale, array $loaderIds = array(), array $options = array())
|
||||
{
|
||||
// BC 3.x, to be removed in 4.0 along with the $defaultLocale default value
|
||||
if (is_array($defaultLocale) || 3 > func_num_args()) {
|
||||
if (!$container instanceof SymfonyContainerInterface) {
|
||||
throw new \InvalidArgumentException('Missing third $defaultLocale argument.');
|
||||
}
|
||||
|
||||
$options = $loaderIds;
|
||||
$loaderIds = $defaultLocale;
|
||||
$defaultLocale = $container->getParameter('kernel.default_locale');
|
||||
@trigger_error(sprintf('Method %s() takes the default locale as 3rd argument since version 3.3. Not passing it is deprecated and will trigger an error in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
$this->loaderIds = $loaderIds;
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.0.0
|
||||
-----
|
||||
|
||||
* removed `FirewallContext::getContext()`
|
||||
* made `FirewallMap::$container` and `::$map` private
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
|
@ -37,16 +37,6 @@ class FirewallContext
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.3, will be removed in 4.0. Use {@link getListeners()} and/or {@link getExceptionListener()} instead.
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
@trigger_error(sprintf('Method %s() is deprecated since version 3.3 and will be removed in 4.0. Use %s::getListeners/getExceptionListener() instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED);
|
||||
|
||||
return array($this->getListeners(), $this->getExceptionListener());
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
return $this->listeners;
|
||||
|
@ -22,88 +22,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class FirewallMap extends _FirewallMap implements FirewallMapInterface
|
||||
{
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0 alongside with magic methods below
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0 alongside with magic methods below
|
||||
*/
|
||||
private $map;
|
||||
|
||||
public function __construct(ContainerInterface $container, $map)
|
||||
{
|
||||
parent::__construct($container, $map);
|
||||
$this->container = $container;
|
||||
$this->map = $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ('map' === $name || 'container' === $name) {
|
||||
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);
|
||||
|
||||
if ('map' === $name && $this->map instanceof \Traversable) {
|
||||
$this->map = iterator_to_array($this->map);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
if ('map' === $name || 'container' === $name) {
|
||||
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);
|
||||
|
||||
$set = \Closure::bind(function ($name, $value) { $this->$name = $value; }, $this, parent::class);
|
||||
$set($name, $value);
|
||||
}
|
||||
|
||||
$this->$name = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
if ('map' === $name || 'container' === $name) {
|
||||
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return isset($this->$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
if ('map' === $name || 'container' === $name) {
|
||||
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);
|
||||
|
||||
$unset = \Closure::bind(function ($name) { unset($this->$name); }, $this, parent::class);
|
||||
$unset($name);
|
||||
}
|
||||
|
||||
unset($this->$name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal to be removed in 4.0
|
||||
*/
|
||||
class _FirewallMap
|
||||
class FirewallMap implements FirewallMapInterface
|
||||
{
|
||||
private $container;
|
||||
private $map;
|
||||
|
@ -37,18 +37,6 @@ class FirewallContextTest extends TestCase
|
||||
$this->assertEquals($config, $context->getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Method Symfony\Bundle\SecurityBundle\Security\FirewallContext::getContext() is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Bundle\SecurityBundle\Security\FirewallContext::getListeners/getExceptionListener() instead.
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetContext()
|
||||
{
|
||||
$context = (new FirewallContext($listeners = array(), $exceptionListener = $this->getExceptionListenerMock(), new FirewallConfig('main', 'request_matcher', 'user_checker')))
|
||||
->getContext();
|
||||
|
||||
$this->assertEquals(array($listeners, $exceptionListener), $context);
|
||||
}
|
||||
|
||||
private function getExceptionListenerMock()
|
||||
{
|
||||
return $this
|
||||
|
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.4.0
|
||||
-----
|
||||
|
||||
* removed `ContainerAwareRuntimeLoader`
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
|
@ -1,52 +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\Bundle\TwigBundle;
|
||||
|
||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig_ContainerRuntimeLoader class instead.', ContainerAwareRuntimeLoader::class), E_USER_DEPRECATED);
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Loads Twig extension runtimes via the service container.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, will be removed in 4.0. Use \Twig_ContainerRuntimeLoader instead.
|
||||
*/
|
||||
class ContainerAwareRuntimeLoader implements \Twig_RuntimeLoaderInterface
|
||||
{
|
||||
private $container;
|
||||
private $mapping;
|
||||
private $logger;
|
||||
|
||||
public function __construct(ContainerInterface $container, array $mapping, LoggerInterface $logger = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->mapping = $mapping;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($class)
|
||||
{
|
||||
if (isset($this->mapping[$class])) {
|
||||
return $this->container->get($this->mapping[$class]);
|
||||
}
|
||||
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->warning(sprintf('Class "%s" is not configured as a Twig runtime. Add the "twig.runtime" tag to the related service in the container.', $class));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +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\Bundle\TwigBundle\Tests;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Bundle\TwigBundle\ContainerAwareRuntimeLoader;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ContainerAwareRuntimeLoaderTest extends TestCase
|
||||
{
|
||||
public function testLoad()
|
||||
{
|
||||
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
|
||||
$container->expects($this->once())->method('get')->with('foo');
|
||||
|
||||
$loader = new ContainerAwareRuntimeLoader($container, array(
|
||||
'FooClass' => 'foo',
|
||||
));
|
||||
$loader->load('FooClass');
|
||||
}
|
||||
|
||||
public function testLoadWithoutAMatch()
|
||||
{
|
||||
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||
$logger->expects($this->once())->method('warning')->with('Class "BarClass" is not configured as a Twig runtime. Add the "twig.runtime" tag to the related service in the container.');
|
||||
$loader = new ContainerAwareRuntimeLoader($this->getMockBuilder(ContainerInterface::class)->getMock(), array(), $logger);
|
||||
$this->assertNull($loader->load('BarClass'));
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@ CHANGELOG
|
||||
* removed `TraceableControllerResolver::getArguments()`
|
||||
* removed `ControllerResolver::getArguments()` and the ability to resolve arguments
|
||||
* removed the `argument_resolver` service dependency from the `debug.controller_resolver`
|
||||
* removed `LazyLoadingFragmentHandler::addRendererService()`
|
||||
* removed `Psr6CacheClearer::addPool()`
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\CacheClearer;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
@ -25,13 +23,6 @@ class Psr6CacheClearer implements CacheClearerInterface
|
||||
$this->pools = $pools;
|
||||
}
|
||||
|
||||
public function addPool(CacheItemPoolInterface $pool)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->pools[] = $pool;
|
||||
}
|
||||
|
||||
public function hasPool($name)
|
||||
{
|
||||
return isset($this->pools[$name]);
|
||||
|
@ -23,10 +23,6 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
class LazyLoadingFragmentHandler extends FragmentHandler
|
||||
{
|
||||
private $container;
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
private $rendererIds = array();
|
||||
private $initialized = array();
|
||||
|
||||
/**
|
||||
@ -43,34 +39,11 @@ class LazyLoadingFragmentHandler extends FragmentHandler
|
||||
parent::__construct($requestStack, array(), $debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a service as a fragment renderer.
|
||||
*
|
||||
* @param string $name The service name
|
||||
* @param string $renderer The render service id
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
public function addRendererService($name, $renderer)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->rendererIds[$name] = $renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($uri, $renderer = 'inline', array $options = array())
|
||||
{
|
||||
// BC 3.x, to be removed in 4.0
|
||||
if (isset($this->rendererIds[$renderer])) {
|
||||
$this->addRenderer($this->container->get($this->rendererIds[$renderer]));
|
||||
unset($this->rendererIds[$renderer]);
|
||||
|
||||
return parent::render($uri, $renderer, $options);
|
||||
}
|
||||
|
||||
if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
|
||||
$this->addRenderer($this->container->get($renderer));
|
||||
$this->initialized[$renderer] = true;
|
||||
|
@ -45,25 +45,4 @@ class Psr6CacheClearerTest extends TestCase
|
||||
{
|
||||
(new Psr6CacheClearer())->clearPool('unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer::addPool() method is deprecated since version 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead.
|
||||
*/
|
||||
public function testClearPoolsInjectedByAdder()
|
||||
{
|
||||
$pool1 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool1
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$pool2 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool2
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$clearer = new Psr6CacheClearer(array('pool1' => $pool1));
|
||||
$clearer->addPool($pool2);
|
||||
$clearer->clear('');
|
||||
}
|
||||
}
|
||||
|
@ -18,31 +18,6 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class LazyLoadingFragmentHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler::addRendererService() method is deprecated since version 3.3 and will be removed in 4.0.
|
||||
*/
|
||||
public function testRenderWithLegacyMapping()
|
||||
{
|
||||
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
|
||||
$renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
|
||||
$renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
|
||||
|
||||
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
|
||||
$requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
|
||||
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
||||
$container->expects($this->once())->method('get')->will($this->returnValue($renderer));
|
||||
|
||||
$handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
|
||||
$handler->addRendererService('foo', 'foo');
|
||||
|
||||
$handler->render('/foo', 'foo');
|
||||
|
||||
// second call should not lazy-load anymore (see once() above on the get() method)
|
||||
$handler->render('/foo', 'foo');
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
|
||||
|
Reference in New Issue
Block a user