<commit_before><?php declare(strict_types=1);

namespace Symplify\ModularDoctrineFilters\Adapter\Nette\DI;

use Doctrine\ORM\Configuration;
use Nette\DI\Compiler;
use Nette\DI\CompilerExtension;
use Symplify\ModularDoctrineFilters\Contract\Filter\FilterInterface;
use Symplify\ModularDoctrineFilters\Contract\FilterManagerInterface;
use Symplify\ModularDoctrineFilters\EventSubscriber\EnableFiltersSubscriber;

final class ModularDoctrineFiltersExtension extends CompilerExtension
{
    /**
     * @var DefinitionFinder
     */
    private $definitionFinder;

    public function loadConfiguration()
    {
        Compiler::loadDefinitions(
            $this->getContainerBuilder(),
            $this->loadFromFile(__DIR__ . '/../../../config/services.neon')['services']
        );
    }

    public function beforeCompile() : void
    {
        $this->definitionFinder = new DefinitionFinder($this->getContainerBuilder());

        $this->loadFiltersToFilterManager();
        $this->passFilterManagerToSubscriber();
    }

    private function loadFiltersToFilterManager() : void
    {
        $containerBuilder = $this->getContainerBuilder();

        $filterManagerDefinition = DefinitionFinder::getByType($containerBuilder, FilterManagerInterface::class);
        $ormConfigurationDefinition = DefinitionFinder::getByType($containerBuilder, Configuration::class);

        $filterDefinitions = $containerBuilder->findByType(FilterInterface::class);
        foreach ($filterDefinitions as $name => $filterDefinition) {
            // 1) to filter manager to run conditions and enable allowed only
            $filterManagerDefinition->addSetup(
                'addFilter',
                [$name, '@' . $name]
            );
            // 2) to Doctrine itself
            $ormConfigurationDefinition->addSetup(
                'addFilter',
                [$name, $filterDefinition->getClass()]<commit_msg>cleanup<commit_after><?php declare(strict_types=1);

namespace Symplify\ModularDoctrineFilters\Adapter\Nette\DI;

use Doctrine\ORM\Configuration;
use Nette\DI\Compiler;
use Nette\DI\CompilerExtension;
use Symplify\ModularDoctrineFilters\Contract\Filter\FilterInterface;
use Symplify\ModularDoctrineFilters\Contract\FilterManagerInterface;
use Symplify\ModularDoctrineFilters\EventSubscriber\EnableFiltersSubscriber;

final class ModularDoctrineFiltersExtension extends CompilerExtension
{
    public function loadConfiguration()
    {
        Compiler::loadDefinitions(
            $this->getContainerBuilder(),
            $this->loadFromFile(__DIR__ . '/../../../config/services.neon')['services']
        );
    }

    public function beforeCompile() : void
    {
        $this->loadFiltersToFilterManager();
        $this->passFilterManagerToSubscriber();
    }

    private function loadFiltersToFilterManager() : void
    {
        $containerBuilder = $this->getContainerBuilder();

        $filterManagerDefinition = DefinitionFinder::getByType($containerBuilder, FilterManagerInterface::class);
        $ormConfigurationDefinition = DefinitionFinder::getByType($containerBuilder, Configuration::class);

        $filterDefinitions = $containerBuilder->findByType(FilterInterface::class);
        foreach ($filterDefinitions as $name => $filterDefinition) {
            // 1) to filter manager to run conditions and enable allowed only
            $filterManagerDefinition->addSetup(
                'addFilter',
                [$name, '@' . $name]
            );
            // 2) to Doctrine itself
            $ormConfigurationDefinition->addSetup(
                'addFilter',
                [$name, $filterDefinition->getClass()]
{'fraction_non_alphanumeric': 0.10694748358862144, 'fraction_numerical': 0.0016411378555798686, 'mean_word_length': 3.3125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '380806', 'n_tokens_mistral': 919, 'n_tokens_neox': 903, 'n_words': 158}