8000 be able to enable workflow support explicitly · symfony/symfony@eaa506f · GitHub
[go: up one dir, main page]

Skip to content

Commit eaa506f

Browse files
committed
be able to enable workflow support explicitly
1 parent 012c56b commit eaa506f

File tree

8 files changed

+178
-122
lines changed

8 files changed

+178
-122
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 137 additions & 113 deletions
Large diffs are not rendered by default.

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,13 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
530530
/**
531531
* Loads the workflow configuration.
532532
*
533-
* @param array $workflows A workflow configuration array
533+
* @param array $config A workflow configuration array
534534
* @param ContainerBuilder $container A ContainerBuilder instance
535535
* @param XmlFileLoader $loader An XmlFileLoader instance
536536
*/
537-
private function registerWorkflowConfiguration(array $workflows, ContainerBuilder $container, XmlFileLoader $loader)
537+
private function registerWorkflowConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
538538
{
539-
if (!$workflows) {
539+
if (!$config['enabled']) {
540540
if (!class_exists(Workflow\Workflow::class)) {
541541
$container->removeDefinition(WorkflowDumpCommand::class);
542542
}
@@ -552,7 +552,7 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
552552

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

555-
foreach ($workflows as $name => $workflow) {
555+
foreach ($config['workflows'] as $name => $workflow) {
556556
if (!array_key_exists('type', $workflow)) {
557557
$workflow['type'] = 'workflow';
558558
@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);

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,16 @@
254254

255255
<xsd:complexType name="workflow">
256256
<xsd:sequence>
257-
<xsd:element name="marking-store" type="marking_store" />
257+
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
258258
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
259-
<xsd:element name="place" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
260-
<xsd:element name="transition" type="transition" minOccurs="1" maxOccurs="unbounded" />
259+
<xsd:element name="place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
260+
<xsd:element name="transition" type="transition" minOccurs="0" maxOccurs="unbounded" />
261261
</xsd:sequence>
262-
<xsd:attribute name="name" type="xsd:string" use="required" />
262+
<xsd:attribute name="name" type="xsd:string" />
263263
<xsd:attribute name="type" type="workflow_type" />
264264
<xsd:attribute name="initial-place" type="xsd:string" />
265265
<xsd:attribute name="support-strategy" type="xsd:string" />
266+
<xsd:attribute name="enabled" type="xsd:boolean" />
266267
</xsd:complexType>
267268

268269
<xsd:complexType name="marking_store">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ protected static function getBundleDefaultConfig()
331331
'default_redis_provider' => 'redis://localhost',
332332
'default_memcached_provider' => 'memcached://localhost',
333333
),
334-
'workflows' => array(),
334+
'workflows' => array(
335+
'enabled' => false,
336+
'workflows' => array(),
337+
),
335338
'php_errors' => array(
336339
'log' => true,
337340
'throw' => true,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'workflows' => null,
5+
));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:workflow enabled="true" />
10+
</framework:config>
11+
</container>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
framework:
2+
workflows: ~

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
1313

1414
use Doctrine\Common\Annotations\Annotation;
15+
use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand;
1516
use Symfony\Bundle\FullStack;
1617
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1718
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
@@ -42,6 +43,7 @@
4243
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
4344
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
4445
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
46+
use Symfony\Component\Workflow\Registry;
4547

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

312+
public function testWorkflowServicesCanBeEnabled()
313+
{
314+
$container = $this->createContainerFromFile('workflows_enabled');
315+
316+
$this->assertTrue($container->has(Registry::class));
317+
$this->assertTrue($container->hasDefinition(WorkflowDumpCommand::class));
318+
}
319+
310320
public function testRouter()
311321
{
312322
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)
0