<commit_before><?php

namespace Assmat\Providers;

use Silex\ServiceProviderInterface;
use Puzzle\Configuration;
use Silex\Application;
use Silex\Provider\DoctrineServiceProvider;
use Puzzle\PrefixedConfiguration;
use Assmat\DataSource\Repositories\Mysql\MysqlWrapper;

class MysqlDBAL implements ServiceProviderInterface
{
    public function register(Application $app)
    {
        $this->validatePuzzleConfiguration($app);
        $this->registerDatabases($app);
    }

    private function registerDatabases(Application $app)
    {
        $options = array();
        $configuration = $app['configuration'];

        $databases = array_keys($configuration->readRequired('db'));
        foreach($databases as $database)
        {
            $options[$database] = $this->registerDatabase($app, $configuration, $database);
        }

        $app->register(new DoctrineServiceProvider(), array(
            'dbs.options' => $options
        ));
    }

    private function registerDatabase(Application $app, Configuration $configuration, $database)
    {
        $configuration = new PrefixedConfiguration($configuration, 'db/ ' . $database);

        $options = array(
            'driver'   => 'pdo_mysql',
            'dbname'   => $configuration->readRequired('database'),
            'host'     => $configuration->readRequired('host'),
            'user'     => $configuration->readRequired('user'),
            'password' => $configuration->readRequired('password'),
            'port'     => $configuration->read('port', 3306),
            'charset'  => $configuration->read('charset', 'utf8'),
        );

        // Declare helper
        $app['db.' . $database] = $app->share(function() use ($app, $database) {
            return new MysqlWrapper($app['dbs'][$database]);
        });

        return $options;
    }

    public function boot(Application $app)
    {
    }

    private function validatePuzzleConfiguration(Application $app)
    {
        if(!isset($app['configuration']) || !$app['configuration'] instanceof Configuration)
        {
            throw new \LogicException(__CLASS__ . ' requires an instance of puzzle/configuration (as key "configuration")');
        }
    }
}<commit_msg>fix: mysql dbal provider config<commit_after><?php

namespace Assmat\Providers;

use Silex\ServiceProviderInterface;
use Puzzle\Configuration;
use Silex\Application;
use Silex\Provider\DoctrineServiceProvider;
use Puzzle\PrefixedConfiguration;
use Assmat\DataSource\Repositories\Mysql\MysqlWrapper;

class MysqlDBAL implements ServiceProviderInterface
{
    public function register(Application $app)
    {
        $this->validatePuzzleConfiguration($app);
        $this->registerDatabases($app);
    }

    private function registerDatabases(Application $app)
    {
        $options = array();
        $configuration = $app['configuration'];

        $databases = array_keys($configuration->readRequired('db'));
        foreach($databases as $database)
        {
            $options[$database] = $this->registerDatabase($app, $configuration, $database);
        }

        $app->register(new DoctrineServiceProvider(), array(
            'dbs.options' => $options
        ));
    }

    private function registerDatabase(Application $app, Configuration $configuration, $database)
    {
        $configuration = new PrefixedConfiguration($configuration, 'db/' . $database);

        $options = array(
            'driver'   => 'pdo_mysql',
            'dbname'   => $configuration->readRequired('database'),
            'host'     => $configuration->readRequired('host'),
            'user'     => $configuration->readRequired('user'),
            'password' => $configuration->readRequired('password'),
            'port'     => $configuration->read('port', 3306),
            'charset'  => $configuration->read('charset', 'utf8'),
        );

        // Declare helper
        $app['db.' . $database] = $app->share(function() use ($app, $database) {
            return new MysqlWrapper($app['dbs'][$database]);
        });

        return $options;
    }

    public function boot(Application $app)
    {
    }

    private function validatePuzzleConfiguration(Application $app)
    {
        if(!isset($app['configuration']) || !$app['configuration'] instanceof Configuration)
        {
            throw new \LogicException(__CLASS__ . ' requires an instance of puzzle/configuration (as key "configuration")');
        }
    }
}
{'fraction_non_alphanumeric': 0.13643515396718364, 'fraction_numerical': 0.0022476961114857273, 'mean_word_length': 2.9035087719298245, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5188102', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1138, 'n_words': 230}