Skip to content

Commit c23de94

Browse files
author
Willem Oostendorp
committed
Fixed some styling issues and made all private methods and properties protected to allow subclassing of the registry class
1 parent 08a8126 commit c23de94

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/WorkflowRegistry.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ class WorkflowRegistry
2424
/**
2525
* @var Registry
2626
*/
27-
private $registry;
27+
protected $registry;
2828

2929
/**
3030
* @var array
3131
*/
32-
private $config;
32+
protected $config;
3333

3434
/**
3535
* @var EventDispatcher
3636
*/
37-
private $dispatcher;
37+
protected $dispatcher;
3838

3939
/**
4040
* WorkflowRegistry constructor
@@ -44,11 +44,11 @@ class WorkflowRegistry
4444
*/
4545
public function __construct(array $config)
4646
{
47-
$this->registry = new Registry();
48-
$this->config = $config;
47+
$this->registry = new Registry();
48+
$this->config = $config;
4949
$this->dispatcher = new EventDispatcher();
5050

51-
$subscriber = new WorkflowSubscriber();
51+
$subscriber = new WorkflowSubscriber();
5252
$this->dispatcher->addSubscriber($subscriber);
5353

5454
foreach ($this->config as $name => $workflowData) {
@@ -71,10 +71,10 @@ public function get($subject, $workflowName = null)
7171
/**
7272
* Add a workflow to the subject
7373
*
74-
* @param Workflow $workflow
75-
* @param SupportStrategyInterface $supportStrategy
74+
* @param Workflow $workflow
75+
* @param string $supportStrategy
7676
*/
77-
public function add(Workflow $workflow, SupportStrategyInterface $supportStrategy)
77+
public function add(Workflow $workflow, $supportStrategy)
7878
{
7979
$this->registry->add($workflow, new ClassInstanceSupportStrategy($supportStrategy));
8080
}
@@ -98,9 +98,9 @@ public function addFromArray($name, array $workflowData)
9898
$builder->addTransition(new Transition($transitionName, $transition['from'], $transition['to']));
9999
}
100100

101-
$definition = $builder->build();
101+
$definition = $builder->build();
102102
$markingStore = $this->getMarkingStoreInstance($workflowData);
103-
$workflow = $this->getWorkflowInstance($name, $workflowData, $definition, $markingStore);
103+
$workflow = $this->getWorkflowInstance($name, $workflowData, $definition, $markingStore);
104104

105105
foreach ($workflowData['supports'] as $supportedClass) {
106106
$this->add($workflow, $supportedClass);
@@ -116,19 +116,18 @@ public function addFromArray($name, array $workflowData)
116116
* @param MarkingStoreInterface $markingStore
117117
* @return Workflow
118118
*/
119-
private function getWorkflowInstance(
119+
protected function getWorkflowInstance(
120120
$name,
121121
array $workflowData,
122122
Definition $definition,
123123
MarkingStoreInterface $markingStore
124124
) {
125-
$type = isset($workflowData['type']) ? $workflowData['type'] : 'workflow';
126-
$className = Workflow::class;
127-
128-
if ($type === 'state_machine') {
129-
$className = StateMachine::class;
130-
} elseif (isset($workflowData['class'])) {
125+
if (isset($workflowData['class'])) {
131126
$className = $workflowData['class'];
127+
} elseif (isset($workflowData['type']) && $workflowData['type'] === 'state_machine') {
128+
$className = StateMachine::class;
129+
} else {
130+
$className = Workflow::class;
132131
}
133132

134133
return new $className($definition, $markingStore, $this->dispatcher, $name);
@@ -141,17 +140,17 @@ private function getWorkflowInstance(
141140
* @return MarkingStoreInterface
142141
* @throws \ReflectionException
143142
*/
144-
private function getMarkingStoreInstance(array $workflowData)
143+
protected function getMarkingStoreInstance(array $workflowData)
145144
{
146145
$markingStoreData = isset($workflowData['marking_store']) ? $workflowData['marking_store'] : [];
147-
$type = isset($markingStoreData['type']) ? $markingStoreData['type'] : 'single_state';
148-
$className = SingleStateMarkingStore::class;
149-
$arguments = isset($markingStoreData['arguments']) ? $markingStoreData['arguments'] : [];
146+
$arguments = isset($markingStoreData['arguments']) ? $markingStoreData['arguments'] : [];
150147

151-
if ($type === 'multiple_state') {
152-
$className = MultipleStateMarkingStore::class;
153-
} elseif (isset($markingStoreData['class'])) {
148+
if (isset($markingStoreData['class'])) {
154149
$className = $markingStoreData['class'];
150+
} elseif (isset($markingStoreData['type']) && $markingStoreData['type'] === 'multiple_state') {
151+
$className = MultipleStateMarkingStore::class;
152+
} else {
153+
$className = SingleStateMarkingStore::class;
155154
}
156155

157156
$class = new \ReflectionClass($className);

0 commit comments

Comments
 (0)