Skip to content

Navigation Menu

Sign in
Appearance settings

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 6f8e66c

Browse filesBrowse files
committed
--
1 parent b087c0a commit 6f8e66c
Copy full SHA for 6f8e66c

File tree

1 file changed

+59
-0
lines changed
Filter options

1 file changed

+59
-0
lines changed
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Workflow\MarkingStore;
13+
14+
use Symfony\Component\PropertyAccess\PropertyAccess;
15+
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
16+
17+
/**
18+
* SingleStateMarkingStore stores the marking with a method of the subject.
19+
*
20+
* This store deals with a "single state" Marking. It means a subject can be in
21+
* one and only one state at the same time.
22+
*
23+
* The constructor accept a `property` name.
24+
* The `getMarking` method will use `$subject->getProperty()`.
25+
* The `setMarking` method will use `$subject->setProperty($places, $context)`.
26+
*
27+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
28+
*/
29+
class MethodSingleStateMarkingStore implements MarkingStoreInterface
30+
{
31+
private $property;
32+
33+
public function __construct(string $property = 'setMarking')
34+
{
35+
$this->property = $property;
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function getMarking($subject)
42+
{
43+
$placeName = $subject->{'get'.ucfirst($this->property)}();
44+
45+
if (!$placeName) {
46+
return new Marking();
47+
}
48+
49+
return new Marking(array($placeName => 1));
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function setMarking($subject, Marking $marking, array $context = array())
56+
{
57+
$subject->{'set'.ucfirst($this->property)}(key($marking->getPlaces()), $context);
58+
}
59+
}

0 commit comments

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