DoctrineMongodDBFactory::verifyDependencies()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 7
cp 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/*
4
 * This file is part of php-cache organization.
5
 *
6
 * (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\AdapterBundle\Factory;
13
14
use Cache\Adapter\Doctrine\DoctrineCachePool;
15
use Doctrine\Common\Cache\MongoDBCache;
16
use MongoClient;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
final class DoctrineMongodDBFactory extends AbstractDoctrineAdapterFactory
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getAdapter(array $config)
28
    {
29
        $mongo = new MongoClient();
30
        $collection = $mongo->selectCollection($config['host'], $config['collection']);
31
32
        return new DoctrineCachePool(new MongoDBCache($collection));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected static function configureOptionResolver(OptionsResolver $resolver)
39
    {
40
        $resolver->setRequired(['host', 'collection']);
41
42
        $resolver->setAllowedTypes('host', ['string']);
43
        $resolver->setAllowedTypes('collection', ['string']);
44
    }
45
46
    protected static function verifyDependencies()
47
    {
48
        if (!version_compare(phpversion('mongo'), '1.3.0', '>=')) {
49
            throw new \LogicException('Mongo >= 1.3.0 is required.');
50
        }
51
52
        parent::verifyDependencies();
53
    }
54
}
55