Completed
Push — master ( 8413a9...d75c00 )
by Narcotic
10:07
created

DocumentFieldNamesCompilerPass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * DocumentFieldNamesCompilerPass class file
4
 */
5
6
namespace Graviton\DocumentBundle\DependencyInjection\Compiler;
7
8
use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\Document;
9
use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\DocumentMap;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
13
/**
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class DocumentFieldNamesCompilerPass implements CompilerPassInterface
19
{
20
    /**
21
     * @var DocumentMap
22
     */
23
    private $documentMap;
24
25
    /**
26
     * load services
27
     *
28
     * @param ContainerBuilder $container container builder
29
     *
30
     * @return void
31
     */
32 4
    public function process(ContainerBuilder $container)
33
    {
34 4
        $this->documentMap = $container->get('graviton.document.map');
35
36 4
        $map = [];
37 4
        foreach ($this->documentMap->getDocuments() as $document) {
38 4
            $map[$document->getClass()] = $this->getFieldNames($document);
39
        }
40 4
        $container->setParameter('graviton.document.field.names', $map);
41 4
    }
42
43
    /**
44
     * Get field names
45
     *
46
     * @param Document $document Document
47
     * @return array
48
     */
49 4
    private function getFieldNames(Document $document)
50
    {
51 4
        $result = [];
52 4
        foreach ($document->getFields() as $field) {
53 4
            $result[$field->getFieldName()] = $field->getExposedName();
54
        }
55 4
        return $result;
56
    }
57
}
58