FOF30\Model\DataModel::addBehaviour PHP Method

addBehaviour() public method

Adds a behaviour by its name. It will search the following classes, in this order: \component_namespace\Model\modelName\Behaviour\behaviourName \component_namespace\Model\DataModel\Behaviour\behaviourName \FOF30\Model\DataModel\Behaviour\behaviourName where: component_namespace is the namespace of the component as defined in the container modelName is the model's name, first character uppercase, e.g. Baz behaviourName is the $behaviour parameter, first character uppercase, e.g. Something
public addBehaviour ( string $behaviour )
$behaviour string The behaviour's name
    public function addBehaviour($behaviour)
    {
        $prefixes = array($this->container->getNamespacePrefix() . 'Model\\Behaviour\\' . ucfirst($this->getName()), $this->container->getNamespacePrefix() . 'Model\\Behaviour', '\\FOF30\\Model\\DataModel\\Behaviour');
        foreach ($prefixes as $prefix) {
            $className = $prefix . '\\' . ucfirst($behaviour);
            if (class_exists($className, true) && !$this->behavioursDispatcher->hasObserverClass($className)) {
                /** @var Observer $o */
                $observer = new $className($this->behavioursDispatcher);
                $this->behavioursDispatcher->attach($observer);
                return $this;
            }
        }
        return $this;
    }