raoul2000\workflow\base\SimpleWorkflowBehavior::sendToStatusInternal PHP Метод

sendToStatusInternal() приватный Метод

This method is called when the owner model is about to change status. This occurs when it is saved, deleted, or when a call is done to sendToStatus() Based on the current value of the owner model status attribute and the internal behavior status, it checks if a transition is about to occur. If that's the case, this method fires all "before" events provided by the event sequence component and then updates status attributes values (both internal and at the owner model level). Finallly it fires the "after" events, or if we are in a save or delete operation, store them as pending events that are fired on the *afterSave" or afterDelete event. Note that if an event handler attached to a "before" event sets the event instance as invalid, all remaining handlers are ingored and the method returns immediately.
private sendToStatusInternal ( mixed $status, boolean $delayed ) : boolean
$status mixed the target status or NULL when leaving the workflow
$delayed boolean if TRUE, all 'after' events are not fire but stored for being fired in AfterSave or afterDelete. This occurs when the transition is performed on a save or delete action.
Результат boolean
    private function sendToStatusInternal($status, $delayed)
    {
        $this->_pendingEvents = [];
        list($newStatus, , $events) = $this->createTransitionItems($status, false, true);
        $delayedStop = false;
        if (!empty($events['before'])) {
            foreach ($events['before'] as $eventBefore) {
                $this->owner->trigger($eventBefore->name, $eventBefore);
                if ($eventBefore->isValid === false) {
                    if ($this->propagateErrorsToModel === true && count($eventBefore->getErrors()) != 0) {
                        $this->owner->addErrors([$this->statusAttribute => $eventBefore->getErrors()]);
                    }
                    if ($this->stopOnFirstInvalidEvent === true) {
                        return false;
                    } else {
                        $delayedStop = true;
                    }
                }
            }
        }
        if ($delayedStop) {
            return false;
        }
        $this->setStatusInternal($newStatus);
        if (!empty($events['after'])) {
            if ($delayed) {
                $this->_pendingEvents = $events['after'];
            } else {
                foreach ($events['after'] as $eventAfter) {
                    $this->owner->trigger($eventAfter->name, $eventAfter);
                }
            }
        }
        if ($this->getStatusAccessor() != null) {
            $this->_statusAccessor->updateStatus($this->owner, $newStatus);
        }
        return true;
    }