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

Commit1b14718

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

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
@@ -1109,6 +1109,29 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11091109
$container->setParameter('workflow.has_guard_listeners',true);
11101110
}
11111111
}
1112+
1113+
$listenerAttributes = [
1114+
Workflow\Attribute\AsAnnounceListener::class,
1115+
Workflow\Attribute\AsCompletedListener::class,
1116+
Workflow\Attribute\AsEnterListener::class,
1117+
Workflow\Attribute\AsEnteredListener::class,
1118+
Workflow\Attribute\AsGuardListener::class,
1119+
Workflow\Attribute\AsLeaveListener::class,
1120+
Workflow\Attribute\AsTransitionListener::class,
1121+
];
1122+
1123+
foreach ($listenerAttributesas$attribute) {
1124+
$container->registerAttributeForAutoconfiguration($attribute,staticfunction (ChildDefinition$definition,AsEventListener$attribute,\ReflectionClass|\ReflectionMethod$reflector) {
1125+
$tagAttributes =get_object_vars($attribute);
1126+
if ($reflectorinstanceof \ReflectionMethod) {
1127+
if (isset($tagAttributes['method'])) {
1128+
thrownewLogicException(sprintf('"%s" attribute cannot declare a method on "%s::%s()".',$attribute::class,$reflector->class,$reflector->name));
1129+
}
1130+
$tagAttributes['method'] =$reflector->getName();
1131+
}
1132+
$definition->addTag('kernel.event_listener',$tagAttributes);
1133+
});
1134+
}
11121135
}
11131136

11141137
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
@@ -8,6 +8,7 @@ CHANGELOG
88
transitions and workflow's metadata into dumped graph
99
* Add support for storing marking in a property
1010
* Add a profiler
11+
* Add some PHP attributes to register listeners and guards
1112

1213
6.2
1314
---

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp