Completed
Push — master ( f9a038...cc9983 )
by Kamil
22:34
created

Driver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDataSource() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
13
14
use Sylius\Component\Grid\Data\DriverInterface;
15
use Sylius\Component\Grid\Parameters;
16
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
17
18
class Driver implements DriverInterface
19
{
20
    /**
21
     * Driver name
22
     */
23
    const NAME = 'doctrine/phpcr-odm';
24
25
    /**
26
     * Alias to use to reference fields from the data source class.
27
     */
28
    const QB_SOURCE_ALIAS = 'o';
29
30
    /**
31
     * @var DocumentManagerInterface
32
     */
33
    private $documentManager;
34
35
    /**
36
     * @param DocumentManagerInterface $documentManager
37
     */
38
    public function __construct(DocumentManagerInterface $documentManager)
39
    {
40
        $this->documentManager = $documentManager;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getDataSource(array $configuration, Parameters $parameters)
47
    {
48
        if (!array_key_exists('class', $configuration)) {
49
            throw new \InvalidArgumentException('"class" must be configured.');
50
        }
51
52
        $repository = $this->documentManager->getRepository($configuration['class']);
53
        $queryBuilder = $repository->createQueryBuilder(self::QB_SOURCE_ALIAS);
54
55
        return new DataSource($queryBuilder);
56
    }
57
}
58