Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit164b919

Browse files
committed
[Workflow] Add some PHP attributes to register listeners and guards
1 parent5fcaa74 commit164b919

File tree

11 files changed

+388
-0
lines changed

11 files changed

+388
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,29 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11041104
$container->setParameter('workflow.has_guard_listeners',true);
11051105
}
11061106
}
1107+
1108+
$listenerAttributes = [
1109+
Workflow\Attribute\AsAnnounceListener::class,
1110+
Workflow\Attribute\AsCompletedListener::class,
1111+
Workflow\Attribute\AsEnterListener::class,
1112+
Workflow\Attribute\AsEnteredListener::class,
1113+
Workflow\Attribute\AsGuardListener::class,
1114+
Workflow\Attribute\AsLeaveListener::class,
1115+
Workflow\Attribute\AsTransitionListener::class,
1116+
];
1117+
1118+
foreach ($listenerAttributesas$attribute) {
1119+
$container->registerAttributeForAutoconfiguration($attribute,staticfunction (ChildDefinition$definition,AsEventListener$attribute,\ReflectionClass|\ReflectionMethod$reflector) {
1120+
$tagAttributes =get_object_vars($attribute);
1121+
if ($reflectorinstanceof \ReflectionMethod) {
1122+
if (isset($tagAttributes['method'])) {
1123+
thrownewLogicException(sprintf('%s attribute cannot declare a method on "%s::%s()".',$attribute::class,$reflector->class,$reflector->name));
1124+
}
1125+
$tagAttributes['method'] =$reflector->getName();
1126+
}
1127+
$definition->addTag('kernel.event_listener',$tagAttributes);
1128+
});
1129+
}
11071130
}
11081131

11091132
privatefunctionregisterDebugConfiguration(array$config,ContainerBuilder$container,PhpFileLoader$loader):void
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
useSymfony\Component\EventDispatcher\Attribute\AsEventListener;
15+
16+
/**
17+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
20+
finalclass AsAnnounceListenerextends AsEventListener
21+
{
22+
use BuildEventNameTrait;
23+
24+
publicfunction__construct(
25+
string$workflow =null,
26+
string$transition =null,
27+
string$method =null,
28+
int$priority =0,
29+
string$dispatcher =null,
30+
) {
31+
parent::__construct($this->buildEventName('announce','transition',$workflow,$transition),$method,$priority,$dispatcher);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
useSymfony\Component\EventDispatcher\Attribute\AsEventListener;
15+
16+
/**
17+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
20+
finalclass AsCompletedListenerextends AsEventListener
21+
{
22+
use BuildEventNameTrait;
23+
24+
publicfunction__construct(
25+
string$workflow =null,
26+
string$transition =null,
27+
string$method =null,
28+
int$priority =0,
29+
string$dispatcher =null,
30+
) {
31+
parent::__construct($this->buildEventName('completed','transition',$workflow,$transition),$method,$priority,$dispatcher);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
useSymfony\Component\EventDispatcher\Attribute\AsEventListener;
15+
16+
/**
17+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
20+
finalclass AsEnterListenerextends AsEventListener
21+
{
22+
use BuildEventNameTrait;
23+
24+
publicfunction__construct(
25+
string$workflow =null,
26+
string$place =null,
27+
string$method =null,
28+
int$priority =0,
29+
string$dispatcher =null,
30+
) {
31+
parent::__construct($this->buildEventName('enter','place',$workflow,$place),$method,$priority,$dispatcher);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
useSymfony\Component\EventDispatcher\Attribute\AsEventListener;
15+
16+
/**
17+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
20+
finalclass AsEnteredListenerextends AsEventListener
21+
{
22+
use BuildEventNameTrait;
23+
24+
publicfunction__construct(
25+
string$workflow =null,
26+
string$place =null,
27+
string$method =null,
28+
int$priority =0,
29+
string$dispatcher =null,
30+
) {
31+
parent::__construct($this->buildEventName('entered','place',$workflow,$place),$method,$priority,$dispatcher);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
useSymfony\Component\EventDispatcher\Attribute\AsEventListener;
15+
16+
/**
17+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
20+
finalclass AsGuardListenerextends AsEventListener
21+
{
22+
use BuildEventNameTrait;
23+
24+
publicfunction__construct(
25+
string$workflow =null,
26+
string$transition =null,
27+
string$method =null,
28+
int$priority =0,
29+
string$dispatcher =null,
30+
) {
31+
parent::__construct($this->buildEventName('guard','transition',$workflow,$transition),$method,$priority,$dispatcher);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
useSymfony\Component\EventDispatcher\Attribute\AsEventListener;
15+
16+
/**
17+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
20+
finalclass AsLeaveListenerextends AsEventListener
21+
{
22+
use BuildEventNameTrait;
23+
24+
publicfunction__construct(
25+
string$workflow =null,
26+
string$place =null,
27+
string$method =null,
28+
int$priority =0,
29+
string$dispatcher =null,
30+
) {
31+
parent::__construct($this->buildEventName('leave','place',$workflow,$place),$method,$priority,$dispatcher);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
useSymfony\Component\EventDispatcher\Attribute\AsEventListener;
15+
16+
/**
17+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
18+
*/
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
20+
finalclass AsTransitionListenerextends AsEventListener
21+
{
22+
use BuildEventNameTrait;
23+
24+
publicfunction__construct(
25+
string$workflow =null,
26+
string$transition =null,
27+
string$method =null,
28+
int$priority =0,
29+
string$dispatcher =null,
30+
) {
31+
parent::__construct($this->buildEventName('transition','transition',$workflow,$transition),$method,$priority,$dispatcher);
32+
}
33+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
namespaceSymfony\Component\Workflow\Attribute;
13+
14+
/**
15+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
16+
*
17+
* @internal
18+
*/
19+
trait BuildEventNameTrait
20+
{
21+
privatefunctionbuildEventName(string$keyword,string$argument,string$workflow =null,string$node =null)
22+
{
23+
if (null ===$workflow) {
24+
if (null !==$node) {
25+
thrownew \LogicException(sprintf('The "%s" argument of "%s" cannot be used without a "workflow" argument.',$argument,self::class));
26+
}
27+
28+
returnsprintf('workflow.%s',$keyword);
29+
}
30+
31+
if (null ===$node) {
32+
returnsprintf('workflow.%s.%s',$workflow,$keyword);
33+
}
34+
35+
returnsprintf('workflow.%s.%s.%s',$workflow,$keyword,$node);
36+
}
37+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add`with-metadata` option to the`workflow:dump` command to include places,
88
transitions and workflow's metadata into dumped graph
99
* Add support for storing marking in a property
10+
* Add some PHP attributes to register listeners and guards
1011

1112
6.2
1213
---

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp