Completed
Push — develop ( 1febcc...70acef )
by Mario
03:07
created

Configs::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AppBundle\Tenant;
4
5
use Ds\Component\Config\Service\ConfigService;
6
use Ds\Component\Tenant\Loader\Loader;
7
use Symfony\Component\Yaml\Yaml;
8
9
/**
10
 * Class Configs
11
 */
12
class Configs implements Loader
13
{
14
    /**
15
     * @var \Ds\Component\Config\Service\ConfigService
16
     */
17
    protected $configService;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param \Ds\Component\Config\Service\ConfigService $configService
23
     */
24
    public function __construct(ConfigService $configService)
25
    {
26
        $this->configService = $configService;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function load(array $data)
33
    {
34
        $yml = file_get_contents('/srv/api-platform/src/AppBundle/Resources/tenant/configs.yml');
35
36
        // @todo Figure out how symfony does parameter binding and use the same technique
37
        $yml = strtr($yml, [
38
            '%config.app.spa.admin.value%' => $data['config']['app.spa.admin']['value'],
39
            '%config.app.spa.portal.value%' => $data['config']['app.spa.portal']['value'],
40
            '%business_unit.administration.uuid%' => $data['business_unit']['administration']['uuid'],
41
            '%tenant.uuid%' => $data['tenant']['uuid']
42
        ]);
43
44
        $configs = Yaml::parse($yml, YAML::PARSE_OBJECT_FOR_MAP);
45
        $manager = $this->configService->getManager();
46
47
        foreach ($configs->objects as $object) {
48
            $object = (object) array_merge((array) $configs->prototype, (array) $object);
49
            $config = $this->configService->createInstance();
50
            $config
51
                ->setOwner($object->owner)
52
                ->setOwnerUuid($object->owner_uuid)
53
                ->setKey($object->key)
54
                ->setValue($object->value)
55
                ->setTenant($object->tenant);
56
            $manager->persist($config);
57
            $manager->flush();
58
        }
59
    }
60
}
61