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

Commit 923d50b

Browse filesBrowse files
committed
feature #21283 [Form][FrameworkBundle] Move FormPass to the Form component (chalasr)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Form][FrameworkBundle] Move FormPass to the Form component | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a So that anyone using only Form and DI can use it for registering form types/type guessers. Follows #19443, related to #21284 Commits ------- e68a6d9 [FrameworkBundle][Form] Move FormPass to the Form component
2 parents 846d24a + e68a6d9 commit 923d50b
Copy full SHA for 923d50b

File tree

11 files changed

+352
-70
lines changed
Filter options

11 files changed

+352
-70
lines changed

‎UPGRADE-3.3.md

Copy file name to clipboardExpand all lines: UPGRADE-3.3.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ FrameworkBundle
6161
deprecated and will be removed in 4.0.
6262
Use the `Symfony\Component\Serializer\DependencyInjection\SerializerPass` class instead.
6363

64+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass` class has been
65+
deprecated and will be removed in 4.0. Use the `Symfony\Component\Form\DependencyInjection\FormPass`
66+
class instead.
67+
6468
HttpKernel
6569
-----------
6670

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ FrameworkBundle
179179
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass` class has been removed.
180180
Use the `Symfony\Component\Serializer\DependencyInjection\SerializerPass` class instead.
181181

