2016-08-16 12:13:16 +01:00
|
|
|
<?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\Exception\RuntimeException;
|
|
|
|
use Symfony\Component\Workflow\Validator\DefinitionValidatorInterface;
|
|
|
|
use Symfony\Component\Workflow\Validator\StateMachineValidator;
|
|
|
|
use Symfony\Component\Workflow\Validator\WorkflowValidator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
|
|
|
*/
|
|
|
|
class ValidateWorkflowsPass implements CompilerPassInterface
|
|
|
|
{
|
|
|
|
public function process(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$taggedServices = $container->findTaggedServiceIds('workflow.definition');
|
|
|
|
foreach ($taggedServices as $id => $tags) {
|
|
|
|
$definition = $container->get($id);
|
|
|
|
foreach ($tags as $tag) {
|
2016-11-07 17:57:54 +00:00
|
|
|
if (!array_key_exists('name', $tag)) {
|
2016-08-16 12:13:16 +01:00
|
|
|
throw new RuntimeException(sprintf('The "name" for the tag "workflow.definition" of service "%s" must be set.', $id));
|
|
|
|
}
|
2016-11-07 17:57:54 +00:00
|
|
|
if (!array_key_exists('type', $tag)) {
|
2016-08-16 12:13:16 +01:00
|
|
|
throw new RuntimeException(sprintf('The "type" for the tag "workflow.definition" of service "%s" must be set.', $id));
|
|
|
|
}
|
2016-11-07 17:57:54 +00:00
|
|
|
if (!array_key_exists('marking_store', $tag)) {
|
2016-08-16 12:13:16 +01:00
|
|
|
throw new RuntimeException(sprintf('The "marking_store" for the tag "workflow.definition" of service "%s" must be set.', $id));
|
|
|
|
}
|
|
|
|
|
2016-11-11 17:53:11 +00:00
|
|
|
$this->createValidator($tag)->validate($definition, $tag['name']);
|
2016-08-16 12:13:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $tag
|
|
|
|
*
|
|
|
|
* @return DefinitionValidatorInterface
|
|
|
|
*/
|
2016-11-11 17:53:11 +00:00
|
|
|
private function createValidator($tag)
|
2016-08-16 12:13:16 +01:00
|
|
|
{
|
2016-11-11 17:53:11 +00:00
|
|
|
if ('state_machine' === $tag['type']) {
|
|
|
|
return new StateMachineValidator();
|
2016-08-16 12:13:16 +01:00
|
|
|
}
|
|
|
|
|
2016-11-11 17:53:11 +00:00
|
|
|
if ('single_state' === $tag['marking_store']) {
|
|
|
|
return new WorkflowValidator(true);
|
2016-08-16 12:13:16 +01:00
|
|
|
}
|
|
|
|
|
2016-11-11 17:53:11 +00:00
|
|
|
return new WorkflowValidator();
|
2016-08-16 12:13:16 +01:00
|
|
|
}
|
|
|
|
}
|