Finite icon indicating copy to clipboard operation
Finite copied to clipboard

Access transition parameters passed to apply() in TransitionInterface::process

Open iainmckay opened this issue 9 years ago • 2 comments

Hi, we're integrating Finite in our project and we're implementing our transition logic as concrete implementations of TransitionInterface. Tracing through the source, we've found the the parameters passed to StateMachine::apply() aren't passed to TransitionInterface::process.

Is there a reason for this? Would a PR be accepted to change this?

iainmckay avatar Apr 18 '16 12:04 iainmckay

Hi @iainmckay,

There is a single reason behind this : it implies modification on the TransitionInterface, which is a BC break...

I'll accept a PR for that with pleasure, but it implies a version bump to 2.0, which will not be tagged now as I have some new feature to include at the same time.

The current way to retrieve parameters at transition time is to implement listeners. Or to declare a method of your custom transition class as a transition callback.

yohang avatar Apr 20 '16 07:04 yohang

+1

I'm doing the same concrete implementation of transitions and being able to receive the parameters on the process method would be awesome.

As a fix, I created my own base Transition class that uses resolveProperties to store the values:

protected $propertyValues;

public function resolveProperties(array $properties)
{
    $this->propertyValues = parent::resolveProperties($properties);
    return $this->propertyValues;
}

public function getPropertyValue(string $property)
{
    return $this->propertyValues[$property] ?? null;
}

It depends on resolveProperties being called by the event, but at least I'm able to handle the values on the process method for now.

luads avatar Dec 02 '16 03:12 luads