yii\base\Component::attachBehaviorInternal PHP Method

attachBehaviorInternal() private method

Attaches a behavior to this component.
private attachBehaviorInternal ( string | integer $name, string | array | Behavior $behavior ) : Behavior
$name string | integer the name of the behavior. If this is an integer, it means the behavior is an anonymous one. Otherwise, the behavior is a named one and any existing behavior with the same name will be detached first.
$behavior string | array | Behavior the behavior to be attached
return Behavior the attached behavior.
    private function attachBehaviorInternal($name, $behavior)
    {
        if (!$behavior instanceof Behavior) {
            $behavior = Yii::createObject($behavior);
        }
        if (is_int($name)) {
            $behavior->attach($this);
            $this->_behaviors[] = $behavior;
        } else {
            if (isset($this->_behaviors[$name])) {
                $this->_behaviors[$name]->detach();
            }
            $behavior->attach($this);
            $this->_behaviors[$name] = $behavior;
        }
        return $behavior;
    }