Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing use of DSN for redis and mongo factories #24

Merged
merged 3 commits into from
Jan 27, 2016

Conversation

cryptiklemur
Copy link
Member

if (empty($config['dsn'])) {
$manager = new Manager(sprintf('mongodb://%s:%s', $config['host'], $config['port']));
} else {
$manager = new Manager($config['dsn']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgotten validate here

@Nyholm
Copy link
Member

Nyholm commented Jan 26, 2016

Cool solution with the DSN object.

Maybe you could override the validate function to make sure we validate the DSN on build time?

/**
     * {@inheritdoc}
     */
    public static function validate(array $options, $adapterName)
    {
        parent::validate(options, adapterName);

        if (empty($options['dsn'])) {
            return;
        }
        $dsn = new DSN($options['dsn']);
        if (!$dsn->isValid()) {
            throw new \InvalidArgumentException('Invalid DSN: '.$config['dsn']);
        }
    }


private function parseProtocol($dsn)
{
$regex = '/^(redis|mysql|mongodb|tcp):\/\//i';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be more generic with?:

 $regex = '|^(.*?)://|i';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would allow for any protocol to be considered valid. I only want redis, mysql, mongodb, and tcp to be considered valid for now

use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

@Nyholm
Copy link
Member

Nyholm commented Jan 26, 2016

Nice work. The DSN factory really makes sen and made the code cleaner.

Creating AbstractDsnAdapterFactory
Updating DSN to parse multiple hosts.
Adding tests for DSN
cryptiklemur added a commit that referenced this pull request Jan 27, 2016
Allowing use of DSN for redis and mongo factories
@cryptiklemur cryptiklemur merged commit 4724d79 into php-cache:master Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants