Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Fixtures\Workflow\Validator; | ||
|
||
use Symfony\Component\Workflow\Definition; | ||
use Symfony\Component\Workflow\Validator\DefinitionValidatorInterface; | ||
|
||
class DefinitionValidator implements DefinitionValidatorInterface | ||
{ | ||
public static bool $called = false; | ||
|
||
public function validate(Definition $definition, string $name): void | ||
{ | ||
self::$called = true; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?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\CacheWarmer; | ||
|
||
use Symfony\Component\Workflow\Definition; | ||
use Symfony\Component\Workflow\Validator\DefinitionValidatorInterface; | ||
|
||
final class DefinitionAndValidator | ||
{ | ||
public function __construct( | ||
public readonly DefinitionValidatorInterface $validator, | ||
public readonly Definition $definition, | ||
public readonly string $name, | ||
) { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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\CacheWarmer; | ||
|
||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; | ||
use Symfony\Component\Workflow\CacheWarmer\Model\DefinitionAndValidator; | ||
|
||
final class DefinitionValidatorCacheWarmer implements CacheWarmerInterface | ||
{ | ||
/** | ||
* @param iterable<DefinitionAndValidator> $definitionAndValidators | ||
Check failure on line 20 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
Check failure on line 20 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
|
||
*/ | ||
public function __construct( | ||
private readonly iterable $definitionAndValidators, | ||
) { | ||
} | ||
|
||
public function isOptional(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function warmUp(string $cacheDir, ?string $buildDir = null): array | ||
{ | ||
foreach ($this->definitionAndValidators as $definitionAndValidator) { | ||
$definitionAndValidator | ||
Check failure on line 35 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
Check failure on line 35 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
|
||
->validator | ||
->validate($definitionAndValidator->definition, $definitionAndValidator->name) | ||
Check failure on line 37 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
Check failure on line 37 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
Check failure on line 37 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
Check failure on line 37 in src/Symfony/Component/Workflow/CacheWarmer/DefinitionValidatorCacheWarmer.php GitHub Actions / PsalmUndefinedDocblockClass
|
||
; | ||
} | ||
|
||
return []; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?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\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\Workflow\CacheWarmer\DefinitionAndValidator; | ||
use Symfony\Component\Workflow\Validator\ConfiguredDefinitionValidatorInterface; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class DefinitionValidatorPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasDefinition('workflow.cache_warmer.definition_validator')) { | ||
return; | ||
} | ||
|
||
$definitions = []; | ||
foreach ($container->findTaggedServiceIds('workflow.definition') as $id => $attributes) { | ||
$name = $attributes[0]['name'] ?? throw new InvalidArgumentException(sprintf('The "name" attribute is mandatory for the "workflow.definition" tag. Check the tag for service "%s".', $id)); | ||
$definitions[$name] = new Reference($id); | ||
} | ||
|
||
|
||
$definitionAndValidators = []; | ||
foreach ($container->findTaggedServiceIds('workflow.definition_validator') as $id => $attributes) | ||
{ | ||
$def = $container->getDefinition($id); | ||
|
||
$class = $def->getClass(); | ||
|
||
if (!$r = $container->getReflectionClass($class)) { | ||
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); | ||
} | ||
if (!$r->isSubclassOf(ConfiguredDefinitionValidatorInterface::class)) { | ||
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, ConfiguredDefinitionValidatorInterface::class)); | ||
} | ||
|
||
foreach ($class::getSupportedWorkflows() as $name) { | ||
Check failure on line 54 in src/Symfony/Component/Workflow/DependencyInjection/DefinitionValidatorPass.php GitHub Actions / PsalmUndefinedClass
Check failure on line 54 in src/Symfony/Component/Workflow/DependencyInjection/DefinitionValidatorPass.php GitHub Actions / PsalmUndefinedClass
|
||
if ('*' === $name) { | ||
foreach ($definitions as $definitionName => $definition) { | ||
$definitionAndValidators[] = new Definition( | ||
DefinitionAndValidator::class, | ||
[ | ||
new Reference($id), | ||
$definition, | ||
$definitionName, | ||
] | ||
); | ||
} | ||
} elseif (isset($definitions[$name])) { | ||
$definitionAndValidators[] = new Definition( | ||
DefinitionAndValidator::class, | ||
[ | ||
new Reference($id), | ||
$definitions[$name], | ||
$name, | ||
] | ||
); | ||
} else { | ||
throw new InvalidArgumentException(sprintf('The workflow "%s" does not exist. Check the "getConfiguration()" method of the service "%s".', $name, $id)); | ||
} | ||
} | ||
} | ||
|
||
$container | ||
->getDefinition('workflow.cache_warmer.definition_validator') | ||
->replaceArgument(0, $definitionAndValidators) | ||
; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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\Validator; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
interface ConfiguredDefinitionValidatorInterface extends DefinitionValidatorInterface | ||
{ | ||
/** | ||
* @return list<string> A list of workflow name, or "*" for all workflows | ||
*/ | ||
public static function getSupportedWorkflows(): iterable; | ||
} |