Completed
Push — master ( 36c459...78506e )
by Guillaume
02:39
created

AbstractGenerator::getFichiers()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
nc 1
1
<?php
2
3
namespace Starkerxp\StructureBundle\Generator;
4
5
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
6
use Symfony\Component\HttpKernel\Bundle\Bundle;
7
use Symfony\Component\HttpKernel\KernelInterface;
8
use Symfony\Component\Yaml\Yaml;
9
10
abstract class AbstractGenerator extends Generator
11
{
12
    /**
13
     * @var KernelInterface
14
     */
15
    protected $kernel;
16
17
    public abstract function getFichiers();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
18
    public abstract function getClef();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
19
    public abstract function getParamaters(Bundle $bundle, $libelle);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
20
21
    public function traiterLeFichier($fichier, $target, $parameters)
22
    {
23
        if (file_exists($target) && explode('.', basename($target))[1] == 'yml') {
24
            $currentServices = Yaml::parse(file_get_contents($target));
25
            $newServices = Yaml::parse($this->render($fichier.'.twig', $parameters));
26
            if (empty($newServices['services'])) {
27
                return;
28
            }
29
            $listeNewServices = array_keys($newServices['services']);
30
            foreach ($listeNewServices as $servicePotentiel) {
31
                if (!empty($currentServices['services'][$servicePotentiel])) {
32
                    continue;
33
                }
34
                $currentServices['services'][$servicePotentiel] = $newServices['services'][$servicePotentiel];
35
            }
36
            $content = Yaml::dump($currentServices, 8, 4);
37
            $flink = fopen($target, 'w');
38
            if ($flink) {
39
                $write = fwrite($flink, $content);
40
                if ($write) {
41
                    fclose($flink);
42
                }
43
            }
44
        }
45
        $this->renderFile($fichier.'.twig', $target, $parameters);
46
    }
47
48
    /**
49
     * @param KernelInterface $kernel
50
     * @return AbstractGenerator
51
     */
52
    public function setKernel(KernelInterface $kernel)
53
    {
54
        $this->kernel = $kernel;
55
56
        return $this;
57
    }
58
59
60
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
61