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 8fe122f

Browse filesBrowse files
committed
Move ValidateWorkflowsPass to the Workflow component
1 parent bbe269f commit 8fe122f
Copy full SHA for 8fe122f

File tree

Expand file treeCollapse file tree

9 files changed

+114
-47
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+114
-47
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
@@ -236,6 +236,10 @@ FrameworkBundle
236236
class has been deprecated and will be removed in 4.0.
237237
Use the `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` class instead.
238238

239+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass`
240+
class has been deprecated and will be removed in 4.0. Use the
241+
`Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` class instead.
242+
239243
HttpFoundation
240244
--------------
241245

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ FrameworkBundle
326326
removed. Use the `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass`
327327
class instead.
328328

329+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass` class
330+
has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass`
331+
class instead.
332+
329333
HttpFoundation
330334
--------------
331335

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ CHANGELOG
4545
`Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass` instead
4646
* Deprecated `AddConstraintValidatorsPass`, use
4747
`Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` instead
48+
* Deprecated `ValidateWorkflowsPass`, use
49+
`Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` instead
4850

4951
3.2.0
5052
-----

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

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

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

14-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
17-
use Symfony\Component\Workflow\Validator\DefinitionValidatorInterface;
18-
use Symfony\Component\Workflow\Validator\StateMachineValidator;
19-
use Symfony\Component\Workflow\Validator\WorkflowValidator;
14+
use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass as BaseValidateWorkflowsPass;
15+
16+
@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);
2017

2118
/**
2219
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
20+
*
21+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseValidateWorkflowsPass} instead
2322
*/
24-
class ValidateWorkflowsPass implements CompilerPassInterface
23+
class ValidateWorkflowsPass extends BaseValidateWorkflowsPass
2524
{
26-
public function process(ContainerBuilder $container)
27-
{
28-
$taggedServices = $container->findTaggedServiceIds('workflow.definition', true);
29-
foreach ($taggedServices as $id => $tags) {
30-
$definition = $container->get($id);
31-
foreach ($tags as $tag) {
32-
if (!array_key_exists('name', $tag)) {
33-
throw new RuntimeException(sprintf('The "name" for the tag "workflow.definition" of service "%s" must be set.', $id));
34-
}
35-
if (!array_key_exists('type', $tag)) {
36-
throw new RuntimeException(sprintf('The "type" for the tag "workflow.definition" of service "%s" must be set.', $id));
37-
}
38-
if (!array_key_exists('marking_store', $tag)) {
39-
throw new RuntimeException(sprintf('The "marking_store" for the tag "workflow.definition" of service "%s" must be set.', $id));
40-
}
41-
42-
$this->createValidator($tag)->validate($definition, $tag['name']);
43-
}
44-
}
45-
}
46-
47-
/**
48-
* @param array $tag
49-
*
50-
* @return DefinitionValidatorInterface
51-
*/
52-
private function createValidator($tag)
53-
{
54-
if ('state_machine' === $tag['type']) {
55-
return new StateMachineValidator();
56-
}
57-
58-
if ('single_state' === $tag['marking_store']) {
59-
return new WorkflowValidator(true);
60-
}
61-
62-
return new WorkflowValidator();
63-
}
6425
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
2929
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
3030
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
31-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
3231
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
3332
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
3433
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
@@ -48,6 +47,7 @@
4847
use Symfony\Component\Config\Resource\ClassExistenceResource;
4948
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
5049
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
50+
use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass;
5151

5252
/**
5353
* Bundle.
@@ -106,7 +106,7 @@ public function build(ContainerBuilder $container)
106106
$container->addCompilerPass(new DataCollectorTranslatorPass());
107107
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
108108
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
109-
$container->addCompilerPass(new ValidateWorkflowsPass());
109+
$this->addCompilerPassIfExists($container, ValidateWorkflowsPass::class);
110110
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
111111
$this->addCompilerPassIfExists($container, FormPass::class);
112112

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ CHANGELOG
1414
* Added support for `Event::getWorkflowName()`.
1515
* Added `SupportStrategyInterface` to allow custom strategies to decide whether
1616
or not a workflow supports a subject.
17+
* Added `ValidateWorkflowPass`.
+64Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\Workflow\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
17+
use Symfony\Component\Workflow\Validator\StateMachineValidator;
18+
use Symfony\Component\Workflow\Validator\WorkflowValidator;
19+
20+
/**
21+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
22+
*/
23+
class ValidateWorkflowsPass implements CompilerPassInterface
24+
{
25+
private $definitionTag;
26+
27+
public function __construct($definitionTag = 'workflow.definition')
28+
{
29+
$this->definitionTag = $definitionTag;
30+
}
31+
32+
public function process(ContainerBuilder $container)
33+
{
34+
$taggedServices = $container->findTaggedServiceIds($this->definitionTag, true);
35+
foreach ($taggedServices as $id => $tags) {
36+
foreach ($tags as $tag) {
37+
if (!array_key_exists('name', $tag)) {
38+
throw new RuntimeException(sprintf('The "name" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id));
39+
}
40+
if (!array_key_exists('type', $tag)) {
41+
throw new RuntimeException(sprintf('The "type" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id));
42+
}
43+
if (!array_key_exists('marking_store', $tag)) {
44+
throw new RuntimeException(sprintf('The "marking_store" for the tag "%s" of service "%s" must be set.', $this->definitionTag, $id));
45+
}
46+
47+
$this->createValidator($tag)->validate($container->get($id), $tag['name']);
48+
}
49+
}
50+
}
51+
52+
private function createValidator($tag)
53+
{
54+
if ('state_machine' === $tag['type']) {
55+
return new StateMachineValidator();
56+
}
57+
58+
if ('single_state' === $tag['marking_store']) {
59+
return new WorkflowValidator(true);
60+
}
61+
62+
return new WorkflowValidator();
63+
}
64+
}
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Symfony\Component\Workflow\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\Workflow\Definition;
8+
use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass;
9+
use Symfony\Component\Workflow\Transition;
10+
11+
class ValidateWorkflowsPassTest extends TestCase
12+
{
13+
public function testProcess()
14+
{
15+
$container = $this->getMockBuilder(ContainerBuilder::class)->getMock();
16+
$container
17+
->expects($this->once())
18+
->method('findTaggedServiceIds')
19+
->with('workflow.definition')
20+
->willReturn(array('definition1' => array('workflow.definition' => array('name' => 'wf1', 'type' => 'state_machine', 'marking_store' => 'foo'))));
21+
22+
$container
23+
->expects($this->once())
24+
->method('get')
25+
->with('definition1')
26+
->willReturn(new Definition(array('a', 'b', 'c'), array(new Transition('t1', 'a', 'b'), new Transition('t2', 'a', 'c'))));
27+
28+
(new ValidateWorkflowsPass())->process($container);
29+
}
30+
}

‎src/Symfony/Component/Workflow/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"require-dev": {
2727
"psr/log": "~1.0",
28+
"symfony/dependency-injection": "~2.8|~3.0",
2829
"symfony/event-dispatcher": "~2.1|~3.0",
2930
"symfony/expression-language": "~2.8|~3.0",
3031
"symfony/security-core": "~2.8|~3.0"

0 commit comments

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