Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

container_factory.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 5.29 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\install\helper;
015   
016  use phpbb\install\exception\cannot_build_container_exception;
017  use phpbb\language\language;
018  use phpbb\request\request;
019   
020  class container_factory
021  {
022      /**
023       * @var language
024       */
025      protected $language;
026   
027      /**
028       * @var string
029       */
030      protected $phpbb_root_path;
031   
032      /**
033       * @var string
034       */
035      protected $php_ext;
036   
037      /**
038       * @var request
039       */
040      protected $request;
041   
042      /**
043       * @var update_helper
044       */
045      protected $update_helper;
046   
047      /**
048       * The full phpBB container
049       *
050       * @var \Symfony\Component\DependencyInjection\ContainerInterface
051       */
052      protected $container;
053   
054      /**
055       * Constructor
056       *
057       * @param language         $language            Language service
058       * @param request        $request            Request interface
059       * @param update_helper    $update_helper        Update helper
060       * @param string        $phpbb_root_path    Path to phpBB's root
061       * @param string        $php_ext            Extension of PHP files
062       */
063      public function __construct(language $language, request $request, update_helper $update_helper, $phpbb_root_path, $php_ext)
064      {
065          $this->language            = $language;
066          $this->request            = $request;
067          $this->update_helper    = $update_helper;
068          $this->phpbb_root_path    = $phpbb_root_path;
069          $this->php_ext            = $php_ext;
070          $this->container        = null;
071      }
072   
073      /**
074       * Container getter
075       *
076       * @param null|string    $service_name    Name of the service to return
077       *
078       * @return \Symfony\Component\DependencyInjection\ContainerInterface|Object    phpBB's dependency injection container
079       *                                                                             or the service specified in $service_name
080       *
081       * @throws cannot_build_container_exception                                                        When container cannot be built
082       * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException            If the service is not defined
083       * @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException    When a circular reference is detected
084       * @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException            When the service is not defined
085       */
086      public function get($service_name = null)
087      {
088          // Check if container was built, if not try to build it
089          if ($this->container === null)
090          {
091              $this->build_container();
092          }
093   
094          return ($service_name === null) ? $this->container : $this->container->get($service_name);
095      }
096   
097      /**
098       * Returns the specified parameter from the container
099       *
100       * @param string    $param_name
101       *
102       * @return mixed
103       *
104       * @throws cannot_build_container_exception    When container cannot be built
105       */
106      public function get_parameter($param_name)
107      {
108          // Check if container was built, if not try to build it
109          if ($this->container === null)
110          {
111              $this->build_container();
112          }
113   
114          return $this->container->getParameter($param_name);
115      }
116   
117      /**
118       * Build dependency injection container
119       *
120       * @throws cannot_build_container_exception    When container cannot be built
121       */
122      protected function build_container()
123      {
124          // If the container has been already built just return.
125          // Although this should never happen
126          if ($this->container instanceof \Symfony\Component\DependencyInjection\ContainerInterface)
127          {
128              return;
129          }
130   
131          // Check whether container can be built
132          // We need config.php for that so let's check if it has been set up yet
133          if (!filesize($this->phpbb_root_path . 'config.' . $this->php_ext))
134          {
135              throw new cannot_build_container_exception();
136          }
137   
138          $disable_super_globals = $this->request->super_globals_disabled();
139   
140          // This is needed because container_builder::get_env_parameters() uses $_SERVER
141          if ($disable_super_globals)
142          {
143              $this->request->enable_super_globals();
144          }
145   
146          $phpbb_config_php_file = new \phpbb\config_php_file($this->phpbb_root_path, $this->php_ext);
147          $phpbb_container_builder = new \phpbb\di\container_builder($this->phpbb_root_path, $this->php_ext);
148   
149          // For BC with functions that we need during install
150          global $phpbb_container, $table_prefix;
151   
152          $other_config_path = $this->phpbb_root_path . 'install/update/new/config';
153          $config_path = (is_dir($other_config_path)) ? $other_config_path : $this->phpbb_root_path . 'config';
154   
155          $this->container = $phpbb_container_builder
156              ->with_environment('production')
157              ->with_config($phpbb_config_php_file)
158              ->with_config_path($config_path)
159              ->without_compiled_container()
160              ->get_container();
161   
162          // Setting request is required for the compatibility globals as those are generated from
163          // this container
164          if (!$this->container->isFrozen())
165          {
166              $this->container->register('request')->setSynthetic(true);
167              $this->container->register('language')->setSynthetic(true);
168          }
169   
170          $this->container->set('request', $this->request);
171          $this->container->set('language', $this->language);
172   
173          $this->container->compile();
174   
175          $phpbb_container = $this->container;
176          $table_prefix = $phpbb_config_php_file->get('table_prefix');
177   
178          // Restore super globals to previous state
179          if ($disable_super_globals)
180          {
181              $this->request->disable_super_globals();
182          }
183   
184          // Get compatibility globals and constants
185          $this->update_helper->include_file('includes/compatibility_globals.' . $this->php_ext);
186   
187          $this->update_helper->include_file('includes/constants.' . $this->php_ext);
188   
189          register_compatibility_globals();
190      }
191  }
192