apply() public method

public apply ( $transitionName, array $parameters = [] )
$parameters array
コード例 #1
0
ファイル: Finite.php プロジェクト: AM2studio/Laravel-Finite
 /**
  * Transitions selected object
  *
  * @param \Illuminate\Database\Eloquent\Model $object
  * @param $value
  * @throws \Finite\Exception\StateException
  */
 public function apply(\Illuminate\Database\Eloquent\Model $object, $value, $properties = [])
 {
     $this->setStateMachine($object);
     $this->stateMachine->apply($value);
     $object->saveFiniteRelationship($this->stateMachine->getCurrentState()->getName(), $properties);
     event(new StateSuccessfullyApplied($object));
 }
コード例 #2
0
ファイル: CallbacksTest.php プロジェクト: Rioji/Finite
 public function test()
 {
     $this->callbacksMock->expects($this->once())->method('afterItWasProposed');
     $this->callbacksMock->expects($this->exactly(2))->method('afterItWasProposedOrReviewed');
     $this->callbacksMock->expects($this->exactly(2))->method('afterItWasAnythingButProposed');
     $this->callbacksMock->expects($this->once())->method('onReview');
     $this->callbacksMock->expects($this->once())->method('afterItLeavesReviewed');
     $this->stateMachine->apply('propose');
     $this->stateMachine->apply('review');
     $this->stateMachine->apply('publish');
     $this->alternativeStateMachine->apply('propose');
     $this->alternativeStateMachine->apply('review');
     $this->alternativeStateMachine->apply('publish');
 }
コード例 #3
0
 /**
  * Apply a transition.
  *
  * @param string $transitionName
  * @param array  $parameters
  *
  * @return mixed
  * @throws StateException
  */
 public function apply($transitionName, array $parameters = [])
 {
     return $this->stateMachine->apply($transitionName, $parameters);
 }
コード例 #4
0
use Finite\State\State;
use Finite\State\StateInterface;
use Finite\StateMachine\StateMachine;
// Composer Autoloader
require_once '../vendor/autoload.php';
// Create a new State Machine
$stateMachine = new StateMachine();
// define some States
$stateMachine->addState(new State('state1', StateInterface::TYPE_INITIAL));
$stateMachine->addState(new State('state2'));
$stateMachine->addState(new State('state3'));
$stateMachine->addState(new State('state4', StateInterface::TYPE_FINAL));
$thing = new Thing();
// add some transitions
$stateMachine->addTransition('from_1_to_2', 'state1', 'state2');
$stateMachine->addTransition('from_2_to_3', 'state2', 'state3');
$stateMachine->addTransition('from_3_to_4', 'state3', 'state4');
$stateMachine->addTransition('from_4_to_2', 'state4', 'state2');
// add stateful object into state machine
$stateMachine->setObject($thing);
$stateMachine->initialize();
// current state
echo $stateMachine->getCurrentState();
// can transition to a valid state
var_dump($stateMachine->can('from_1_to_2'));
// can transition to a invalid state
var_dump($stateMachine->can('from_2_to_3'));
// switch state
$stateMachine->apply('from_1_to_2');
var_dump($stateMachine->can('from_2_to_3'));
echo $stateMachine->getCurrentState();
コード例 #5
0
 /**
  * @param $name
  *
  * @return mixed
  * @throws \Finite\Exception\StateException
  */
 public function transition($name)
 {
     return $this->stateMachine->apply($name);
 }