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

[Form][FrameworkBundle] Move FormPass to the Form component #21283

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
Feb 16, 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 @@ -35,6 +35,10 @@ FrameworkBundle

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

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass` class has been
deprecated and will be removed in 4.0. Use the `Symfony\Component\Form\DependencyInjection\FormPass`
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 @@ -156,6 +156,9 @@ FrameworkBundle

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

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass` class has been
removed. Use the `Symfony\Component\Form\DependencyInjection\FormPass` class instead.

SecurityBundle
--------------

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CHANGELOG
is disabled.
* Added `GlobalVariables::getToken()`
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
* Added configurable paths for validation files
* Deprecated `FormPass`, use `Symfony\Component\Form\DependencyInjection\FormPass` instead.

3.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,18 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@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\Form\DependencyInjection\FormPass as BaseFormPass;

/**
* Adds all services with the tags "form.type" and "form.type_guesser" as
* arguments of the "form.extension" service.
*
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseFormPass} instead.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormPass implements CompilerPassInterface
class FormPass extends BaseFormPass
{
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()) {
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form types are lazy-loaded.', $serviceId));
}

// 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()) {
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type extensions are lazy-loaded.', $serviceId));
}

$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()) {
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type guessers are lazy-loaded.', $serviceId));
}
}

$definition->replaceArgument(3, $guessers);
}
}
18 changes: 13 additions & 5 deletions 18 src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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\FormPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
Expand All @@ -42,8 +41,10 @@
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
use Symfony\Component\Form\DependencyInjection\FormPass;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\Config\Resource\ClassExistenceResource;

/**
* Bundle.
Expand Down Expand Up @@ -81,10 +82,6 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new TemplatingPass());
$container->addCompilerPass(new AddConstraintValidatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new AddValidatorInitializersPass());
if (class_exists(AddConsoleCommandPass::class)) {
$container->addCompilerPass(new AddConsoleCommandPass());
}
$container->addCompilerPass(new FormPass());
$container->addCompilerPass(new TranslatorPass());
$container->addCompilerPass(new LoggingTranslatorPass());
$container->addCompilerPass(new AddCacheWarmerPass());
Expand All @@ -99,6 +96,8 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
$container->addCompilerPass(new ValidateWorkflowsPass());
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
$this->addCompilerPassIfExists($container, FormPass::class);

if ($container->getParameter('kernel.debug')) {
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
Expand All @@ -109,4 +108,13 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new CacheCollectorPass());
}
}

private function addCompilerPassIfExists(ContainerBuilder $container, $class, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0)
{
$container->addResource(new ClassExistenceResource($class));

if (class_exists($class)) {
$container->addCompilerPass(new $class(), $type, $priority);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Form\AbstractType;

/**
* @group legacy
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormPassTest extends \PHPUnit_Framework_TestCase
Expand Down
5 changes: 3 additions & 2 deletions 5 src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"symfony/dom-crawler": "~2.8|~3.0",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/security": "~2.8|~3.0",
"symfony/form": "~2.8.16|~3.1.9|^3.2.2",
"symfony/form": "~3.3",
"symfony/expression-language": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0",
"symfony/security-core": "~3.2",
Expand All @@ -57,7 +57,8 @@
"conflict": {
"phpdocumentor/reflection-docblock": "<3.0",
"phpdocumentor/type-resolver": "<0.2.0",
"symfony/console": "<3.3"
"symfony/console": "<3.3",
"symfony/form": "<3.3"
},
"suggest": {
"ext-apcu": "For best performance of the system caches",
Expand Down
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.3.0
-----

* added `FormPass`

3.2.0
-----

Expand Down
95 changes: 95 additions & 0 deletions 95 src/Symfony/Component/Form/DependencyInjection/FormPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?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\Form\DependencyInjection;

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>
*/
class FormPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

private $formExtensionService;
private $formTypeTag;
private $formTypeExtensionTag;
private $formTypeGuesserTag;

public function __construct($formExtensionService = 'form.extension', $formTypeTag = 'form.type', $formTypeExtensionTag = 'form.type_extension', $formTypeGuesserTag = 'form.type_guesser')
{
$this->formExtensionService = $formExtensionService;
$this->formTypeTag = $formTypeTag;
$this->formTypeExtensionTag = $formTypeExtensionTag;
$this->formTypeGuesserTag = $formTypeGuesserTag;
}

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->formExtensionService)) {
return;
}

$definition = $container->getDefinition($this->formExtensionService);

// Builds an array with fully-qualified type class names as keys and service IDs as values
$types = array();
foreach ($container->findTaggedServiceIds($this->formTypeTag) as $serviceId => $tag) {
$serviceDefinition = $container->getDefinition($serviceId);
if (!$serviceDefinition->isPublic()) {
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form types are lazy-loaded.', $serviceId));
}

// Support type access by FQCN
$types[$serviceDefinition->getClass()] = $serviceId;
}

$definition->replaceArgument(1, $types);

$typeExtensions = array();

foreach ($this->findAndSortTaggedServices($this->formTypeExtensionTag, $container) as $reference) {
$serviceId = (string) $reference;
$serviceDefinition = $container->getDefinition($serviceId);
if (!$serviceDefinition->isPublic()) {
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type extensions are lazy-loaded.', $serviceId));
}

$tag = $serviceDefinition->getTag($this->formTypeExtensionTag);
if (isset($tag[0]['extended_type'])) {
$extendedType = $tag[0]['extended_type'];
} else {
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));
}

$typeExtensions[$extendedType][] = $serviceId;
}

$definition->replaceArgument(2, $typeExtensions);

$guessers = array_keys($container->findTaggedServiceIds($this->formTypeGuesserTag));
foreach ($guessers as $serviceId) {
$serviceDefinition = $container->getDefinition($serviceId);
if (!$serviceDefinition->isPublic()) {
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type guessers are lazy-loaded.', $serviceId));
}
}

$definition->replaceArgument(3, $guessers);
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.