<commit_before><?php

namespace UniMapper\Extension;

use Nette\Diagnostics,
    UniMapper\Exceptions\PropertyException;

/**
 * Nette Framework extension.
 */
class NetteExtension extends \Nette\Config\CompilerExtension
{

    /** @var array $defaults Default configuration */
    public $defaults = array();

    /**
     * Processes configuration data
     *
     * @return void
     */
    public function loadConfiguration()
    {
        $builder = $this->getContainerBuilder();
        if ($builder->parameters["debugMode"]) {

            // Create panel service
            $builder->addDefinition($this->prefix("panel"))
                ->setClass("UniMapper\Extension\NetteExtension\Panel")
                ->addSetup(
                    'Nette\Diagnostics\Debugger::$bar->addPanel(?)',
                    array('@self')
                )
                ->addSetup(
                    'Nette\Diagnostics\Debugger::$blueScreen->addPanel(?)',
                    array('UniMapper\Extension\NetteExtension::renderException')
                );

            // Create logger service
            $builder->addDefinition($this->prefix("logger"))
                ->setClass("UniMapper\Logger");
        }
    }

    public function beforeCompile()
    {
        $builder = $this->getContainerBuilder();
        if ($builder->parameters["debugMode"]) {

            // Register panel
            $builder->getDefinition("application")
                ->addSetup(
                    '$service->onStartup[] = ?',
                    array(array($this->prefix("@panel"), "getTab"))
                );

            // Find registered repository services
            $panel = $builder->getDefinition($this->prefix("panel"));
            foreach ($builder->getDefinitions() as $serviceName => $serviceDefinition) {

                $class = $serviceDefinition->class !== NULL ? $serviceDefinition->class : $serviceDefinition->factory->entity;
                if (class_exists($class) && is_subclass_of($class, "UniMapper\Repository")) {


                    $builder->getDefinition($serviceName)->addSetup("setLogger");

                    // Register repository into the panel
                    $panel->addSetup('registerRepository', "@" . $serviceName);
                }
            }
        }
    }

    /**
     * Register extension
     *
     * @param \Nette\Configurator $configurator
     */
    public static function register(\Nette\Configurator $configurator)
    {
        $class = get_class();
        $configurator->onCompile[] = function ($config, \Nette\Config\Compiler $compiler) use ($class) {
            $compiler->addExtension("unimapper", new $class);
        };
    }

    /**
     * Extend debugger bluescreen
     *
     * @param mixed $exception Exception
     *
     * @return array
     */
    public static function renderException($exception)
    {
        if ($exception instanceof PropertyException<commit_msg>extensions: Nette - fixed logger duplicities<commit_after><?php

namespace UniMapper\Extension;

use Nette\Diagnostics,
    UniMapper\Exceptions\PropertyException;

/**
 * Nette Framework extension.
 */
class NetteExtension extends \Nette\Config\CompilerExtension
{

    /** @var array $defaults Default configuration */
    public $defaults = array();

    /**
     * Processes configuration data
     *
     * @return void
     */
    public function loadConfiguration()
    {
        $builder = $this->getContainerBuilder();
        if ($builder->parameters["debugMode"]) {

            // Create panel service
            $builder->addDefinition($this->prefix("panel"))
                ->setClass("UniMapper\Extension\NetteExtension\Panel")
                ->addSetup(
                    'Nette\Diagnostics\Debugger::$bar->addPanel(?)',
                    array('@self')
                )
                ->addSetup(
                    'Nette\Diagnostics\Debugger::$blueScreen->addPanel(?)',
                    array('UniMapper\Extension\NetteExtension::renderException')
                );
        }
    }

    public function beforeCompile()
    {
        $builder = $this->getContainerBuilder();
        if ($builder->parameters["debugMode"]) {

            // Register panel
            $builder->getDefinition("application")
                ->addSetup(
                    '$service->onStartup[] = ?',
                    array(array($this->prefix("@panel"), "getTab"))
                );

            // Find registered repository services
            $panel = $builder->getDefinition($this->prefix("panel"));
            foreach ($builder->getDefinitions() as $serviceName => $serviceDefinition) {

                $class = $serviceDefinition->class !== NULL ? $serviceDefinition->class : $serviceDefinition->factory->entity;
                if (class_exists($class) && is_subclass_of($class, "UniMapper\Repository")) {


                    $builder->getDefinition($serviceName)->addSetup("setLogger", new \UniMapper\Logger);

                    // Register repository into the panel
                    $panel->addSetup('registerRepository', "@" . $serviceName);
                }
            }
        }
    }

    /**
     * Register extension
     *
     * @param \Nette\Configurator $configurator
     */
    public static function register(\Nette\Configurator $configurator)
    {
        $class = get_class();
        $configurator->onCompile[] = function ($config, \Nette\Config\Compiler $compiler) use ($class) {
            $compiler->addExtension("unimapper", new $class);
        };
    }

    /**
     * Extend debugger bluescreen
     *
     * @param mixed $exception Exception
     *
     * @return array
     */
    public static function renderException($exception)
    {
        if ($exception instanceof PropertyException
{'fraction_non_alphanumeric': 0.1310487342862063, 'fraction_numerical': 0.0, 'mean_word_length': 1.9845837615621789, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, 'https://': 0, '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': '5878607', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1404, 'n_words': 260}