<commit_before><?php
/**
 * @version     $Id$
 * @package     Koowa_Mixin
 * @copyright   Copyright (C) 2007 - 2012 <NAME>. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Toolbar Mixin Class
 *
 * @author      <NAME> <<EMAIL>>
 * @package     Koowa_Mixin
 */
class KMixinToolbar extends KMixinAbstract
{
    /**
     * List of toolbars
     *
     * Associative array of toolbars, where key holds the toolbar identifier string
     * and the value is an identifier object.
     *
     * @var    array
     */
    protected $_toolbars = array();

    /**
     * Constructor
     *
     * @param     object     An optional KConfig object with configuration options.
     */
    public function __construct(KConfig $config)
    {
        parent::__construct($config);

        //Add the toolbars
        $toolbars = (array)KConfig::unbox($config->toolbars);

        foreach ($toolbars as $key => $value)
        {
            if (is_numeric($key)) {
                $this->attachToolbar($value);
            } else {
                $this->attachToolbar($key, $value);
            }
        }
    }

    /**
     * Initializes the default configuration for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param     object     An optional KConfig object with configuration options.
     * @return void
     */
    protected function _initialize(KConfig $config)
    {
        parent::_initialize($config);

        $config->append(array(
            'toolbars' => array(),
        ));
    }

    /**
     * Add one or more toolbars
     *
     * @param   mixed    An object that implements KObjectServiceable, KServiceIdentifier object
     *                     or valid identifier string
     * @return  KObject    The mixer object
     */
    public function attachToolbar($toolbar, $config = array(), $priority = KEvent::PRIORITY_NORMAL)
    {
        if (!($toolbar instanceof KControllerToolbarInterface)) {
            $toolbar = $this->getToolbar($toolbar, $config);
        }

        if ($this->inherits('KMixinEvent')) {
            $this->addEventSubscriber($toolbar, $priority);
        }

        return $this->getMixer();
    }

    /**
     * Check if a toolbar exists
     *
     * @param     string    The name of the toolbar
     * @return  boolean    TRUE if the toolbar exists, FALSE otherwise
     */
    public function hasToolbar($toolbar)
    {
        return isset($this->_toolbars[$toolbar]);
    }

    /**
     * Get a toolbar by identifier
     *
     * @return KControllerToolbarAbstract
     */
    public function getToolbar($toolbar, $config = array())
    {
        if (!($toolbar instanceof KServiceIdentifier))
        {
            //Create the complete identifier if a partial identifier was passed
            if (is_string($toolbar) && strpos($toolbar, '.') === false)
            {
                $identifier = clone $this->getIdentifier();
                $identifier->path = array('controller', 'toolbar');
                $identifier->name = $toolbar;
            }
            else $identifier = $this->getIdentifier($toolbar);
        }
        else $identifier = $toolbar;

        if (!isset($this->_toolbars[$identifier->name]))
        {
            $config['controller'] = $this->getMixer();
            $toolbar = $this->getService($identifier, $config);

            if (!($toolbar instanceof KControllerToolbarInterface)) {
                throw new KControllerToolbarException("Controller toolbar $identifier does not implement KControllerToolbarInterface");
            }

            $this->_toolbars[$toolbar->getIdentifier()->name] = $toolbar;
        }
        else $toolbar = $this->_toolbars[$identifier->name];

        return $toolbar;
    }

    /**
     * Gets the toolbars
     *
     * @return array    An asscociate array of toolbars, keys are the toolbar names
     */
    public function getToolbars()
    {
        return $this->_toolbars;
    }
}<commit_msg>re #281 : Replaced exceptions by PHP defaults.<commit_after><?php
/**
 * @version     $Id$
 * @package     Koowa_Mixin
 * @copyright   Copyright (C) 2007 - 2012 <NAME>. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Toolbar Mixin Class
 *
 * @author      <NAME> <<EMAIL>>
 * @package     Koowa_Mixin
 */
class KMixinToolbar extends KMixinAbstract
{
    /**
     * List of toolbars
     *
     * The key holds the behavior name and the value the behavior object
     *
     * @var    array
     */
    protected $_toolbars = array();

    /**
     * Constructor
     *
     * @param     object     An optional KConfig object with configuration options.
     */
    public function __construct(KConfig $config)
    {
        parent::__construct($config);

        //Add the toolbars
        $toolbars = (array)KConfig::unbox($config->toolbars);

        foreach ($toolbars as $key => $value)
        {
            if (is_numeric($key)) {
                $this->attachToolbar($value);
            } else {
                $this->attachToolbar($key, $value);
            }
        }
    }

    /**
     * Initializes the default configuration for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param     object     An optional KConfig object with configuration options.
     * @return void
     */
    protected function _initialize(KConfig $config)
    {
        parent::_initialize($config);

        $config->append(array(
            'toolbars' => array(),
        ));
    }

    /**
     * Add one or more toolbars
     *
     * @param   mixed    An object that implements KObjectServiceable, KServiceIdentifier object
     *                   or valid identifier string
     * @return  KObject  The mixer object
     */
    public function attachToolbar($toolbar, $config = array(), $priority = KEvent::PRIORITY_NORMAL)
    {
        if (!($toolbar instanceof KControllerToolbarInterface)) {
            $toolbar = $this->getToolbar($toolbar, $config);
        }

        if ($this->inherits('KMixinEvent')) {
            $this->addEventSubscriber($toolbar, $priority);
        }

        return $this->getMixer();
    }

    /**
     * Check if a toolbar exists
     *
     * @param     string    The name of the toolbar
     * @return  boolean    TRUE if the toolbar exists, FALSE otherwise
     */
    public function hasToolbar($toolbar)
    {
        return isset($this->_toolbars[$toolbar]);
    }

    /**
     * Get a toolbar by identifier
     *
     * @return KControllerToolbarAbstract
     */
    public function getToolbar($toolbar, $config = array())
    {
        if (!($toolbar instanceof KServiceIdentifier))
        {
            //Create the complete identifier if a partial identifier was passed
            if (is_string($toolbar) && strpos($toolbar, '.') === false)
            {
                $identifier = clone $this->getIdentifier();
                $identifier->path = array('controller', 'toolbar');
                $identifier->name = $toolbar;
            }
            else $identifier = $this->getIdentifier($toolbar);
        }
        else $identifier = $toolbar;

        if (!isset($this->_toolbars[$identifier->name]))
        {
            $config['controller'] = $this->getMixer();
            $toolbar = $this->getService($identifier, $config);

            if (!($toolbar instanceof KControllerToolbarInterface)) {
                throw new \UnexpectedValueException("Controller toolbar $identifier does not implement KControllerToolbarInterface");
            }

            $this->_toolbars[$toolbar->getIdentifier()->name] = $toolbar;
        }
        else $toolbar = $this->_toolbars[$identifier->name];

        return $toolbar;
    }

    /**
     * Gets the toolbars
     *
     * @return array  An asscociate array of toolbars, keys are the toolbar names
     */
    public function getToolbars()
    {
        return $this->_toolbars;
    }
}
{'fraction_non_alphanumeric': 0.11833374293438191, 'fraction_numerical': 0.0025804866060457113, 'mean_word_length': 2.0110987791342954, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5613758', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2136, 'n_words': 572}