/**
  * @param string|StateMachineEvent $event
  * @param string|null|false $role - null means automatically set role, false will explicitly NOT use any role
  * @return StateMachineContext
  * @throws EventNotFoundException
  * @throws InvalidSchemaException
  * @throws StateNotFoundException
  * @throws \Exception
  */
 public function trigger($event, $role = null)
 {
     $m = $this->owner;
     // State
     $state = $this->sm->getState($m->{$this->attr});
     // Role
     if ($role === null) {
         $role = $this->internalGetUserRole(Yii::$app->user->getIdentity(false));
     }
     // Event
     if (is_string($event)) {
         $evt = $state->getEventByLabel($event, $role);
         if (!$evt) {
             throw new EventNotFoundException("Event `{$event}` for Role `{$role}` not found in State Machine `{$this->sm->name}`");
         }
         $event = $evt;
     }
     // Context
     $context = $this->createContext($role);
     try {
         $this->sm->transition($event, $context);
     } catch (Exception $e) {
         $context->attachException($e);
     } finally {
         // Migrate the context errors to the virtual attribute
         foreach ($context->errors as $attr => $error) {
             $m->addError($this->virtAttr, $error);
         }
         return $context;
     }
 }