Move PropertyInfoPass to the PropertyInfo component
This commit is contained in:
parent
28a00dac0c
commit
7a7ff24a43
@ -139,6 +139,10 @@ FrameworkBundle
|
|||||||
deprecated and will be removed in 4.0. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass`
|
deprecated and will be removed in 4.0. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass`
|
||||||
class instead.
|
class instead.
|
||||||
|
|
||||||
|
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass` class has been
|
||||||
|
deprecated and will be removed in 4.0. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass`
|
||||||
|
class instead.
|
||||||
|
|
||||||
HttpKernel
|
HttpKernel
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
@ -198,6 +198,9 @@ FrameworkBundle
|
|||||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been removed.
|
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been removed.
|
||||||
Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` class instead.
|
Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` class instead.
|
||||||
|
|
||||||
|
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass` class has been
|
||||||
|
removed. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass`
|
||||||
|
class instead.
|
||||||
|
|
||||||
HttpFoundation
|
HttpFoundation
|
||||||
---------------
|
---------------
|
||||||
|
@ -19,6 +19,7 @@ CHANGELOG
|
|||||||
* Deprecated `TestSessionListener`
|
* Deprecated `TestSessionListener`
|
||||||
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`.
|
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`.
|
||||||
Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead.
|
Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead.
|
||||||
|
* Deprecated `PropertyInfoPass`, use `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` instead
|
||||||
|
|
||||||
3.2.0
|
3.2.0
|
||||||
-----
|
-----
|
||||||
|
@ -11,41 +11,17 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
@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\DependencyInjection\Compiler\CompilerPassInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
|
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass as BasePropertyInfoPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds extractors to the property_info service.
|
* Adds extractors to the property_info service.
|
||||||
*
|
*
|
||||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||||
|
*
|
||||||
|
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BasePropertyInfoPass instead}.
|
||||||
*/
|
*/
|
||||||
class PropertyInfoPass implements CompilerPassInterface
|
class PropertyInfoPass extends BasePropertyInfoPass
|
||||||
{
|
{
|
||||||
use PriorityTaggedServiceTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function process(ContainerBuilder $container)
|
|
||||||
{
|
|
||||||
if (!$container->hasDefinition('property_info')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$definition = $container->getDefinition('property_info');
|
|
||||||
|
|
||||||
$listExtractors = $this->findAndSortTaggedServices('property_info.list_extractor', $container);
|
|
||||||
$definition->replaceArgument(0, new IteratorArgument($listExtractors));
|
|
||||||
|
|
||||||
$typeExtractors = $this->findAndSortTaggedServices('property_info.type_extractor', $container);
|
|
||||||
$definition->replaceArgument(1, new IteratorArgument($typeExtractors));
|
|
||||||
|
|
||||||
$descriptionExtractors = $this->findAndSortTaggedServices('property_info.description_extractor', $container);
|
|
||||||
$definition->replaceArgument(2, new IteratorArgument($descriptionExtractors));
|
|
||||||
|
|
||||||
$accessExtractors = $this->findAndSortTaggedServices('property_info.access_extractor', $container);
|
|
||||||
$definition->replaceArgument(3, new IteratorArgument($accessExtractors));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheCollectorPa
|
|||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
|
||||||
@ -37,6 +36,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
|
|||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
|
||||||
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
|
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
|
||||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
||||||
|
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
|
||||||
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
|
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
|
||||||
use Symfony\Component\Debug\ErrorHandler;
|
use Symfony\Component\Debug\ErrorHandler;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
@ -95,7 +95,7 @@ class FrameworkBundle extends Bundle
|
|||||||
$container->addCompilerPass(new TranslationDumperPass());
|
$container->addCompilerPass(new TranslationDumperPass());
|
||||||
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
|
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
|
||||||
$this->addCompilerPassIfExists($container, SerializerPass::class);
|
$this->addCompilerPassIfExists($container, SerializerPass::class);
|
||||||
$container->addCompilerPass(new PropertyInfoPass());
|
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
|
||||||
$container->addCompilerPass(new DataCollectorTranslatorPass());
|
$container->addCompilerPass(new DataCollectorTranslatorPass());
|
||||||
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
|
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
|
||||||
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
|
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
|
||||||
|
@ -15,6 +15,9 @@ use PHPUnit\Framework\TestCase;
|
|||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
class PropertyInfoPassTest extends TestCase
|
class PropertyInfoPassTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testServicesAreOrderedAccordingToPriority()
|
public function testServicesAreOrderedAccordingToPriority()
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
CHANGELOG
|
||||||
|
=========
|
||||||
|
|
||||||
|
3.3.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Added `PropertyInfoPass`
|
@ -0,0 +1,66 @@
|
|||||||
|
<?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\PropertyInfo\DependencyInjection;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds extractors to the property_info service.
|
||||||
|
*
|
||||||
|
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||||
|
*/
|
||||||
|
class PropertyInfoPass implements CompilerPassInterface
|
||||||
|
{
|
||||||
|
use PriorityTaggedServiceTrait;
|
||||||
|
|
||||||
|
private $propertyInfoService;
|
||||||
|
private $listExtractorTag;
|
||||||
|
private $typeExtractorTag;
|
||||||
|
private $descriptionExtractorTag;
|
||||||
|
private $accessExtractorTag;
|
||||||
|
|
||||||
|
public function __construct($propertyInfoService = 'property_info', $listExtractorTag = 'property_info.list_extractor', $typeExtractorTag = 'property_info.type_extractor', $descriptionExtractorTag = 'property_info.description_extractor', $accessExtractorTag = 'property_info.access_extractor')
|
||||||
|
{
|
||||||
|
$this->propertyInfoService = $propertyInfoService;
|
||||||
|
$this->listExtractorTag = $listExtractorTag;
|
||||||
|
$this->typeExtractorTag = $typeExtractorTag;
|
||||||
|
$this->descriptionExtractorTag = $descriptionExtractorTag;
|
||||||
|
$this->accessExtractorTag = $accessExtractorTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
if (!$container->hasDefinition($this->propertyInfoService)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$definition = $container->getDefinition($this->propertyInfoService);
|
||||||
|
|
||||||
|
$listExtractors = $this->findAndSortTaggedServices($this->listExtractorTag, $container);
|
||||||
|
$definition->replaceArgument(0, new IteratorArgument($listExtractors));
|
||||||
|
|
||||||
|
$typeExtractors = $this->findAndSortTaggedServices($this->typeExtractorTag, $container);
|
||||||
|
$definition->replaceArgument(1, new IteratorArgument($typeExtractors));
|
||||||
|
|
||||||
|
$descriptionExtractors = $this->findAndSortTaggedServices($this->descriptionExtractorTag, $container);
|
||||||
|
$definition->replaceArgument(2, new IteratorArgument($descriptionExtractors));
|
||||||
|
|
||||||
|
$accessExtractors = $this->findAndSortTaggedServices($this->accessExtractorTag, $container);
|
||||||
|
$definition->replaceArgument(3, new IteratorArgument($accessExtractors));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
<?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\PropertyInfo\Tests\DependencyInjection;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
|
||||||
|
|
||||||
|
class PropertyInfoPassTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testServicesAreOrderedAccordingToPriority()
|
||||||
|
{
|
||||||
|
$services = array(
|
||||||
|
'n3' => array('tag' => array()),
|
||||||
|
'n1' => array('tag' => array('priority' => 200)),
|
||||||
|
'n2' => array('tag' => array('priority' => 100)),
|
||||||
|
);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
new Reference('n1'),
|
||||||
|
new Reference('n2'),
|
||||||
|
new Reference('n3'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
|
||||||
|
|
||||||
|
$container
|
||||||
|
->expects($this->any())
|
||||||
|
->method('findTaggedServiceIds')
|
||||||
|
->will($this->returnValue($services));
|
||||||
|
|
||||||
|
$propertyInfoPass = new PropertyInfoPass();
|
||||||
|
|
||||||
|
$method = new \ReflectionMethod(
|
||||||
|
'Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass',
|
||||||
|
'findAndSortTaggedServices'
|
||||||
|
);
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$actual = $method->invoke($propertyInfoPass, 'tag', $container);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
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\Component\PropertyInfo\DependencyInjection\PropertyInfoPass',
|
||||||
|
'findAndSortTaggedServices'
|
||||||
|
);
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$actual = $method->invoke($propertyInfoPass, 'tag', $container);
|
||||||
|
|
||||||
|
$this->assertEquals(array(), $actual);
|
||||||
|
}
|
||||||
|
}
|
@ -29,12 +29,14 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/serializer": "~2.8|~3.0",
|
"symfony/serializer": "~2.8|~3.0",
|
||||||
"symfony/cache": "~3.1",
|
"symfony/cache": "~3.1",
|
||||||
|
"symfony/dependency-injection": "~3.3",
|
||||||
"phpdocumentor/reflection-docblock": "^3.0",
|
"phpdocumentor/reflection-docblock": "^3.0",
|
||||||
"doctrine/annotations": "~1.0"
|
"doctrine/annotations": "~1.0"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"phpdocumentor/reflection-docblock": "<3.0",
|
"phpdocumentor/reflection-docblock": "<3.0",
|
||||||
"phpdocumentor/type-resolver": "<0.2.0"
|
"phpdocumentor/type-resolver": "<0.2.0",
|
||||||
|
"symfony/dependency-injection": "<3.3"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"psr/cache-implementation": "To cache results",
|
"psr/cache-implementation": "To cache results",
|
||||||
|
Reference in New Issue
Block a user