Completed
Push — wip-platform ( c33bec...2d2054 )
by
unknown
03:47
created

BlastGenerator::addResource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
3
/*
4
 *
5
 * Copyright (C) 2015-2017 Libre Informatique
6
 *
7
 * This file is licenced under the GNU LGPL v3.
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Blast\Bundle\CoreBundle\Generator;
13
14
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
15
use Sonata\AdminBundle\Model\ModelManagerInterface;
16
17
/**
18
 * Class BlastGenerator.
19
 */
20
class BlastGenerator extends Generator
21
{
22
    private $file;
23
24
    private $modelManager;
25
26
    /**
27
     * @param string $file
28
     */
29
    public function __construct($file, ModelManagerInterface $manager, $skeletonDirectories)
30
    {
31
        $this->file = (string) $file;
32
        $this->modelManager = $manager;
33
        $this->setSkeletonDirs($skeletonDirectories);
34
    }
35
36
    /**
37
     * @param string $modelClass
38
     *
39
     * @throws \RuntimeException
40
     */
41
    public function addResource($modelClass)
42
    {
43
        $code = '';
44
45
        if (is_file($this->file)) {
46
            $code = rtrim(file_get_contents($this->file));
47
        }
48
49
        $parts = explode('\\', $modelClass);
50
51
        $this->renderFile('Blast.yml.twig', $this->file, array(
52
            'fqcn'    => $modelClass,
53
            'fields'  => $this->modelManager->getExportFields($modelClass),
54
            'entity'  => array_pop($parts),
55
            'oldCode' => $code,
56
        ));
57
    }
58
}
59