ChainParameterCompiler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
c 1
b 0
f 0
dl 0
loc 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 27 4
1
<?php
2
3
4
namespace Oliverde8\PhpEtlBundle\DependencyInjection\Compiler;
5
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\Finder\Finder;
9
use Symfony\Component\Yaml\Yaml;
10
11
class ChainParameterCompiler implements CompilerPassInterface
12
{
13
    /** @TODO make this a parameter. */
14
    protected $paths = ["../config/etl/", "config/etl/", __DIR__ . "/../../Resources/config/etl"];
15
16
    /**
17
     * You can modify the container here before it is dumped to PHP code.
18
     */
19
    public function process(ContainerBuilder $container)
20
    {
21
        $definitionsArray = [];
22
        $definitionsString = [];
23
        $etlFiles = [];
24
25
        $finder = new Finder();
26
27
        foreach ($this->paths as $path) {
28
            if (file_exists($path)) {
29
                $etlFiles = array_merge($etlFiles, iterator_to_array($finder->in([$path])->name("*.yml")));
30
            }
31
        }
32
33
        foreach ($etlFiles as $etlFile) {
34
            // Register file so that when it's modified in dev mode symfony empty caches automatially.
35
            $container->fileExists($etlFile);
36
37
            $etlName = str_replace(".yml", "", $etlFile->getBasename());
38
            $ymlContent = file_get_contents($etlFile);
39
40
            $definitionsArray[$etlName] = Yaml::parse($ymlContent);
41
            $definitionsString[$etlName] = $ymlContent;
42
        }
43
44
        $container->setParameter("oliverde8-php-etl_chain", $definitionsArray);
45
        $container->setParameter("oliverde8-php-etl_chain__string", $definitionsString);
46
    }
47
}