function it_resolves_order_states_with_state_machine_event(StateResolverInterface $stateResolver, TransitionEvent $event, OrderInterface $order, StateMachineInterface $sm) { $event->getStateMachine()->willReturn($sm); $sm->getObject()->willReturn($order); $stateResolver->resolveShippingState($order)->shouldBeCalled(); $stateResolver->resolvePaymentState($order)->shouldBeCalled(); $this->resolveOrderStatesOnTransition($event); }
/** * @param TransitionEvent $event */ public function resolveOrderStatesOnTransition(TransitionEvent $event) { $resource = $event->getStateMachine()->getObject(); if ($resource instanceof OrderInterface) { $this->resolve($resource); } elseif ($resource instanceof OrderAwareInterface && null !== $resource->getOrder()) { $this->resolve($resource->getOrder()); } }
function it_applies_with_default_graph_and_default_transition($factory, TransitionEvent $event, DummyObject $object, StateMachineInterface $sm1, StateMachineInterface $sm2) { $event->getStateMachine()->willReturn($sm2); $event->getTransition()->willReturn('transition'); $sm2->getGraph()->willReturn('graph'); $factory->get($object, 'graph')->willReturn($sm1); $sm1->can('transition')->willReturn(true); $sm1->apply('transition', true)->shouldBeCalled(); $this->apply($object, $event); }
/** * @param TransitionEvent $event * * @return mixed The returned value from the callback */ public function call(TransitionEvent $event) { if (!isset($this->specs['args'])) { $args = array($event); } else { $expr = new ExpressionLanguage(); $args = array_map(function ($arg) use($expr, $event) { return $expr->evaluate($arg, array('object' => $event->getStateMachine()->getObject(), 'event' => $event)); }, $this->specs['args']); } return call_user_func_array($this->callable, $args); }
/** * Apply a transition to the object that has just undergone a transition * * @param \Traversable|array $objects Object or array|traversable of objects to apply the transition on * @param TransitionEvent $event Transition event * @param string|null $transition Transition that is to be applied (if null, same as the trigger) * @param string|null $graph Graph on which the new transition will apply (if null, same as the trigger) * @param bool $soft If true, check if it can apply the transition first (no Exception thrown) */ public function apply($objects, TransitionEvent $event, $transition = null, $graph = null, $soft = true) { if (!is_array($objects) && !$objects instanceof \Traversable) { $objects = array($objects); } if (null === $transition) { $transition = $event->getTransition(); } if (null === $graph) { $graph = $event->getStateMachine()->getGraph(); } foreach ($objects as $object) { $this->factory->get($object, $graph)->apply($transition, $soft); } }
/** * @param callable|array $callable A callable or array with index 0 starting with "object" that will evaluated as a property path with "object" being the object undergoing the transition * @param TransitionEvent $event * * @return callable */ protected function filterCallable($callable, TransitionEvent $event) { if (is_array($callable) && isset($callable[0]) && is_string($callable[0]) && 'object' === substr($callable[0], 0, 6)) { $object = $event->getStateMachine()->getObject(); // callable could be "object.property" and not just "object", so we evaluate the "property" path if ('object' !== $callable[0]) { $accessor = new PropertyAccessor(); $object = $accessor->getValue($object, substr($callable[0], 7)); } return array($object, $callable[1]); } return $callable; }