<commit_before><?php

namespace Digex;

use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface;
use Digex\Provider\ConfigurationServiceProvider;
use Silex\Provider\SessionServiceProvider;
use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\TwigServiceProvider;
use Silex\Provider\MonologServiceProvider;

/**
 * @author <NAME> <dpitard at digitas dot fr>
 * @copyright Digitas France
 */
abstract class StandardControllerProvider implements ControllerProviderInterface, ServiceProviderInterface
{
    protected function isEnabled(Application $app, $name)
    {
        return (isset($app['app.providers'][$name]) &&  $app['app.providers'][$name]);
    }
    
    public function register(Application $app)
    {
        if (!isset($app['app_dir'])) {
            throw new \Exception('"app_dir" parameter is undefined');
        }
        
        if (!isset($app['vendor_dir'])) {
            throw new \Exception('"vendor_dir" parameter is undefined');
        }
        
        if (!isset($app['config_dir'])) {
            $app['config_dir'] = $app['app_dir'] . '/config';
        }
        
        //register Configuration extension
        $app->register(new ConfigurationServiceProvider());
        
        if ($this->isEnabled($app, 'session')) {
            $app->register(new SessionServiceProvider());
        }
        
        //register UrlGenerator extension
        if ($this->isEnabled($app, 'url_generator')) {
            $app->register(new UrlGeneratorServiceProvider());
        }

        //register Twig
        if ($this->isEnabled($app, 'twig')) {

            if (!isset($app['twig.path'])) {
                $app['twig.path'] = $app['app_dir'] . '/Resources/views';
            }
            
            if (!isset($app['twig.class_path'])) {
                $app['twig.class_path'] = $app['vendor_dir'] . '/twig/lib';
            }
            
            if (!isset($app['twig.options']) && (!isset($app['debug']) || !$app['debug'])) {
                $app['twig.options'] = array('cache' => $app['app_dir'] . '/cache/twig');
            }
            
            $app->register(new TwigServiceProvider());
        }

        //register Monolog
        if ($this->isEnabled($app, 'monolog')) {
            $app->register(new MonologServiceProvider(), array(
                'monolog.logfile'       => $app['app_dir'].'/logs/app.log',
                'monolog.class_path'    => $app['vendor_dir'].'/monolog/src',
                'monolog.name' => 'app'
            ));
        }
    }
}<commit_msg>added Doctrine DBAL support<commit_after><?php

namespace Digex;

use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface;
use Digex\Provider\ConfigurationServiceProvider;
use Silex\Provider\SessionServiceProvider;
use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\TwigServiceProvider;
use Silex\Provider\MonologServiceProvider;
use Silex\Provider\DoctrineServiceProvider;

/**
 * @author <NAME> <dpitard at digitas dot fr>
 * @copyright Digitas France
 */
abstract class StandardControllerProvider implements ControllerProviderInterface, ServiceProviderInterface
{
    protected function isEnabled(Application $app, $name)
    {
        return (isset($app['app.providers'][$name]) &&  $app['app.providers'][$name]);
    }
    
    public function register(Application $app)
    {
        if (!isset($app['app_dir'])) {
            throw new \Exception('"app_dir" parameter is undefined');
        }
        
        if (!isset($app['vendor_dir'])) {
            throw new \Exception('"vendor_dir" parameter is undefined');
        }
        
        if (!isset($app['config_dir'])) {
            $app['config_dir'] = $app['app_dir'] . '/config';
        }
        
        //register Configuration extension
        $app->register(new ConfigurationServiceProvider());
        
        if ($this->isEnabled($app, 'session')) {
            $app->register(new SessionServiceProvider());
        }
        
        //register UrlGenerator extension
        if ($this->isEnabled($app, 'url_generator')) {
            $app->register(new UrlGeneratorServiceProvider());
        }

        //register Twig
        if ($this->isEnabled($app, 'twig')) {

            if (!isset($app['twig.path'])) {
                $app['twig.path'] = $app['app_dir'] . '/Resources/views';
            }
            
            if (!isset($app['twig.class_path'])) {
                $app['twig.class_path'] = $app['vendor_dir'] . '/twig/lib';
            }
            
            if (!isset($app['twig.options']) && (!isset($app['debug']) || !$app['debug'])) {
                $app['twig.options'] = array('cache' => $app['app_dir'] . '/cache/twig');
            }
            
            $app->register(new TwigServiceProvider());
        }

        //register Monolog
        if ($this->isEnabled($app, 'monolog')) {
            $app->register(new MonologServiceProvider(), array(
                'monolog.logfile'       => $app['app_dir'].'/logs/app.log',
                'monolog.class_path'    => $app['vendor_dir'].'/monolog/src',
                'monolog.name' => 'app'
            ));
        }
        
        //register Doctrine DBAL
        if ($this->isEnabled($app, 'doctrine-dbal')) {

            if (!isset($app['twig.driver'])) {
                $app['db.driver'] = 'pdo_mysql';
            }
            
            $app->register(new DoctrineServiceProvider(), array(
                'db.options'    => array(
                    'driver'    => $app['db.driver'],
                    'dbname'    => isset($app['db.dbname'])?$app['db.dbname']:null,
                    'host'      => $app['db.host']?$app['db.host']:null,
                    'user'      => $app['db.user']?$app['db.user']:null,
                    'password'  => $app['db.password']?$app['db.password']:null,
                ),
                'db.dbal.class_path'    => $app['vendor_dir'].'/doctrine-dbal/lib',
                'db.common.class_path'  => $app['vendor_dir'].'/doctrine-common/lib'
            ));
        }
    }
}
{'fraction_non_alphanumeric': 0.16255840180441436, 'fraction_numerical': 0.0, 'mean_word_length': 2.160896130346232, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4926144', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1751, 'n_words': 288}