Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 15e35fc

Browse filesBrowse files
committed
[Workflow] Remove constraints on transition/place name + Updated Dumper
1 parent 89d1b65 commit 15e35fc
Copy full SHA for 15e35fc

27 files changed

+350
-374
lines changed

‎src/Symfony/Component/Workflow/Definition.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Definition.php
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Workflow;
1313

14-
use Symfony\Component\Workflow\Exception\InvalidArgumentException;
1514
use Symfony\Component\Workflow\Exception\LogicException;
1615

1716
/**
@@ -82,10 +81,6 @@ private function setInitialPlace(string $place = null)
8281

8382
private function addPlace(string $place)
8483
{
85-
if (!preg_match('{^[\w_-]+$}', $place)) {
86-
throw new InvalidArgumentException(sprintf('The place "%s" contains invalid characters.', $place));
87-
}
88-
8984
if (!count($this->places)) {
9085
$this->initialPlace = $place;
9186
}

‎src/Symfony/Component/Workflow/DefinitionBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/DefinitionBuilder.php
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Workflow;
1313

14-
use Symfony\Component\Workflow\Exception\InvalidArgumentException;
15-
1614
/**
1715
* Builds a definition.
1816
*
@@ -77,10 +75,6 @@ public function setInitialPlace($place)
7775
*/
7876
public function addPlace($place)
7977
{
80-
if (!preg_match('{^[\w_-]+$}', $place)) {
81-
throw new InvalidArgumentException(sprintf('The place "%s" contains invalid characters.', $place));
82-
}
83-
8478
if (!$this->places) {
8579
$this->initialPlace = $place;
8680
}

‎src/Symfony/Component/Workflow/Dumper/GraphvizDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Dumper/GraphvizDumper.php
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function addPlaces(array $places)
107107
$code = '';
108108

109109
foreach ($places as $id => $place) {
110-
$code .= sprintf(" place_%s [label=\"%s\", shape=circle%s];\n", $this->dotize($id), $id, $this->addAttributes($place['attributes']));
110+
$code .= sprintf(" place_%s [label=\"%s\", shape=circle%s];\n", $this->dotize($id), $this->escape($id), $this->addAttributes($place['attributes']));
111111
}
112112

113113
return $code;
@@ -121,7 +121,7 @@ protected function addTransitions(array $transitions)
121121
$code = '';
122122

123123
foreach ($transitions as $place) {
124-
$code .= sprintf(" transition_%s [label=\"%s\", shape=box%s];\n", $this->dotize($place['name']), $place['name'], $this->addAttributes($place['attributes']));
124+
$code .= sprintf(" transition_%s [label=\"%s\", shape=box%s];\n", $this->dotize($place['name']), $this->escape($place['name']), $this->addAttributes($place['attributes']));
125125
}
126126

127127
return $code;
@@ -198,15 +198,23 @@ protected function endDot()
198198
*/
199199
protected function dotize($id)
200200
{
201-
return strtolower(preg_replace('/[^\w]/i', '_', $id));
201+
return hash('sha1', $id);
202+
}
203+
204+
/**
205+
* @internal
206+
*/
207+
protected function escape(string $string): string
208+
{
209+
return addslashes($string);
202210
}
203211

204212
private function addAttributes(array $attributes): string
205213
{
206214
$code = array();
207215

208216
foreach ($attributes as $k => $v) {
209-
$code[] = sprintf('%s="%s"', $k, $v);
217+
$code[] = sprintf('%s="%s"', $k, $this->escape($v));
210218
}
211219

212220
return $code ? ', '.implode(', ', $code) : '';

‎src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php
+25-14Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class PlantUmlDumper implements DumperInterface
3434
qM53XHDUwhY0TAwPug3OG9NonRFhO8ynF3I4unuAMDHmSrXH57V1RGvl9jafuZF9ZhqjWOEh98y0tUYGsUxkBSllIyBdT2oM5Fn2-ut-fzsq_cQNuL6Uvwqr
3535
knh4RrvOKzxZfLV3s0rs_R_1SdYt3VxeQ1_y2_W2
3636
}';
37-
private const INITIAL = 'initial';
38-
private const MARKED = 'marked';
37+
private const INITIAL = '<<initial>>';
38+
private const MARKED = '<<marked>>';
3939

4040
const STATEMACHINE_TRANSITION = 'arrow';
4141
const WORKFLOW_TRANSITION = 'square';
@@ -45,11 +45,11 @@ class PlantUmlDumper implements DumperInterface
4545
'titleBorderRoundCorner' => 15,
4646
'titleBorderThickness' => 2,
4747
'state' => array(
48-
'BackgroundColor<<'.self::INITIAL.'>>' => '#87b741',
49-
'BackgroundColor<<'.self::MARKED.'>>' => '#3887C6',
48+
'BackgroundColor'.self::INITIAL => '#87b741',
49+
'BackgroundColor'.self::MARKED => '#3887C6',
5050
'BorderColor' => '#3887C6',
51-
'BorderColor<<'.self::MARKED.'>>' => 'Black',
52-
'FontColor<<'.self::MARKED.'>>' => 'White',
51+
'BorderColor'.self::MARKED => 'Black',
52+
'FontColor'.self::MARKED => 'White',
5353
),
5454
'agent' => array(
5555
'BackgroundColor' => '#ffffff',
@@ -63,7 +63,7 @@ class PlantUmlDumper implements DumperInterface
6363
public function __construct(string $transitionType = null)
6464
{
6565
if (!in_array($transitionType, self::TRANSITION_TYPES)) {
66-
throw new InvalidArgumentException("Transition type '{$transitionType}' does not exist.");
66+
throw new InvalidArgumentException("Transition type '$transitionType' does not exist.");
6767
}
6868
$this->transitionType = $transitionType;
6969
}
@@ -73,31 +73,36 @@ public function dump(Definition $definition, Marking $marking = null, array $opt
7373
$options = array_replace_recursive(self::DEFAULT_OPTIONS, $options);
7474
$code = $this->initialize($options);
7575
foreach ($definition->getPlaces() as $place) {
76+
$placeEscaped = $this->escape($place);
7677
$code[] =
77-
"state {$place}".
78-
($definition->getInitialPlace() === $place ? ' <<'.self::INITIAL.'>>' : '').
79-
($marking && $marking->has($place) ? ' <<'.self::MARKED.'>>' : '');
78+
"state $placeEscaped".
79+
($definition->getInitialPlace() === $place ? ' '.self::INITIAL : '').
80+
($marking && $marking->has($place) ? ' '.self::MARKED : '');
8081
}
8182
if ($this->isWorkflowTransitionType()) {
8283
foreach ($definition->getTransitions() as $transition) {
83-
$code[] = "agent {$transition->getName()}";
84+
$transitionEscaped = $this->escape($transition->getName());
85+
$code[] = "agent $transitionEscaped";
8486
}
8587
}
8688
foreach ($definition->getTransitions() as $transition) {
89+
$transitionEscaped = $this->escape($transition->getName());
8790
foreach ($transition->getFroms() as $from) {
91+
$fromEscaped = $this->escape($from);
8892
foreach ($transition->getTos() as $to) {
93+
$toEscaped = $this->escape($to);
8994
if ($this->isWorkflowTransitionType()) {
9095
$lines = array(
91-
"{$from} --> {$transition->getName()}",
92-
"{$transition->getName()} --> {$to}",
96+
"$fromEscaped --> $transitionEscaped",
97+
"$transitionEscaped --> $toEscaped",
9398
);
9499
foreach ($lines as $line) {
95100
if (!in_array($line, $code)) {
96101
$code[] = $line;
97102
}
98103
}
99104
} else {
100-
$code[] = "{$from} --> {$to}: {$transition->getName()}";
105+
$code[] = "$fromEscaped --> $toEscaped: $transitionEscaped";
101106
}
102107
}
103108
}
@@ -169,4 +174,10 @@ private function initialize(array $options): array
169174

170175
return $code;
171176
}
177+
178+
private function escape(string $string): string
179+
{
180+
// It's not possible to escape property double quote, so let's remove it
181+
return '"'.str_replace('"', '', $string).'"';
182+
}
172183
}

‎src/Symfony/Component/Workflow/Dumper/StateMachineGraphvizDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Dumper/StateMachineGraphvizDumper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function addEdges(array $edges)
7171

7272
foreach ($edges as $id => $edges) {
7373
foreach ($edges as $edge) {
74-
$code .= sprintf(" place_%s -> place_%s [label=\"%s\" style=\"%s\"];\n", $this->dotize($id), $this->dotize($edge['to']), $edge['name'], 'solid');
74+
$code .= sprintf(" place_%s -> place_%s [label=\"%s\" style=\"%s\"];\n", $this->dotize($id), $this->dotize($edge['to']), $this->escape($edge['name']), 'solid');
7575
}
7676
}
7777

‎src/Symfony/Component/Workflow/Tests/DefinitionBuilderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/DefinitionBuilderTest.php
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88

99
class DefinitionBuilderTest extends TestCase
1010
{
11-
/**
12-
* @expectedException \Symfony\Component\Workflow\Exception\InvalidArgumentException
13-
*/
14-
public function testAddPlaceInvalidName()
15-
{
16-
$builder = new DefinitionBuilder(array('a"', 'b'));
17-
}
18-
1911
public function testSetInitialPlace()
2012
{
2113
$builder = new DefinitionBuilder(array('a', 'b'));

‎src/Symfony/Component/Workflow/Tests/DefinitionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/DefinitionTest.php
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ public function testAddPlaces()
1818
$this->assertEquals('a', $definition->getInitialPlace());
1919
}
2020

21-
/**
22-
* @expectedException \Symfony\Component\Workflow\Exception\InvalidArgumentException
23-
*/
24-
public function testAddPlacesInvalidArgument()
25-
{
26-
$places = array('a"', 'e"');
27-
$definition = new Definition($places, array());
28-
}
29-
3021
public function testSetInitialPlace()
3122
{
3223
$places = range('a', 'e');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.