Closed
Description
It seems I cannot implement my own MarkingStore in Symfony 3.2, besides using SingleStateMarkingStore and MultipleStateMarkingStore.
Our use case (which is a state machine) requires some mapping of the places within the state machine. In our domain, the workflow which sets a "status" is an enumeration while our entity holds numeric values (due to legacy reasons) for this status.
Implementing a MarkingStore, such as the one below seems the cleanest solution.
public function getMarking($subject)
{
$value = $this->propertyAccessor->getValue($subject, $this->property); // should return 3
$placeName = $this->converter->convertToEnum($value); // should return FOR_SALE
if (!$placeName) {
return new Marking();
}
return new Marking(array($placeName => 1));
}
public function setMarking($subject, Marking $marking)
{
$value = key($marking->getPlaces()); // should return FOR_SALE
$placeName = $this->converter->convertToInt($value); //should return 3
$this->propertyAccessor->setValue($subject, $this->property, $placeName);
}
Adding new MarkingStores is avoided by the configuration, which defines the following:
...
->arrayNode('marking_store')
->fixXmlConfig('argument')
->children()
->enumNode('type')
->values(array('multiple_state', 'single_state'))
->end()
...
Am I missing something here?