Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle][PropertyInfo] Move PropertyInfoPass to the PropertyInfo component #21806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 4 UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ FrameworkBundle
deprecated and will be removed in 4.0. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass`
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
-----------

Expand Down
3 changes: 3 additions & 0 deletions 3 UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ FrameworkBundle
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been removed.
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
---------------
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CHANGELOG
* Deprecated `TestSessionListener`
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`.
Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead.
* Deprecated `PropertyInfoPass`, use `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` instead

3.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,17 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@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 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));
}
}
4 changes: 2 additions & 2 deletions 4 src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
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\TemplatingPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
Expand All @@ -37,6 +36,7 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new TranslationDumperPass());
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
$this->addCompilerPassIfExists($container, SerializerPass::class);
$container->addCompilerPass(new PropertyInfoPass());
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
$container->addCompilerPass(new DataCollectorTranslatorPass());
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
use Symfony\Component\DependencyInjection\Reference;

/**
* @group legacy
*/
class PropertyInfoPassTest extends TestCase
{
public function testServicesAreOrderedAccordingToPriority()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

3.3.0
-----

* Added `PropertyInfoPass`
Original file line number Diff line number Diff line change
@@ -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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this kind of extension point really needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think, we did it for each other (see #20250 (comment))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? It allows configuring multiple property info services in an application easily.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It adds stuff to maintain and I'm not sure it's really useful, but if you think it is why not.

{
$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));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 3 additions & 1 deletion 4 src/Symfony/Component/PropertyInfo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
"require-dev": {
"symfony/serializer": "~2.8|~3.0",
"symfony/cache": "~3.1",
"symfony/dependency-injection": "~3.3",
"phpdocumentor/reflection-docblock": "^3.0",
"doctrine/annotations": "~1.0"
},
"conflict": {
"phpdocumentor/reflection-docblock": "<3.0",
"phpdocumentor/type-resolver": "<0.2.0"
"phpdocumentor/type-resolver": "<0.2.0",
"symfony/dependency-injection": "<3.3"
},
"suggest": {
"psr/cache-implementation": "To cache results",
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.