/** * Evaluates the configured (symfony) expression for the given subject. * * @param StatefulSubjectInterface $subject * * @return boolean */ public function accept(StatefulSubjectInterface $subject) { $execution_context = $subject->getExecutionContext(); $parameters = $execution_context->getParameters(); if (is_object($parameters) && is_callable(array($parameters, 'toArray'))) { $params = $parameters->toArray(); } elseif (is_array($parameters)) { $params = $parameters; } else { throw new RuntimeError('Invalid return type given by execution context get parameters method.'); } return (bool) $this->expression_language->evaluate($this->getOption('expression'), array_merge(['subject' => $subject], $params)); }
/** * Evaluates the configured expression for the given subject. The expression may * use the current user as "current_user" and the subject as "subject". * * @param StatefulSubjectInterface $subject * * @return boolean true if transition is acceptable */ public function accept(StatefulSubjectInterface $subject) { $execution_context = $subject->getExecutionContext(); $parameters = $execution_context->getParameters(); if (is_array($parameters)) { $params = $parameters; } elseif (is_object($parameters) && is_callable(array($parameters, 'toArray'))) { $params = $parameters->toArray(); } else { throw new RuntimeError('The $subject->getExecutionContext()->getParameters() must return array or object with toArray method.'); } $transition_acceptable = $this->expression_service->evaluate($this->options->get('expression'), array_merge($params, ['subject' => $subject, 'current_user' => $this->environment->getUser()])); return (bool) $transition_acceptable; }
/** * Propagates the new state machine position to the execution context of the given subject, * by calling the execution context's "onStateExit" method. * * @param StatefulSubjectInterface $subject */ public function onExit(StatefulSubjectInterface $subject) { $subject->getExecutionContext()->onStateExit($this); }
/** * Determines the state at which to resume the exexution. * * @param StatefulSubjectInterface $subject * * @return StateInterface * * @throws Error If the state exposed by the subject's execution context is invalid or does not exist. */ protected function resumeExecutionState(StatefulSubjectInterface $subject) { return $this->getStateOrFail($subject->getExecutionContext()->getCurrentStateName()); }
/** * Evaluates the configured (symfony) expression for the given subject. * * @param StatefulSubjectInterface $subject * * @return boolean */ public function accept(StatefulSubjectInterface $subject) { $execution_context = $subject->getExecutionContext(); return (bool) $this->expression_language->evaluate($this->getOption('expression'), ['subject' => $subject, 'params' => $execution_context->getParameters()]); }