<commit_before><?php

/**
 * This file is part of Symnedi.
 * Copyright (c) 2014 <NAME> (http://tomasvotruba.cz)
 */

namespace Symnedi\Validator\DI;

use Nette\DI\CompilerExtension;
use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Validator\RecursiveValidator;
use Symfony\Component\Validator\ValidatorBuilder;
use Symnedi\Validator\Caching\Cache;


class ValidatorExtension extends CompilerExtension
{

	public function loadConfiguration()
	{
		$builder = $this->getContainerBuilder();

		$builder->addDefinition($this->prefix('cache'))
			->setClass(Cache::class);

		$builder->addDefinition($this->prefix('validatorBuilder'))
			->setClass(ValidatorBuilder::class)
			->addSetup('enableAnnotationMapping')
			->addSetup('setMetadataCache');

		$builder->addDefinition($this->prefix('validator'))
			->setClass(RecursiveValidator::class)
			->setFactory(['@' . $this->prefix('validatorBuilder'), 'getValidator']);
	}

}<commit_msg>fix AnnotationReader reference<commit_after><?php

/**
 * This file is part of Symnedi.
 * Copyright (c) 2014 <NAME> (http://tomasvotruba.cz)
 */

namespace Symnedi\Validator\DI;

use Doctrine\Common\Annotations\AnnotationReader;
use Nette\DI\CompilerExtension;
use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Validator\RecursiveValidator;
use Symfony\Component\Validator\ValidatorBuilder;
use Symnedi\Validator\Caching\Cache;


class ValidatorExtension extends CompilerExtension
{

	public function loadConfiguration()
	{
		$containerBuilder = $this->getContainerBuilder();

		$containerBuilder->addDefinition($this->prefix('cache'))
			->setClass(Cache::class);

		$containerBuilder->addDefinition($this->prefix('validatorBuilder'))
			->setClass(ValidatorBuilder::class)
			->addSetup('setMetadataCache');

		$containerBuilder->addDefinition($this->prefix('validator'))
			->setClass(RecursiveValidator::class)
			->setFactory(['@' . $this->prefix('validatorBuilder'), 'getValidator']);
	}


	public function beforeCompile()
	{
		$annotationReaderName = $this->getNonAutowiredServiceNameByType(AnnotationReader::class);

		$containerBuilder = $this->getContainerBuilder();
		$containerBuilder->getDefinition($this->prefix('validatorBuilder'))
			->addSetup('enableAnnotationMapping', ['@' . $annotationReaderName]);
	}


	/**
	 * @param string $type
	 * @return string|NULL
	 */
	private function getNonAutowiredServiceNameByType($type)
	{
		$containerBuilder = $this->getContainerBuilder();
		foreach ($containerBuilder->findByType($type) as $name => $definition) {
			return $name;
		}
		return NULL;
	}

}
{'fraction_non_alphanumeric': 0.14857582755966128, 'fraction_numerical': 0.003079291762894534, 'mean_word_length': 6.179558011049724, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, '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': '2109266', 'n_tokens_mistral': 809, 'n_tokens_neox': 752, 'n_words': 120}