diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 792fe3fc2062..8f08c8777009 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -236,6 +236,10 @@ FrameworkBundle class has been deprecated and will be removed in 4.0. Use the `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` class instead. + * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass` + class has been deprecated and will be removed in 4.0. Use the + `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` class instead. + HttpFoundation -------------- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 1375d6ffab86..ef331de9ff3c 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -326,6 +326,10 @@ FrameworkBundle removed. Use the `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` class instead. + * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass` class + has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` + class instead. + HttpFoundation -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index e733a6a0bff2..e9b83f6a7da6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -45,6 +45,8 @@ CHANGELOG `Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass` instead * Deprecated `AddConstraintValidatorsPass`, use `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` instead + * Deprecated `ValidateWorkflowsPass`, use + `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` instead 3.2.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php index 8034e441e6c3..6599f1f1a030 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php @@ -11,54 +11,15 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Exception\RuntimeException; -use Symfony\Component\Workflow\Validator\DefinitionValidatorInterface; -use Symfony\Component\Workflow\Validator\StateMachineValidator; -use Symfony\Component\Workflow\Validator\WorkflowValidator; +use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass as BaseValidateWorkflowsPass; + +@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', ValidateWorkflowsPass::class, BaseValidateWorkflowsPass::class), E_USER_DEPRECATED); /** * @author Tobias Nyholm + * + * @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseValidateWorkflowsPass} instead */ -class ValidateWorkflowsPass implements CompilerPassInterface +class ValidateWorkflowsPass extends BaseValidateWorkflowsPass { - public function process(ContainerBuilder $container) - { - $taggedServices = $container->findTaggedServiceIds('workflow.definition', true); - foreach ($taggedServices as $id => $tags) { - $definition = $container->get($id); - foreach ($tags as $tag) { - if (!array_key_exists('name', $tag)) { - throw new RuntimeException(sprintf('The "name" for the tag "workflow.definition" of service "%s" must be set.', $id)); - } - if (!array_key_exists('type', $tag)) { - throw new RuntimeException(sprintf('The "type" for the tag "workflow.definition" of service "%s" must be set.', $id)); - } - if (!array_key_exists('marking_store', $tag)) { - throw new RuntimeException(sprintf('The "marking_store" for the tag "workflow.definition" of service "%s" must be set.', $id)); - } - - $this->createValidator($tag)->validate($definition, $tag['name']); - } - } - } - - /** - * @param array $tag - * - * @return DefinitionValidatorInterface - */ - private function createValidator($tag) - { - if ('state_machine' === $tag['type']) { - return new StateMachineValidator(); - } - - if ('single_state' === $tag['marking_store']) { - return new WorkflowValidator(true); - } - - return new WorkflowValidator(); - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 8af5aa5228f7..1794a86f9248 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -28,7 +28,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass; use Symfony\Component\Config\DependencyInjection\ConfigCachePass; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass; @@ -48,6 +47,7 @@ use Symfony\Component\Config\Resource\ClassExistenceResource; use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass; use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass; +use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass; /** * Bundle. @@ -106,7 +106,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new DataCollectorTranslatorPass()); $container->addCompilerPass(new ControllerArgumentValueResolverPass()); $container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32); - $container->addCompilerPass(new ValidateWorkflowsPass()); + $this->addCompilerPassIfExists($container, ValidateWorkflowsPass::class); $container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING); $this->addCompilerPassIfExists($container, FormPass::class); diff --git a/src/Symfony/Component/Workflow/CHANGELOG.md b/src/Symfony/Component/Workflow/CHANGELOG.md index 47353c995aab..51a52777dfa8 100644 --- a/src/Symfony/Component/Workflow/CHANGELOG.md +++ b/src/Symfony/Component/Workflow/CHANGELOG.md @@ -14,3 +14,4 @@ CHANGELOG * Added support for `Event::getWorkflowName()`. * Added `SupportStrategyInterface` to allow custom strategies to decide whether or not a workflow supports a subject. + * Added `ValidateWorkflowPass`. diff --git a/src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php b/src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php new file mode 100644 index 000000000000..7100095735de --- /dev/null +++ b/src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\DependencyInjection; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; +use Symfony\Component\Workflow\Validator\StateMachineValidator; +use Symfony\Component\Workflow\Validator\WorkflowValidator; + +/** + * @author Tobias Nyholm + */ +class ValidateWorkflowsPass implements CompilerPassInterface +{ + private $definitionTag; + + public function __construct($definitionTag = 'workflow.definition') + { + $this->definitionTag = $definitionTag; + } + + public function process(ContainerBuilder $container) + { + $taggedServices = $container->findTaggedServiceIds($this->definitionTag, true); + foreach ($taggedServices as $id => $tags) { + foreach ($tags as $tag) { + if (!array_key_exists('name', $tag)) { + throw new RuntimeException(sprintf('The "name" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id)); + } + if (!array_key_exists('type', $tag)) { + throw new RuntimeException(sprintf('The "type" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id)); + } + if (!array_key_exists('marking_store', $tag)) { + throw new RuntimeException(sprintf('The "marking_store" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id)); + } + + $this->createValidator($tag)->validate($container->get($id), $tag['name']); + } + } + } + + private function createValidator($tag) + { + if ('state_machine' === $tag['type']) { + return new StateMachineValidator(); + } + + if ('single_state' === $tag['marking_store']) { + return new WorkflowValidator(true); + } + + return new WorkflowValidator(); + } +} diff --git a/src/Symfony/Component/Workflow/Tests/DependencyInjection/ValidateWorkflowsPassTest.php b/src/Symfony/Component/Workflow/Tests/DependencyInjection/ValidateWorkflowsPassTest.php new file mode 100644 index 000000000000..3b7ddf6d6d7a --- /dev/null +++ b/src/Symfony/Component/Workflow/Tests/DependencyInjection/ValidateWorkflowsPassTest.php @@ -0,0 +1,30 @@ +getMockBuilder(ContainerBuilder::class)->getMock(); + $container + ->expects($this->once()) + ->method('findTaggedServiceIds') + ->with('workflow.definition') + ->willReturn(array('definition1' => array('workflow.definition' => array('name' => 'wf1', 'type' => 'state_machine', 'marking_store' => 'foo')))); + + $container + ->expects($this->once()) + ->method('get') + ->with('definition1') + ->willReturn(new Definition(array('a', 'b', 'c'), array(new Transition('t1', 'a', 'b'), new Transition('t2', 'a', 'c')))); + + (new ValidateWorkflowsPass())->process($container); + } +} diff --git a/src/Symfony/Component/Workflow/composer.json b/src/Symfony/Component/Workflow/composer.json index 66f8f65dc041..cba7243523f7 100644 --- a/src/Symfony/Component/Workflow/composer.json +++ b/src/Symfony/Component/Workflow/composer.json @@ -25,6 +25,7 @@ }, "require-dev": { "psr/log": "~1.0", + "symfony/dependency-injection": "~2.8|~3.0", "symfony/event-dispatcher": "~2.1|~3.0", "symfony/expression-language": "~2.8|~3.0", "symfony/security-core": "~2.8|~3.0"