Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workflow] Added initial set of files
- Loading branch information
Showing
43 changed files
with
2,032 additions
and
280 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
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,52 @@ | ||
<?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\Bridge\Twig\Extension; | ||
|
||
use Symfony\Component\Workflow\Registry; | ||
|
||
/** | ||
* WorkflowExtension. | ||
* | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class WorkflowExtension extends \Twig_Extension | ||
{ | ||
private $workflowRegistry; | ||
|
||
public function __construct(Registry $workflowRegistry) | ||
{ | ||
$this->workflowRegistry = $workflowRegistry; | ||
} | ||
|
||
public function getFunctions() | ||
{ | ||
return array( | ||
new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')), | ||
new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')), | ||
); | ||
} | ||
|
||
public function canTransition($object, $transition, $name = null) | ||
{ | ||
return $this->workflowRegistry->get($object, $name)->can($object, $transition); | ||
} | ||
|
||
public function getEnabledTransitions($object, $name = null) | ||
{ | ||
return $this->workflowRegistry->get($object, $name)->getEnabledTransitions($object); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'workflow'; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.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,78 @@ | ||
<?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\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Workflow\Dumper\GraphvizDumper; | ||
use Symfony\Component\Workflow\Marking; | ||
|
||
/** | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class WorkflowDumpCommand extends ContainerAwareCommand | ||
{ | ||
public function isEnabled() | ||
{ | ||
return $this->getContainer()->has('workflow.registry'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('workflow:dump') | ||
->setDefinition(array( | ||
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'), | ||
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'), | ||
)) | ||
->setDescription('Dump a workflow') | ||
->setHelp(<<<'EOF' | ||
The <info>%command.name%</info> command dumps the graphical representation of a | ||
workflow in DOT format | ||
%command.full_name% <workflow name> | dot -Tpng > workflow.png | ||
EOF | ||
) | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$workflow = $this->getContainer()->get('workflow.'.$input->getArgument('name')); | ||
$definition = $this->getProperty($workflow, 'definition'); | ||
|
||
$dumper = new GraphvizDumper(); | ||
|
||
$marking = new Marking(); | ||
foreach ($input->getArgument('marking') as $place) { | ||
$marking->mark($place); | ||
} | ||
|
||
$output->writeln($dumper->dump($definition, $marking)); | ||
} | ||
|
||
private function getProperty($object, $property) | ||
{ | ||
$reflectionProperty = new \ReflectionProperty(get_class($object), $property); | ||
$reflectionProperty->setAccessible(true); | ||
|
||
return $reflectionProperty->getValue($object); | ||
} | ||
} |
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
Oops, something went wrong.