code/libraries/joomlatools/library/behavior/mixin/mixin.php
public function addBehavior($behavior, $config = array())
    {
        //Create the complete identifier if a partial identifier was passed
        if (is_string($behavior) && strpos($behavior, '.') === false)
        {
            $identifier = $this->getIdentifier()->toArray();
            if($identifier['path']) {
                $identifier['path'] = array($identifier['path'][0], 'behavior');
            } else {
                $identifier['path'] = array($identifier['name'], 'behavior');
            }
            $identifier['name'] = $behavior;

            $identifier = $this->getIdentifier($identifier);
        }
        else
        {
            if($behavior instanceof KBehaviorInterface) {
                $identifier = $behavior->getIdentifier();
            } else {
                $identifier = $this->getIdentifier($behavior);
            }
        }

        //Attach the behavior if it doesn't exist yet
        if (!$this->hasCommandHandler($identifier))
        {
            //Create the behavior object
            if (!($behavior instanceof KBehaviorInterface))
            {
                $config['mixer'] = $this->getMixer();
                $behavior = $this->getObject($identifier, $config);
            }

            if (!($behavior instanceof KBehaviorInterface)) {
                throw new UnexpectedValueException("Behavior $identifier does not implement KBehaviorInterface");
            }

            if(!$this->hasBehavior($behavior->getName()))
            {
                //Force set the mixer
                $behavior->setMixer($this->getMixer());

                //Add the behavior
                $this->addCommandHandler($behavior);

                //Mixin the behavior
                $this->mixin($behavior);

                //Store the behavior to allow for named lookups
                $this->__behaviors[$behavior->getName()] = $behavior;
            }
        }

        return $this->getMixer();
    }
public function addBehavior($behavior, $config = array())
    {
        //Create the complete identifier if a partial identifier was passed
        if (is_string($behavior) && strpos($behavior, '.') === false)
        {
            $identifier = $this->getIdentifier()->toArray();
            if($identifier['path']) {
                $identifier['path'] = array($identifier['path'][0], 'behavior');
            } else {
                $identifier['path'] = array($identifier['name'], 'behavior');
            }
            $identifier['name'] = $behavior;

            $identifier = $this->getIdentifier($identifier);
        }
        else
        {
            if($behavior instanceof KBehaviorInterface) {
                $identifier = $behavior->getIdentifier();
            } else {
                $identifier = $this->getIdentifier($behavior);
            }
        }

        //Attach the behavior if it doesn't exist yet
        if (!$this->hasCommandHandler($identifier))
        {
            //Create the behavior object
            if (!($behavior instanceof KBehaviorInterface))
            {
                $config['mixer'] = $this->getMixer();
                $behavior = $this->getObject($identifier, $config);
            }

            if (!($behavior instanceof KBehaviorInterface)) {
                throw new UnexpectedValueException("Behavior $identifier does not implement KBehaviorInterface");
            }

            if(!$this->hasBehavior($behavior->getName()))
            {
                //Force set the mixer
                $behavior->setMixer($this->getMixer());

                //Add the behavior
                $this->addCommandHandler($behavior);

                //Mixin the behavior
                $this->mixin($behavior);

                //Store the behavior to allow for named lookups
                $this->__behaviors[$behavior->getName()] = $behavior;
            }
        }

        return $this->getMixer();
    }
public function addBehavior ( $ behavior , $ config = array ( ) ) { //Create the complete identifier if a partial identifier was passed if ( is_string ( $ behavior ) && strpos ( $ behavior , '.' ) === false ) { $ identifier = $ this -> getIdentifier ( ) -> toArray ( ) ; if ( $ identifier [ 'path' ] ) { $ identifier [ 'path' ] = array ( $ identifier [ 'path' ] [ 0 ] , 'behavior' ) ; } else { $ identifier [ 'path' ] = array ( $ identifier [ 'name' ] , 'behavior' ) ; } $ identifier [ 'name' ] = $ behavior ; $ identifier = $ this -> getIdentifier ( $ identifier ) ; } else { if ( $ behavior instanceof KBehaviorInterface ) { $ identifier = $ behavior -> getIdentifier ( ) ; } else { $ identifier = $ this -> getIdentifier ( $ behavior ) ; } } //Attach the behavior if it doesn't exist yet if ( ! $ this -> hasCommandHandler ( $ identifier ) ) { //Create the behavior object if ( ! ( $ behavior instanceof KBehaviorInterface ) ) { $ config [ 'mixer' ] = $ this -> getMixer ( ) ; $ behavior = $ this -> getObject ( $ identifier , $ config ) ; } if ( ! ( $ behavior instanceof KBehaviorInterface ) ) { throw new UnexpectedValueException ( "Behavior $identifier does not implement KBehaviorInterface" ) ; } if ( ! $ this -> hasBehavior ( $ behavior -> getName ( ) ) ) { //Force set the mixer $ behavior -> setMixer ( $ this -> getMixer ( ) ) ; //Add the behavior $ this -> addCommandHandler ( $ behavior ) ; //Mixin the behavior $ this -> mixin ( $ behavior ) ; //Store the behavior to allow for named lookups $ this -> __behaviors [ $ behavior -> getName ( ) ] = $ behavior ; } } return $ this -> getMixer ( ) ; }
Add a behavior

@param   mixed $behavior An object that implements KBehaviorInterface, an KObjectIdentifier
or valid identifier string
@param   array $config An optional associative array of configuration settings
@throws UnexpectedValueException
@return  KObject The mixer object
Add a behavior