Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | yes |
Symfony version | 3.2.6 |
Hi everyone,
First of all, let me say that I am a big fan of Symfony and enjoy the new functionality introduced in Symfony 3.x, such as the Workflow Component, a great help!
I wanted to request a feature on the Workflow Component to support the use of ValueObjects for the marking store. I am a big fan of using ValueObjects to restrict the usage of otherwise potentially 'generic' properties. For example, I have the following YML:
framework:
workflows:
my_workflow:
type: 'state_machine'
supports:
- AppBundle\Entity\MyEntity
marking_store:
type: 'single_state'
arguments:
- 'status'
The usage of the 'status' elsewhere in the application is guarded by the ValueObject MyStatus:
class MyStatus
{
const STATUS_NEW = 'new';
const STATUS_OTHER = 'other';
/** @var string **/
protected $status;
public function __construct(string $status) {
if(!in_array($status,self::getStatuses()) {
throw new InvalidArgumentException();
}
$this->status = $status;
}
public function __toString()
{
return $this->status;
}
public function getStatuses()
{
return [
self::STATUS_NEW,
self::STATUS_OTHER
];
}
}
This is then used in the MyEntity class:
...
/**
* @var MyStatus
*/
protected $status;
...
public function __construct()
{
$this->status = new MyStatus(MyStatus::NEW);
}
...
Currently, I get the following error when I try using a ValueObject:
ContextErrorException: Warning: Illegal offset type
Thrown in the SingleStateMarkingStore at line 52:
return new Marking(array($placeName => 1));
Could support for ValueObjects be realized by potentially doing a string cast?
return new Marking(array((string)$placeName => 1));
I hope I made my case clear and I'm not overlooking anything here that might indicate my feature request to be a non-issue or already available.
Thanks in advance,
Kind regards,
Mark