Completed
Pull Request — develop (#533)
by Mathias
07:53
created

MongoQueueFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 29 4
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2019 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Queue;
12
13
use Interop\Container\ContainerInterface;
14
use SlmQueue\Job\JobPluginManager;
15
use Zend\ServiceManager\Factory\FactoryInterface;
16
17
/**
18
 * Factory for \Core\Queue\MongoQueue
19
 * 
20
 * @author Mathias Gelhausen <[email protected]>
21
 */
22
class MongoQueueFactory implements FactoryInterface
23
{
24
    
25 2
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
26
    {
27
        /* @var \Doctrine\ODM\MongoDB\DocumentManager $dm */
28 2
        $config = $container->get('config');
29 2
        $config = $config['slm_queue']['queues'][$requestedName] ?? [];
30 2
        $dm = $container->get('Core/DocumentManager');
31
32
        // @codeCoverageIgnoreStart
33
        if (isset($config['dns'])) {
34
            $client = new \MongoDB\Client($config['dns']);
35
        } else {
36
            $client = $dm->getConnection()->getMongoClient()->getClient();
37
        }
38
        // @codeCoverageIgnoreEnd
39
40 2
        if (!isset($config['db'])) {
41 1
            $config['db'] = $dm->getConfiguration()->getDefaultDB();
42
        }
43
44 2
        if (!isset($config['collection'])) {
45 1
            $config['collection'] = 'core.queue';
46
        }
47
48 2
        $collection = $client->selectCollection($config['db'], $config['collection']);
49 2
        $jobPlugins = $container->get(JobPluginManager::class);
50
51 2
        $service = new MongoQueue($collection, $requestedName, $jobPlugins);
52
        
53 2
        return $service;    
54
    }
55
}
56