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

isAttachedTo() публичный статический Метод

This method returns FALSE if $model is not an instance of yii\base\Component or if none of its attached behaviors is a or inherit from SimpleWorkflowBehavior.
public static isAttachedTo ( BaseActiveRecord $model ) : boolean
$model yii\db\BaseActiveRecord the model to test.
Результат boolean TRUE if at least one SimpleWorkflowBehavior behavior is attached to $model, FALSE otherwise
    public static function isAttachedTo($model)
    {
        if ($model instanceof yii\base\Component) {
            foreach ($model->getBehaviors() as $behavior) {
                if ($behavior instanceof SimpleWorkflowBehavior) {
                    return true;
                }
            }
        } else {
            throw new WorkflowException('Invalid argument type : $model must be a BaseActiveRecord');
        }
        return false;
    }

Usage Example

 /**
  * (non-PHPdoc)
  * @see \yii\base\Object::init()
  */
 public function init()
 {
     parent::init();
     if (!isset($this->containerId)) {
         throw new InvalidConfigException("Parameter 'containerId' is missing ");
     }
     if (!isset($this->visNetworkId)) {
         $this->visNetworkId = uniqid('vis_');
     }
     if (!isset($this->workflow)) {
         throw new InvalidConfigException("Parameter 'workflow' is missing ");
     }
     if ($this->workflow instanceof \yii\base\Model) {
         if (!\raoul2000\workflow\base\SimpleWorkflowBehavior::isAttachedTo($this->workflow)) {
             throw new InvalidConfigException("The model passed as parameter 'workflow' is not attached to a SimpleWorkflowBehavior.");
         }
         $this->_workflow = $this->workflow->getWorkflow();
         if ($this->_workflow == null) {
             $this->_workflow = $this->workflow->getWorkflowSource()->getWorkflow($this->workflow->getDefaultWorkflowId());
         }
     } elseif ($this->workflow instanceof \raoul2000\workflow\base\WorkflowInterface) {
         $this->_workflow = $this->workflow;
     }
     if ($this->_workflow == null) {
         throw new InvalidConfigException("Failed to find workflow instance from parameter 'workflow'");
     }
     $this->_visId = uniqid();
 }
All Usage Examples Of raoul2000\workflow\base\SimpleWorkflowBehavior::isAttachedTo