-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Description
We would find it helpful if a custom implementation of MarkingStoreInterface had access to the configured property in workflow configuration. Currently, it does not seem possible.
Default MethodMarkingStore takes into account the configured property name:
framework:
workflows:
order:
type: "state_machine"
marking_store:
type: "method"
property: "status"With this settings, the MethodMarkingStore operates with property status instead of the property marking which is set as default value in constructor:
final class MethodMarkingStore implements MarkingStoreInterface
{
public function __construct(bool $singleState = false, string $property = 'marking')
{
$this->property = $property;
// ...
}We would expect similar behaviour when using custom marking store, but the property configuration does not seem to have any effect:
framework:
workflows:
order:
type: "state_machine"
marking_store:
service: app.marking_store.custom
property: "status"namespace App\Workflow\MarkingStore;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
class CustomMarkingStore implements MarkingStoreInterface
{
protected string $property;
public function __construct(string $property = 'marking')
{
$this->property = $property;
}
}In this case, the CustomMarkingStore always operates with property marking (which is set as default in constructor), but it should operate with property status instead.
Alternatively, having an option to define service arguments in workflow configuration would solve the issue:
framework:
workflows:
order:
type: "state_machine"
marking_store:
service: app.marking_store.custom
arguments:
$property: "status"This seems to have been possible in version Symfony 4.4, but is no longer possible in Symfony 6.2.
Example
Currently, the only way to achieve the expected behaviour is to register a pre-configured service for each workflow definition like this:
services:
app.marking_store.oder:
class: App\Workflow\MarkingStore\CustomMarkingStore
arguments:
$property: 'status'
app.marking_store.item:
class: App\Workflow\MarkingStore\CustomMarkingStore
arguments:
$property: 'condition'framework:
workflows:
order:
type: "state_machine"
marking_store:
service: app.marking_store.order
item:
type: "state_machine"
marking_store:
service: app.marking_store.itemThis feels unfortunate in case we have many workflow definitions that use the same custom marking store, but differ in property name only.
If using property or arguments as described above is not an option, would it be possible to at least introduce a new interface, for example PropertyAwareInterface that could be implemented together with MarkingStoreInterface like this?
namespace App\Workflow\MarkingStore;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\PropertyAwareInterface;
class CustomMarkingStore implements MarkingStoreInterface, PropertyAwareInterface
{
protected string $property;
/**
* {@inheritdoc}
*/
public function setProperty(string $property): void
{
$this->property = $property;
}
}