vendor/metamodels/core/src/CoreBundle/DependencyInjection/Configuration.php line 66

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of MetaModels/core.
  4.  *
  5.  * (c) 2012-2019 The MetaModels team.
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  *
  10.  * This project is provided in good faith and hope to be usable by anyone.
  11.  *
  12.  * @package    MetaModels/core
  13.  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  14.  * @author     Sven Baumann <baumann.sv@gmail.com>
  15.  * @copyright  2012-2019 The MetaModels team.
  16.  * @license    https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later
  17.  * @filesource
  18.  */
  19. namespace MetaModels\CoreBundle\DependencyInjection;
  20. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  21. use Symfony\Component\Config\Definition\ConfigurationInterface;
  22. use Webmozart\PathUtil\Path;
  23. /**
  24.  * Adds the Contao configuration structure.
  25.  */
  26. class Configuration implements ConfigurationInterface
  27. {
  28.     /**
  29.      * The debug flag.
  30.      *
  31.      * @var bool
  32.      */
  33.     private $debug;
  34.     /**
  35.      * The root directory.
  36.      *
  37.      * @var string
  38.      */
  39.     private $rootDir;
  40.     /**
  41.      * Constructor.
  42.      *
  43.      * @param bool   $debug   The debug flag.
  44.      * @param string $rootDir The root directory.
  45.      */
  46.     public function __construct($debug$rootDir)
  47.     {
  48.         $this->debug   = (bool) $debug;
  49.         $this->rootDir $rootDir;
  50.     }
  51.     /**
  52.      * Generates the configuration tree builder.
  53.      *
  54.      * @return TreeBuilder
  55.      */
  56.     public function getConfigTreeBuilder()
  57.     {
  58.         $treeBuilder = new TreeBuilder();
  59.         $rootNode    $treeBuilder->root('metamodels');
  60.         $rootNode
  61.             ->children()
  62.                 ->booleanNode('enable_cache')
  63.                     ->defaultValue(!$this->debug)
  64.                 ->end()
  65.                 ->scalarNode('cache_dir')
  66.                     ->defaultValue('%kernel.cache_dir%' DIRECTORY_SEPARATOR 'metamodels')
  67.                 ->end()
  68.                 ->scalarNode('assets_dir')
  69.                     ->cannotBeEmpty()
  70.                     ->defaultValue($this->resolvePath($this->rootDir '/assets/metamodels'))
  71.                     ->validate()
  72.                         ->always(function ($value) {
  73.                             return $this->resolvePath($value);
  74.                         })
  75.                     ->end()
  76.                 ->end()
  77.                 ->scalarNode('assets_web')
  78.                     ->cannotBeEmpty()
  79.                     ->defaultValue('assets/metamodels')
  80.                 ->end()
  81.             ->end();
  82.         return $treeBuilder;
  83.     }
  84.     /**
  85.      * Resolves a path.
  86.      *
  87.      * @param string $value The path.
  88.      *
  89.      * @return string
  90.      */
  91.     private function resolvePath($value)
  92.     {
  93.         $path Path::canonicalize($value);
  94.         if ('\\' === DIRECTORY_SEPARATOR) {
  95.             $path str_replace('/''\\'$path);
  96.         }
  97.         return $path;
  98.     }
  99. }