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; }
/** * (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(); }