<commit_before><?php

namespace Nedra\RestBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
 */
class NedraRestExtension extends Extension implements PrependExtensionInterface
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        if (!$config['active']) {
            return;
        }

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load("services.yml");

        $container->setParameter("nedrarest.config", $config);
    }

    /**
     * Allow an extension to prepend the extension configurations.
     *
     * @param ContainerBuilder $container
     */
    public function prepend(ContainerBuilder $container)
    {
        $append = false;
        $rules = [];
        foreach ($container->getExtensionConfig('fos_rest') as $config) {
            if (isset($config['format_listener'])) {
                foreach ($config['format_listener']['rules'] as $rule) {
                    if (!isset($rule['path'])) {
                        $rules['path'] = '^/';
                        $append = true;
                    }

                    if (!isset($rule['priorities'])) {
                        $rules['priorities'] = ['json', 'xml'];
                        $append = true;
                    }

                    if (!isset($rule['fallback_format'])) {
                        $rules['fallback_format'] = "json";
                        $append = true;
                    }

                    if (!isset($rule['prefer_extension'])) {
                        $rules['prefer_extension'] = false;
                        $append = true;
                    }
                }
            } else {
                $rules['path'] = '^/';
                $rules['priorities'] = ['json', 'xml'];
                $rules['fallback_format'] = "json";
                $rules['prefer_extension'] = false;
                $append = true;
            }
        }

        if ($append) {
            $container->prependExtensionConfig('fos_rest', [
                'format_listener' => [
                    'rules' => $rules
                ]
            ]);
        }
    }
}<commit_msg>fosrest format update<commit_after><?php

namespace Nedra\RestBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
 */
class NedraRestExtension extends Extension implements PrependExtensionInterface
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        if (!$config['active']) {
            return;
        }

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load("services.yml");

        $container->setParameter("nedrarest.config", $config);
    }

    /**
     * Allow an extension to prepend the extension configurations.
     *
     * @param ContainerBuilder $container
     */
    public function prepend(ContainerBuilder $container)
    {
        $append = false;
        $rules = [];
        foreach ($container->getExtensionConfig('fos_rest') as $config) {
            if (isset($config['format_listener'])) {
                foreach ($config['format_listener']['rules'] as $rule) {
                    if (!isset($rule['path'])) {
                        $rules['path'] = '^/';
                        $append = true;
                    }

                    if (!isset($rule['priorities'])) {
                        $rules['priorities'] = ['json'];
                        $append = true;
                    }

                    if (!isset($rule['fallback_format'])) {
                        $rules['fallback_format'] = "json";
                        $append = true;
                    }

                    if (!isset($rule['prefer_extension'])) {
                        $rules['prefer_extension'] = false;
                        $append = true;
                    }
                }
            } else {
                $rules['path'] = '^/';
                $rules['priorities'] = ['json'];
                $rules['fallback_format'] = "json";
                $rules['prefer_extension'] = false;
                $append = true;
            }
        }

        if ($append) {
            $container->prependExtensionConfig('fos_rest', [
                'format_listener' => [
                    'rules' => $rules
                ]
            ]);
        }
    }
}
{'fraction_non_alphanumeric': 0.1312477526069759, 'fraction_numerical': 0.0, 'mean_word_length': 1.749876421156698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3736344', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1345, 'n_words': 250}