-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workflow] Add some PHP attributes to register listeners and guards
- Loading branch information
Showing
11 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Workflow/Attribute/AsAnnounceListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
final class AsAnnounceListener extends AsEventListener | ||
{ | ||
use BuildEventNameTrait; | ||
|
||
public function __construct( | ||
string $workflow = null, | ||
string $transition = null, | ||
string $method = null, | ||
int $priority = 0, | ||
string $dispatcher = null, | ||
) { | ||
parent::__construct($this->buildEventName('announce', 'transition', $workflow, $transition), $method, $priority, $dispatcher); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Workflow/Attribute/AsCompletedListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
final class AsCompletedListener extends AsEventListener | ||
{ | ||
use BuildEventNameTrait; | ||
|
||
public function __construct( | ||
string $workflow = null, | ||
string $transition = null, | ||
string $method = null, | ||
int $priority = 0, | ||
string $dispatcher = null, | ||
) { | ||
parent::__construct($this->buildEventName('completed', 'transition', $workflow, $transition), $method, $priority, $dispatcher); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Workflow/Attribute/AsEnterListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
final class AsEnterListener extends AsEventListener | ||
{ | ||
use BuildEventNameTrait; | ||
|
||
public function __construct( | ||
string $workflow = null, | ||
string $place = null, | ||
string $method = null, | ||
int $priority = 0, | ||
string $dispatcher = null, | ||
) { | ||
parent::__construct($this->buildEventName('enter', 'place', $workflow, $place), $method, $priority, $dispatcher); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Workflow/Attribute/AsEnteredListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
final class AsEnteredListener extends AsEventListener | ||
{ | ||
use BuildEventNameTrait; | ||
|
||
public function __construct( | ||
string $workflow = null, | ||
string $place = null, | ||
string $method = null, | ||
int $priority = 0, | ||
string $dispatcher = null, | ||
) { | ||
parent::__construct($this->buildEventName('entered', 'place', $workflow, $place), $method, $priority, $dispatcher); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Workflow/Attribute/AsGuardListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
final class AsGuardListener extends AsEventListener | ||
{ | ||
use BuildEventNameTrait; | ||
|
||
public function __construct( | ||
string $workflow = null, | ||
string $transition = null, | ||
string $method = null, | ||
int $priority = 0, | ||
string $dispatcher = null, | ||
) { | ||
parent::__construct($this->buildEventName('guard', 'transition', $workflow, $transition), $method, $priority, $dispatcher); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Workflow/Attribute/AsLeaveListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
final class AsLeaveListener extends AsEventListener | ||
{ | ||
use BuildEventNameTrait; | ||
|
||
public function __construct( | ||
string $workflow = null, | ||
string $place = null, | ||
string $method = null, | ||
int $priority = 0, | ||
string $dispatcher = null, | ||
) { | ||
parent::__construct($this->buildEventName('leave', 'place', $workflow, $place), $method, $priority, $dispatcher); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Workflow/Attribute/AsTransitionListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
final class AsTransitionListener extends AsEventListener | ||
{ | ||
use BuildEventNameTrait; | ||
|
||
public function __construct( | ||
string $workflow = null, | ||
string $transition = null, | ||
string $method = null, | ||
int $priority = 0, | ||
string $dispatcher = null, | ||
) { | ||
parent::__construct($this->buildEventName('transition', 'transition', $workflow, $transition), $method, $priority, $dispatcher); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Symfony/Component/Workflow/Attribute/BuildEventNameTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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\Workflow\Attribute; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
* | ||
* @internal | ||
*/ | ||
trait BuildEventNameTrait | ||
{ | ||
private function buildEventName(string $keyword, string $argument, string $workflow = null, string $node = null) | ||
{ | ||
if (null === $workflow) { | ||
if (null !== $node) { | ||
throw new \LogicException(sprintf('The "%s" argument of "%s" cannot be used without a "workflow" argument.', $argument, self::class)); | ||
} | ||
|
||
return sprintf('workflow.%s', $keyword); | ||
} | ||
|
||
if (null === $node) { | ||
return sprintf('workflow.%s.%s', $workflow, $keyword); | ||
} | ||
|
||
return sprintf('workflow.%s.%s.%s', $workflow, $keyword, $node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.