IrsteaPlantUmlExtension.php 1.86 KB
Newer Older
1
<?php declare(strict_types=1);
2
/*
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
3
 * Copyright (C) 2016-2018 IRSTEA
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
4
 * All rights reserved.
5 6 7 8
 */

namespace Irstea\PlantUmlBundle\DependencyInjection;

9 10
use Irstea\PlantUmlBundle\DependencyInjection\Builder\ClassFilterBuilder;
use Irstea\PlantUmlBundle\DependencyInjection\Builder\GraphDefinitionBuilder;
11
use Symfony\Component\Config\FileLocator;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13 14
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
15 16

/**
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
17
 * Description of IrsteaPlantUmlExtension.
18 19 20 21 22
 */
class IrsteaPlantUmlExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
Guillaume Perréal's avatar
CS.  
Guillaume Perréal committed
23
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
24 25
        $loader->load('services.yml');

26 27 28
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

29 30 31 32 33 34
        $container->setParameter('irstea_plant_uml.binaries.java', $config['binaries']['java']);
        $container->setParameter('irstea_plant_uml.binaries.plamtuml_jar', $config['binaries']['plamtuml_jar']);
        $container->setParameter('irstea_plant_uml.binaries.dot', $config['binaries']['dot']);
        $container->setParameter('irstea_plant_uml.output.directory', $config['output']['directory']);
        $container->setParameter('irstea_plant_uml.output.format', $config['output']['format']);
        $container->setParameter('irstea_plant_uml.graph_keys', array_keys($config['graphs']));
35

36 37 38 39 40
        $filterBuilder = new ClassFilterBuilder($container);
        foreach ($config['graphs'] as $key => $graph) {
            $id = "irstea_plant_uml.graph.$key";
            $builder = new GraphDefinitionBuilder($container, $id, $graph, $filterBuilder);
            $container->setDefinition($id, $builder->build());
41
        }
42 43
    }
}