<commit_before><?php declare(strict_types=1);
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2015-2019, Darvin Studio
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\ContentBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
 * This is the class that validates and merges configuration from your app/config files
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder(): TreeBuilder
    {
        $builder = new TreeBuilder('darvin_content');

        /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $root */
        $root = $builder->getRootNode();
        $root
            ->children()
                ->arrayNode('property')->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('embedder')->addDefaultsIfNotSet()
                            ->children()
                                ->arrayNode('callbacks')->useAttributeAsKey('property')
                                    ->prototype('array')
                                        ->children()
                                            ->scalarNode('object_class')->isRequired()->cannotBeEmpty()->end()
                                            ->scalarNode('service')->isRequired()->cannotBeEmpty()->end()
                                            ->scalarNode('method')->isRequired()->cannotBeEmpty()->end()
                                        ->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
                ->arrayNode('canonical_url')->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('parameter_whitelist')->useAttributeAsKey('pattern')->prototype('boolean')->end()
                            ->validate()
                                ->ifTrue(function (array $whitelist) {
                                    foreach (array_keys($whitelist) as $pattern) {
                                        $pattern = (string)$pattern;

                                        if (false === @preg_match(sprintf('/^%s$/', $pattern), '')) {
                                            throw new \InvalidArgumentException(sprintf('"%s" is not valid pattern.', $pattern));
                                        }
                                    }
<commit_msg>Define property embedder callbacks configuration.<commit_after><?php declare(strict_types=1);
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2015-2019, Darvin Studio
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\ContentBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
 * This is the class that validates and merges configuration from your app/config files
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder(): TreeBuilder
    {
        $builder = new TreeBuilder('darvin_content');

        /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $root */
        $root = $builder->getRootNode();
        $root
            ->children()
                ->arrayNode('property')->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('embedder')->addDefaultsIfNotSet()
                            ->children()
                                ->arrayNode('callbacks')->useAttributeAsKey('property')
                                    ->prototype('array')
                                        ->children()
                                            ->scalarNode('object')->isRequired()->cannotBeEmpty()
                                                ->validate()
                                                    ->ifTrue(function ($object): bool {
                                                        $object = (string)$object;

                                                        return !class_exists($object) && !interface_exists($object);
                                                    })
                                                    ->thenInvalid('Object %s does not exist.')
                                                ->end()
                                            ->end()
                                            ->scalarNode('service')->isRequired()->cannotBeEmpty()->end()
                                            ->scalarNode('method')->isRequired()->cannotBeEmpty()->end()
                                        ->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
                ->arrayNode('canonical_url')->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('parameter_whitelist')->useAttributeAsKey('pattern')->prototype('boolean')->end()
                            ->validate()
                                ->ifTrue(function (array $whitelist) {
                                    foreach (array_keys($whitelist) as $pattern) {
                                        $pattern = (string)$pattern;

                                        if (false === @preg_match(sprintf('/^%s$/', $pattern), '')) {
                                            throw new \InvalidArgumentException(sprintf('"%s" is not valid pattern.', $pattern));
                                        }
                                    }

{'fraction_non_alphanumeric': 0.1191330110712615, 'fraction_numerical': 0.002806798690160611, 'mean_word_length': 1.245798319327731, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 93, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 52, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2632289', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1268, 'n_words': 256}