-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] Introducing the workflow component #11882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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', ar 6D47 ray($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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you implement
isEnabled
command to returnfalse
if you don't have any declared workflows ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I store nothing in the DIC about existing workflow. So I will not be able to do that with ease. I think I should add a parameter in the DIC for that.
So my question is: Do you really need this "feature" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you access configuration from container like you did in the extension class in the Framework extension class ?not that easy indeed, I like your parameter injection idea 👍Because we already have a lot of commands and for now, no way to filter except using this function, I think we got a chance to avoid this command when we don't need it.
To sum up:
What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ; I agree with you. I will implement that ASAP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, in a better way.