Skip to content

Commit

Permalink
feature #24093 [FrameworkBundle] be able to enable workflow support e…
Browse files Browse the repository at this point in the history
…xplicitly (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle] be able to enable workflow support explicitly

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24051
| License       | MIT
| Doc PR        |

Commits
-------

eaa506f be able to enable workflow support explicitly
  • Loading branch information
fabpot committed Sep 5, 2017
2 parents 77b6cc6 + eaa506f commit 3d799dd
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 122 deletions.
250 changes: 137 additions & 113 deletions src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,13 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
/**
* Loads the workflow configuration.
*
* @param array $workflows A workflow configuration array
* @param array $config A workflow configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerWorkflowConfiguration(array $workflows, ContainerBuilder $container, XmlFileLoader $loader)
private function registerWorkflowConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$workflows) {
if (!$config['enabled']) {
if (!class_exists(Workflow\Workflow::class)) {
$container->removeDefinition(WorkflowDumpCommand::class);
}
Expand All @@ -552,7 +552,7 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde

$registryDefinition = $container->getDefinition('workflow.registry');

foreach ($workflows as $name => $workflow) {
foreach ($config['workflows'] as $name => $workflow) {
if (!array_key_exists('type', $workflow)) {
$workflow['type'] = 'workflow';
@trigger_error(sprintf('The "type" option of the "framework.workflows.%s" configuration entry must be defined since Symfony 3.3. The default value will be "state_machine" in Symfony 4.0.', $name), E_USER_DEPRECATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,16 @@

<xsd:complexType name="workflow">
<xsd:sequence>
<xsd:element name="marking-store" type="marking_store" />
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="place" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="transition" type="transition" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="transition" type="transition" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="workflow_type" />
<xsd:attribute name="initial-place" type="xsd:string" />
<xsd:attribute name="support-strategy" type="xsd:string" />
<xsd:attribute name="enabled" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name="marking_store">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ protected static function getBundleDefaultConfig()
'default_redis_provider' => 'redis://localhost',
'default_memcached_provider' => 'memcached://localhost',
),
'workflows' => array(),
'workflows' => array(
'enabled' => false,
'workflows' => array(),
),
'php_errors' => array(
'log' => true,
'throw' => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$container->loadFromExtension('framework', array(
'workflows' => null,
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:workflow enabled="true" />
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework:
workflows: ~
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;

use Doctrine\Common\Annotations\Annotation;
use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand;
use Symfony\Bundle\FullStack;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
Expand Down Expand Up @@ -42,6 +43,7 @@
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
use Symfony\Component\Workflow\Registry;

abstract class FrameworkExtensionTest extends TestCase
{
Expand Down Expand Up @@ -307,6 +309,14 @@ public function testWorkflowMultipleTransitionsWithSameName()
$this->assertSame(array('draft'), $transitions[4]->getArgument(1));
}

public function testWorkflowServicesCanBeEnabled()
{
$container = $this->createContainerFromFile('workflows_enabled');

$this->assertTrue($container->has(Registry::class));
$this->assertTrue($container->hasDefinition(WorkflowDumpCommand::class));
}

public function testRouter()
{
$container = $this->createContainerFromFile('full');
Expand Down

0 comments on commit 3d799dd

Please sign in to comment.