[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/extension/di/ -> extension_base.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\extension\di;
  15  
  16  use Symfony\Component\Config\FileLocator;
  17  use Symfony\Component\Config\Resource\FileResource;
  18  use Symfony\Component\DependencyInjection\ContainerBuilder;
  19  use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  20  use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  21  
  22  /**
  23   * Container core extension
  24   */
  25  class extension_base extends Extension
  26  {
  27      /**
  28       * Name of the extension (vendor/name)
  29       *
  30       * @var string
  31       */
  32      protected $extension_name;
  33  
  34      /**
  35       * Path to the extension.
  36       *
  37       * @var string
  38       */
  39      protected $ext_path;
  40  
  41      /**
  42       * Constructor
  43       *
  44       * @param string $extension_name Name of the extension (vendor/name)
  45       * @param string $ext_path       Path to the extension
  46       */
  47  	public function __construct($extension_name, $ext_path)
  48      {
  49          $this->extension_name = $extension_name;
  50          $this->ext_path = $ext_path;
  51      }
  52  
  53      /**
  54       * Loads a specific configuration.
  55       *
  56       * @param array            $configs   An array of configuration values
  57       * @param ContainerBuilder $container A ContainerBuilder instance
  58       *
  59       * @throws \InvalidArgumentException When provided tag is not defined in this extension
  60       */
  61  	public function load(array $configs, ContainerBuilder $container)
  62      {
  63          $this->load_services($container);
  64      }
  65  
  66      /**
  67       * Loads the services.yml file.
  68       *
  69       * @param ContainerBuilder $container A ContainerBuilder instance
  70       */
  71  	protected function load_services(ContainerBuilder $container)
  72      {
  73          $services_directory = false;
  74          $services_file = false;
  75  
  76          if (file_exists($this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/environment.yml'))
  77          {
  78              $services_directory = $this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/';
  79              $services_file = 'environment.yml';
  80          }
  81          else if (!is_dir($this->ext_path . 'config/' . $container->getParameter('core.environment')))
  82          {
  83              if (file_exists($this->ext_path . 'config/default/container/environment.yml'))
  84              {
  85                  $services_directory = $this->ext_path . 'config/default/container/';
  86                  $services_file = 'environment.yml';
  87              }
  88              else if (!is_dir($this->ext_path . 'config/default') && file_exists($this->ext_path . '/config/services.yml'))
  89              {
  90                  $services_directory = $this->ext_path . 'config';
  91                  $services_file = 'services.yml';
  92              }
  93          }
  94  
  95          if ($services_directory && $services_file)
  96          {
  97              $filesystem = new \phpbb\filesystem\filesystem();
  98              $loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($services_directory)));
  99              $loader->load($services_file);
 100          }
 101      }
 102  
 103      /**
 104       * {@inheritdoc}
 105       */
 106  	public function getConfiguration(array $config, ContainerBuilder $container)
 107      {
 108          $reflected = new \ReflectionClass($this);
 109          $namespace = $reflected->getNamespaceName();
 110  
 111          $class = $namespace . '\\di\configuration';
 112          if (class_exists($class))
 113          {
 114              $r = new \ReflectionClass($class);
 115              $container->addResource(new FileResource($r->getFileName()));
 116  
 117              if (!method_exists($class, '__construct'))
 118              {
 119                  $configuration = new $class();
 120  
 121                  return $configuration;
 122              }
 123          }
 124  
 125      }
 126  
 127      /**
 128       * Returns the recommended alias to use in XML.
 129       *
 130       * This alias is also the mandatory prefix to use when using YAML.
 131       *
 132       * @return string The alias
 133       */
 134  	public function getAlias()
 135      {
 136          return str_replace('/', '_', $this->extension_name);
 137      }
 138  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1