182+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass` class has been
183+
removed. Use the `Symfony\Component\Form\DependencyInjection\FormPass` class instead.
184+
182185
SecurityBundle
183186
--------------
184187

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHANGELOG
1414
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
1515
* Added configurable paths for validation files
1616
* Deprecated `SerializerPass`, use `Symfony\Component\Serializer\DependencyInjection\SerializerPass` instead.
17+
* Deprecated `FormPass`, use `Symfony\Component\Form\DependencyInjection\FormPass` instead.
1718

1819
3.2.0
1920
-----

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php
+6-62Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,74 +11,18 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
14+
@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);
15+
16+
use Symfony\Component\Form\DependencyInjection\FormPass as BaseFormPass;
1817

1918
/**
2019
* Adds all services with the tags "form.type" and "form.type_guesser" as
2120
* arguments of the "form.extension" service.
2221
*
22+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseFormPass} instead.
23+
*
2324
* @author Bernhard Schussek <bschussek@gmail.com>
2425
*/
25-
class FormPass implements CompilerPassInterface
26+
class FormPass extends BaseFormPass
2627
{
27-
use PriorityTaggedServiceTrait;
28-
29-
public function process(ContainerBuilder $container)
30-
{
31-
if (!$container->hasDefinition('form.extension')) {
32-
return;
33-
}
34-
35-
$definition = $container->getDefinition('form.extension');
36-
37-
// Builds an array with fully-qualified type class names as keys and service IDs as values
38-
$types = array();
39-
40-
foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) {
41-
$serviceDefinition = $container->getDefinition($serviceId);
42-
if (!$serviceDefinition->isPublic()) {
43-
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form types are lazy-loaded.', $serviceId));
44-
}
45-
46-
// Support type access by FQCN
47-
$types[$serviceDefinition->getClass()] = $serviceId;
48-
}
49-
50-
$definition->replaceArgument(1, $types);
51-
52-
$typeExtensions = array();
53-
54-
foreach ($this->findAndSortTaggedServices('form.type_extension', $container) as $reference) {
55-
$serviceId = (string) $reference;
56-
$serviceDefinition = $container->getDefinition($serviceId);
57-
if (!$serviceDefinition->isPublic()) {
58-
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type extensions are lazy-loaded.', $serviceId));
59-
}
60-
61-
$tag = $serviceDefinition->getTag('form.type_extension');
62-
if (isset($tag[0]['extended_type'])) {
63-
$extendedType = $tag[0]['extended_type'];
64-
} else {
65-
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));
66-
}
67-
68-
$typeExtensions[$extendedType][] = $serviceId;
69-
}
70-
71-
$definition->replaceArgument(2, $typeExtensions);
72-
73-
// Find all services annotated with "form.type_guesser"
74-
$guessers = array_keys($container->findTaggedServiceIds('form.type_guesser'));
75-
foreach ($guessers as $serviceId) {
76-
$serviceDefinition = $container->getDefinition($serviceId);
77-
if (!$serviceDefinition->isPublic()) {
78-
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type guessers are lazy-loaded.', $serviceId));
79-
}
80-
}
81-
82-
$definition->replaceArgument(3, $guessers);
83-
}
8428
}

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
2020
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
2121
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
22-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
2322
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
2423
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
2524
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
@@ -43,8 +42,10 @@
4342
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
4443
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
4544
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
45+
use Symfony\Component\Form\DependencyInjection\FormPass;
4646
use Symfony\Component\HttpFoundation\Request;
4747
use Symfony\Component\HttpKernel\Bundle\Bundle;
48+
use Symfony\Component\Config\Resource\ClassExistenceResource;
4849

4950
/**
5051
* Bundle.
@@ -83,10 +84,6 @@ public function build(ContainerBuilder $container)
8384
$container->addCompilerPass(new AddConstraintValidatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
8485
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
8586
$container->addCompilerPass(new AddValidatorInitializersPass());
86-
if (class_exists(AddConsoleCommandPass::class)) {
87-
$container->addCompilerPass(new AddConsoleCommandPass());
88-
}
89-
$container->addCompilerPass(new FormPass());
9087
$container->addCompilerPass(new TranslatorPass());
9188
$container->addCompilerPass(new LoggingTranslatorPass());
9289
$container->addCompilerPass(new AddCacheWarmerPass());
@@ -103,6 +100,8 @@ public function build(ContainerBuilder $container)
103100
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
104101
$container->addCompilerPass(new ValidateWorkflowsPass());
105102
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
103+
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
104+
$this->addCompilerPassIfExists($container, FormPass::class);
106105

107106
if ($container->getParameter('kernel.debug')) {
108107
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
@@ -113,4 +112,13 @@ public function build(ContainerBuilder $container)
113112
$container->addCompilerPass(new CacheCollectorPass());
114113
}
115114
}
115+
116+
private function addCompilerPassIfExists(ContainerBuilder $container, $class, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0)
117+
{
118+
$container->addResource(new ClassExistenceResource($class));
119+
120+
if (class_exists($class)) {
121+
$container->addCompilerPass(new $class(), $type, $priority);
122+
}
123+
}
116124
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\Form\AbstractType;
1919

2020
/**
21+
* @group legacy
22+
*
2123
* @author Bernhard Schussek <bschussek@gmail.com>
2224
*/
2325
class FormPassTest extends \PHPUnit_Framework_TestCase

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"symfony/dom-crawler": "~2.8|~3.0",
4242
"symfony/polyfill-intl-icu": "~1.0",
4343
"symfony/security": "~2.8|~3.0",
44-
"symfony/form": "~2.8.16|~3.1.9|^3.2.2",
44+
"symfony/form": "~3.3",
4545
"symfony/expression-language": "~2.8|~3.0",
4646
"symfony/process": "~2.8|~3.0",
4747
"symfony/security-core": "~3.2",
@@ -61,7 +61,8 @@
6161
"phpdocumentor/reflection-docblock": "<3.0",
6262
"phpdocumentor/type-resolver": "<0.2.0",
6363
"symfony/console": "<3.3",
64-
"symfony/serializer": "<3.3"
64+
"symfony/serializer": "<3.3",
65+
"symfony/form": "<3.3"
6566
},
6667
"suggest": {
6768
"ext-apcu": "For best performance of the system caches",

‎src/Symfony/Component/Form/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* added `FormPass`
8+
49
3.2.0
510
-----
611

+95Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
18+
19+
/**
20+
* Adds all services with the tags "form.type" and "form.type_guesser" as
21+
* arguments of the "form.extension" service.
22+
*
23+
* @author Bernhard Schussek <bschussek@gmail.com>
24+
*/
25+
class FormPass implements CompilerPassInterface
26+
{
27+
use PriorityTaggedServiceTrait;
28+
29+
private $formExtensionService;
30+
private $formTypeTag;
31+
private $formTypeExtensionTag;
32+
private $formTypeGuesserTag;
33+
34+
public function __construct($formExtensionService = 'form.extension', $formTypeTag = 'form.type', $formTypeExtensionTag = 'form.type_extension', $formTypeGuesserTag = 'form.type_guesser')
35+
{
36+
$this->formExtensionService = $formExtensionService;
37+
$this->formTypeTag = $formTypeTag;
38+
$this->formTypeExtensionTag = $formTypeExtensionTag;
39+
$this->formTypeGuesserTag = $formTypeGuesserTag;
40+
}
41+
42+
public function process(ContainerBuilder $container)
43+
{
44+
if (!$container->hasDefinition($this->formExtensionService)) {
45+
return;
46+
}
47+
48+
$definition = $container->getDefinition($this->formExtensionService);
49+
50+
// Builds an array with fully-qualified type class names as keys and service IDs as values
51+
$types = array();
52+
foreach ($container->findTaggedServiceIds($this->formTypeTag) as $serviceId => $tag) {
53+
$serviceDefinition = $container->getDefinition($serviceId);
54+
if (!$serviceDefinition->isPublic()) {
55+
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form types are lazy-loaded.', $serviceId));
56+
}
57+
58+
// Support type access by FQCN
59+
$types[$serviceDefinition->getClass()] = $serviceId;
60+
}
61+
62+
$definition->replaceArgument(1, $types);
63+
64+
$typeExtensions = array();
65+
66+
foreach ($this->findAndSortTaggedServices($this->formTypeExtensionTag, $container) as $reference) {
67+
$serviceId = (string) $reference;
68+
$serviceDefinition = $container->getDefinition($serviceId);
69+
if (!$serviceDefinition->isPublic()) {
70+
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type extensions are lazy-loaded.', $serviceId));
71+
}
72+
73+
$tag = $serviceDefinition->getTag($this->formTypeExtensionTag);
74+
if (isset($tag[0]['extended_type'])) {
75+
$extendedType = $tag[0]['extended_type'];
76+
} else {
77+
throw new InvalidArgumentException(sprintf('"%s" tagged services must have the extended type configured using the extended_type/extended-type attribute, none was configured for the "%s" service.', $this->formTypeExtensionTag, $serviceId));
78+
}
79+
80+
$typeExtensions[$extendedType][] = $serviceId;
81+
}
82+
83+
$definition->replaceArgument(2, $typeExtensions);
84+
85+
$guessers = array_keys($container->findTaggedServiceIds($this->formTypeGuesserTag));
86+
foreach ($guessers as $serviceId) {
87+
$serviceDefinition = $container->getDefinition($serviceId);
88+
if (!$serviceDefinition->isPublic()) {
89+
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type guessers are lazy-loaded.', $serviceId));
90+
}
91+
}
92+
93+
$definition->replaceArgument(3, $guessers);
94+
}
95+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.