SM\Callback\Callback::call PHP Method

call() public method

public call ( SM\Event\TransitionEvent $event ) : mixed
$event SM\Event\TransitionEvent
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) {
                if (!is_string($arg)) {
                    return $arg;
                }
                return $expr->evaluate($arg, array('object' => $event->getStateMachine()->getObject(), 'event' => $event));
            }, $this->specs['args']);
        }
        $callable = $this->filterCallable($this->callable, $event);
        return call_user_func_array($callable, $args);
    }

Usage Example

 /**
  * {@inheritDoc}
  */
 public function call(TransitionEvent $event)
 {
     // Load the services only now (when the callback is actually called)
     if (is_array($this->callable) && is_string($this->callable[0]) && 0 === strpos($this->callable[0], '@') && $this->container->has($serviceId = substr($this->callable[0], 1))) {
         $this->callable[0] = $this->container->get($serviceId);
     }
     return parent::call($event);
 }