<commit_before><?php
/**
 * Webino (http://webino.sk)
 *
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
 * @copyright   Copyright (c) 2012-2014 Webino, s. r. o. (http://webino.sk)
 * @author      <NAME> <<EMAIL>>
 * @license     BSD-3-Clause
 */

namespace WebinoDraw\Draw;

use WebinoDraw\Exception\InvalidHelperException;
use WebinoDraw\Draw\Helper\HelperInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\ConfigInterface;

/**
 *
 */
class HelperPluginManager extends AbstractPluginManager
{
    /**
     * Default set of helpers factories
     *
     * @var array
     */
    protected $factories = [
        'webinodrawabsolutize' => 'WebinoDraw\Draw\Helper\Factory\AbsolutizeFactory',
        'webinodrawform'       => 'WebinoDraw\Draw\Helper\Factory\FormFactory',
    ];

    /**
     * Default set of helpers
     *
     * @var array
     */
    protected $invokableClasses = [
        'webinodrawelement' => 'WebinoDraw\Draw\Helper\Element',
    ];

    /**
     * Constructor
     *
     * After invoking parent constructor, add an initializer to inject the
     * attached helper, if any, to the currently requested helper.
     *
     * @param null|ConfigInterface $configuration
     */
    public function __construct(ConfigInterface $configuration = null)
    {
        parent::__construct($configuration);

        $this
            ->addInitializer([$this, 'injectEventManager'])
            ->addInitializer([$this, 'injectManipulator'])
            ->addInitializer([$this, 'injectVarTranslator'])
            ->addInitializer([$this, 'injectCache']);
    }

    /**
     * Inject a helper instance with the EventManager
     *
     * @param HelperInterface $helper
     */
    public function injectEventManager(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has('EventManager')) {
            $helper->setEventManager($locator->get('EventManager'));
            return;
        }
    }

    /**
     * Inject a helper instance with the WebinoDraw Manipulator
     *
     * @param HelperInterface $helper
     */
    public function injectManipulator(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has('WebinoDraw\Manipulator\Manipulator')) {
            $helper->setManipulator($locator->get('WebinoDraw\Manipulator\Manipulator'));
            return;
        }
    }

    /**
     * Inject a helper instance with the WebinoDraw VarTranslator
     *
     * @param HelperInterface $helper
     */
    public function injectVarTranslator(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has('WebinoDraw\VarTranslator\VarTranslator')) {
            $helper->setVarTranslator($locator->get('WebinoDraw\VarTranslator\VarTranslator'));
            return;
        }
    }

    /**
     * Inject a helper instance with the WebinoDraw DrawCache
     *
     * @param HelperInterface $helper
     */
    public function injectCache(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has('WebinoDraw\Cache\DrawCache')) {
            $helper->setCache($locator->get('WebinoDraw\Cache\DrawCache'));
            return;
        }
    }

    /**
     * Validate the plugin
     *
     * Checks that the helper loaded is an instance of HelperInterface.
     *
     * @param mixed $plugin
     * @throws Exception\InvalidHelperException if invalid
     */
    public function validatePlugin($plugin)
    {
        if ($plugin instanceof HelperInterface) {
            // we're okay
            return;
        }

        throw new InvalidHelperException(
            sprintf(
                'Plugin of type %s is invalid; must implement %s\Helper\HelperInterface',
                (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
                __NAMESPACE__
            )
        );
    }
}<commit_msg>Updated Draw\HelperPluginManager, use class constants instead of strings<commit_after><?php
/**
 * Webino (http://webino.sk)
 *
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
 * @copyright   Copyright (c) 2012-2015 Webino, s. r. o. (http://webino.sk)
 * @author      <NAME> <<EMAIL>>
 * @license     BSD-3-Clause
 */

namespace WebinoDraw\Draw;

use WebinoDraw\Cache\DrawCache;
use WebinoDraw\Draw\Helper\Element;
use WebinoDraw\Draw\Helper\Factory\AbsolutizeFactory;
use WebinoDraw\Draw\Helper\Factory\FormFactory;
use WebinoDraw\Exception;
use WebinoDraw\Draw\Helper\HelperInterface;
use WebinoDraw\Manipulator\Manipulator;
use WebinoDraw\VarTranslator\VarTranslator;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\ConfigInterface;

/**
 * Class HelperPluginManager
 */
class HelperPluginManager extends AbstractPluginManager
{
    /**
     * Default set of helpers factories
     *
     * @var array
     */
    protected $factories = [
        'webinodrawabsolutize' => AbsolutizeFactory::class,
        'webinodrawform'       => FormFactory::class,
    ];

    /**
     * Default set of helpers
     *
     * @var array
     */
    protected $invokableClasses = [
        'webinodrawelement' => Element::class,
    ];

    /**
     * Constructor
     *
     * After invoking parent constructor, add an initializer to inject the
     * attached helper, if any, to the currently requested helper.
     *
     * @param null|ConfigInterface $configuration
     */
    public function __construct(ConfigInterface $configuration = null)
    {
        parent::__construct($configuration);

        $this
            ->addInitializer([$this, 'injectEventManager'])
            ->addInitializer([$this, 'injectManipulator'])
            ->addInitializer([$this, 'injectVarTranslator'])
            ->addInitializer([$this, 'injectCache']);
    }

    /**
     * Inject a helper instance with the EventManager
     *
     * @param HelperInterface $helper
     */
    public function injectEventManager(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has('EventManager')) {
            $helper->setEventManager($locator->get('EventManager'));
            return;
        }
    }

    /**
     * Inject a helper instance with the WebinoDraw Manipulator
     *
     * @param HelperInterface $helper
     */
    public function injectManipulator(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has(Manipulator::class)) {
            $helper->setManipulator($locator->get(Manipulator::class));
            return;
        }
    }

    /**
     * Inject a helper instance with the WebinoDraw VarTranslator
     *
     * @param HelperInterface $helper
     */
    public function injectVarTranslator(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has(VarTranslator::class)) {
            $helper->setVarTranslator($locator->get(VarTranslator::class));
            return;
        }
    }

    /**
     * Inject a helper instance with the WebinoDraw DrawCache
     *
     * @param HelperInterface $helper
     */
    public function injectCache(HelperInterface $helper)
    {
        $locator = $this->getServiceLocator();
        if (!$locator) {
            return;
        }

        if ($locator->has(DrawCache::class)) {
            $helper->setCache($locator->get(DrawCache::class));
            return;
        }
    }

    /**
     * Validate the plugin
     *
     * Checks that the helper loaded is an instance of HelperInterface.
     *
     * @param mixed $plugin
     * @throws Exception\InvalidHelperException if invalid
     */
    public function validatePlugin($plugin)
    {
        if ($plugin instanceof HelperInterface) {
            // we're okay
            return;
        }

        throw new Exception\InvalidHelperException(
            sprintf(
                'Plugin of type %s is invalid; must implement %s\Helper\HelperInterface',
                (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
                __NAMESPACE__
            )
        );
    }
}
{'fraction_non_alphanumeric': 0.11573320938879851, 'fraction_numerical': 0.0020915640250987683, 'mean_word_length': 2.229643527204503, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 55, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '2391255', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2401, 'n_words': 503}