<commit_before><?php

/*
 * This file is part of php-cache\cache-bundle package.
 *
 * (c) 2015-2015 <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Cache\CacheBundle\DependencyInjection\Compiler;

use Cache\Bridge\DoctrineCacheBridge;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Class DoctrineSupportCompilerPass
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class DoctrineSupportCompilerPass extends BaseCompilerPass
{
    /**
     * @return void
     * @throws \Exception
     */
    protected function prepare()
    {
        // If disabled, continue
        if (!$this->container->hasParameter('cache.doctrine')) {
            return;
        }

        if (!$this->hasDoctrine()) {
            throw new \Exception(
                "Not able to find any doctrine caches to implement. Ensure you have Doctrine ORM or ODM"
            );
        }

        if (!class_exists('Cache\Bridge\DoctrineCacheBridge')) {
            throw new \Exception(
                'You need the DoctrineBridge to be able to cache queries, results and metadata. Please run "composer.phar require cache/psr-6-doctrine-bridge" to install the missing dependency.'
            );
        }

        $this->enableDoctrineSupport($this->container->getParameter('cache.doctrine'));
    }

    /**
     * Loads the Doctrine configuration.
     *
     * @param array $config A configuration array
     *
     * @throws InvalidConfigurationException
     */
    protected function enableDoctrineSupport(array $config)
    {
        $types = ['entity_managers', 'document_managers'];
        foreach ($config as $cacheType => $cacheData) {
            foreach ($types as $type) {
                if (!isset($cacheData[$type])) {
                    continue;
                }

                $bridgeServiceId = sprintf('cache.provider.doctrine.%s.bridge', $cacheType);
                $bridgeDef = $this->container->register($bridgeServiceId, DoctrineCacheBridge::class);
                $bridgeDef->addArgument(0, new Reference($cacheData['service_id']))
                    ->setPublic(false);

                foreach ($cacheData[$type] as $manager) {
                    $doctrineDefinitionName =
                        sprintf(
                            "doctrine.%s.%s_%s_cache",<commit_msg>Use "composer" instead of "composer.phar"<commit_after><?php

/*
 * This file is part of php-cache\cache-bundle package.
 *
 * (c) 2015-2015 <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Cache\CacheBundle\DependencyInjection\Compiler;

use Cache\Bridge\DoctrineCacheBridge;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Class DoctrineSupportCompilerPass
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class DoctrineSupportCompilerPass extends BaseCompilerPass
{
    /**
     * @return void
     * @throws \Exception
     */
    protected function prepare()
    {
        // If disabled, continue
        if (!$this->container->hasParameter('cache.doctrine')) {
            return;
        }

        if (!$this->hasDoctrine()) {
            throw new \Exception(
                "Not able to find any doctrine caches to implement. Ensure you have Doctrine ORM or ODM"
            );
        }

        if (!class_exists('Cache\Bridge\DoctrineCacheBridge')) {
            throw new \Exception(
                'You need the DoctrineBridge to be able to cache queries, results and metadata. Please run "composer require cache/psr-6-doctrine-bridge" to install the missing dependency.'
            );
        }

        $this->enableDoctrineSupport($this->container->getParameter('cache.doctrine'));
    }

    /**
     * Loads the Doctrine configuration.
     *
     * @param array $config A configuration array
     *
     * @throws InvalidConfigurationException
     */
    protected function enableDoctrineSupport(array $config)
    {
        $types = ['entity_managers', 'document_managers'];
        foreach ($config as $cacheType => $cacheData) {
            foreach ($types as $type) {
                if (!isset($cacheData[$type])) {
                    continue;
                }

                $bridgeServiceId = sprintf('cache.provider.doctrine.%s.bridge', $cacheType);
                $bridgeDef = $this->container->register($bridgeServiceId, DoctrineCacheBridge::class);
                $bridgeDef->addArgument(0, new Reference($cacheData['service_id']))
                    ->setPublic(false);

                foreach ($cacheData[$type] as $manager) {
                    $doctrineDefinitionName =
                        sprintf(
                            "doctrine.%s.%s_%s_cache",
{'fraction_non_alphanumeric': 0.11226285937805594, 'fraction_numerical': 0.003911597887737141, 'mean_word_length': 2.340300457217505, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 43, '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': '6345597', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1304, 'n_words': 333}