-
-
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.
- Loading branch information
Showing
6 changed files
with
266 additions
and
3 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/WorkflowDebugPass.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,36 @@ | ||
<?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\Bundle\FrameworkBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\Workflow\TraceableWorkflow; | ||
|
||
/** | ||
* Adds all configured security voters to the access decision manager. | ||
* | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class WorkflowDebugPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
foreach ($container->findTaggedServiceIds('workflow') as $id => $attributes) { | ||
Check failure on line 28 in src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/WorkflowDebugPass.php GitHub Actions / PsalmUnusedForeachValue
|
||
$container->register("debug.{$id}", TraceableWorkflow::class) | ||
->setDecoratedService($id) | ||
->setArguments([ | ||
new Reference("debug.{$id}.inner"), | ||
]); | ||
} | ||
} | ||
} |
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
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
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
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
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,112 @@ | ||
<?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; | ||
|
||
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface; | ||
use Symfony\Component\Workflow\Metadata\MetadataStoreInterface; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class TraceableWorkflow implements WorkflowInterface | ||
{ | ||
private array $calls = []; | ||
|
||
public function __construct( | ||
private readonly WorkflowInterface $workflow | ||
) { | ||
} | ||
|
||
public function getMarking(object $subject, array $context = []): Marking | ||
{ | ||
return $this->callInner(__FUNCTION__, \func_get_args()); | ||
} | ||
|
||
public function can(object $subject, string $transitionName): bool | ||
{ | ||
return $this->callInner(__FUNCTION__, \func_get_args()); | ||
} | ||
|
||
public function buildTransitionBlockerList(object $subject, string $transitionName): TransitionBlockerList | ||
{ | ||
return $this->callInner(__FUNCTION__, \func_get_args()); | ||
} | ||
|
||
public function apply(object $subject, string $transitionName, array $context = []): Marking | ||
{ | ||
return $this->callInner(__FUNCTION__, \func_get_args()); | ||
} | ||
|
||
public function getEnabledTransitions(object $subject): array | ||
{ | ||
return $this->callInner(__FUNCTION__, \func_get_args()); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->workflow->getName(); | ||
} | ||
|
||
public function getDefinition(): Definition | ||
{ | ||
return $this->workflow->getDefinition(); | ||
} | ||
|
||
public function getMarkingStore(): MarkingStoreInterface | ||
{ | ||
return $this->workflow->getMarkingStore(); | ||
} | ||
|
||
public function getMetadataStore(): MetadataStoreInterface | ||
{ | ||
return $this->workflow->getMetadataStore(); | ||
} | ||
|
||
public function getCalls(): array | ||
{ | ||
return $this->calls; | ||
} | ||
|
||
private function callInner(string $method, array $args): mixed | ||
{ | ||
$startAt = microtime(true); | ||
|
||
|
||
$previousMarking = null; | ||
if ('apply' === $method) { | ||
try { | ||
$previousMarking = $this->workflow->getMarking($args[0]); | ||
} catch (\Throwable) { | ||
} | ||
} | ||
|
||
try { | ||
return $return = $this->workflow->{$method}(...$args); | ||
} catch (\Throwable $exception) { | ||
throw $exception; | ||
} finally { | ||
$call = [ | ||
'method' => $method, | ||
'duration' => microtime(true) - $startAt, | ||
'args' => $args, | ||
'previousMarking' => $previousMarking ?? null, | ||
]; | ||
if (isset($exception)) { | ||
$call['exception'] = $exception; | ||
} elseif (isset($return)) { | ||
$call['return'] = $return; | ||
} | ||
|
||
$this->calls[] = $call; | ||
} | ||
} | ||
} |