Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c91c6d

Browse files
committed
[FrameworkBundle][Form] Move FormPass to the Form component
1 parent cc398db commit 2c91c6d

File tree

11 files changed

+338
-70
lines changed

11 files changed

+338
-70
lines changed

UPGRADE-3.3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ FrameworkBundle
3636

3737
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
3838

39+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass` class has been
40+
deprecated and will be removed in 4.0. Use the `Symfony\Component\Form\DependencyInjection\FormPass`
41+
class instead.
42+
3943
HttpKernel
4044
-----------
4145

UPGRADE-4.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ FrameworkBundle
157157

158158
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been removed. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
159159

160+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass` class has been
161+
removed. Use the `Symfony\Component\Form\DependencyInjection\FormPass` class instead.
162+
160163
SecurityBundle
161164
--------------
162165

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
is disabled.
1313
* Added `GlobalVariables::getToken()`
1414
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
15+
* Deprecated `FormPass`, use `Symfony\Component\Form\DependencyInjection\FormPass` instead.
1516

1617
3.2.0
1718
-----

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

Lines 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 <[email protected]>
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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
20-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
2120
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
2221
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
2322
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
@@ -41,6 +40,7 @@
4140
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
4241
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
4342
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
43+
use Symfony\Component\Form\DependencyInjection\FormPass;
4444
use Symfony\Component\HttpFoundation\Request;
4545
use Symfony\Component\HttpKernel\Bundle\Bundle;
4646

@@ -80,10 +80,6 @@ public function build(ContainerBuilder $container)
8080
$container->addCompilerPass(new TemplatingPass());
8181
$container->addCompilerPass(new AddConstraintValidatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
8282
$container->addCompilerPass(new AddValidatorInitializersPass());
83-
if (class_exists(AddConsoleCommandPass::class)) {
84-
$container->addCompilerPass(new AddConsoleCommandPass());
85-
}
86-
$container->addCompilerPass(new FormPass());
8783
$container->addCompilerPass(new TranslatorPass());
8884
$container->addCompilerPass(new LoggingTranslatorPass());
8985
$container->addCompilerPass(new AddCacheWarmerPass());
@@ -98,6 +94,8 @@ public function build(ContainerBuilder $container)
9894
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
9995
$container->addCompilerPass(new ValidateWorkflowsPass());
10096
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
97+
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
98+
$this->addCompilerPassIfExists($container, FormPass::class);
10199

102100
if ($container->getParameter('kernel.debug')) {
103101
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
@@ -107,4 +105,11 @@ public function build(ContainerBuilder $container)
107105
$container->addCompilerPass(new ConfigCachePass());
108106
}
109107
}
108+
109+
private function addCompilerPassIfExists(ContainerBuilder $container, $class, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0)
110+
{
111+
if (class_exists($class)) {
112+
$container->addCompilerPass(new $class(), $type, $priority);
113+
}
114+
}
110115
}

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

Lines 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 <[email protected]>
2224
*/
2325
class FormPassTest extends \PHPUnit_Framework_TestCase

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"symfony/dom-crawler": "~2.8|~3.0",
4040
"symfony/polyfill-intl-icu": "~1.0",
4141
"symfony/security": "~2.8|~3.0",
42-
"symfony/form": "~2.8.16|~3.1.9|^3.2.2",
42+
"symfony/form": "~3.3",
4343
"symfony/expression-language": "~2.8|~3.0",
4444
"symfony/process": "~2.8|~3.0",
4545
"symfony/security-core": "~3.2",
@@ -57,7 +57,8 @@
5757
"conflict": {
5858
"phpdocumentor/reflection-docblock": "<3.0",
5959
"phpdocumentor/type-resolver": "<0.2.0",
60-
"symfony/console": "<3.3"
60+
"symfony/console": "<3.3",
61+
"symfony/form": "<3.3"
6162
},
6263
"suggest": {
6364
"ext-apcu": "For best performance of the system caches",

src/Symfony/Component/Form/CHANGELOG.md

Lines 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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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 <[email protected]>
24+
*/
25+
class FormPass implements CompilerPassInterface
26+
{
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+
}
84+
}

0 commit comments

Comments
 (0)