Elgg  Version master
InternalContainer.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Di;
4 
5 use Elgg\Config;
10 
132 
142  public function initConfig(Config $config): Config {
143  $this->timer->begin([]);
144 
145  if (!$config->dataroot && !$config->installer_running) {
146  throw new ConfigurationException('Config value "dataroot" is required.');
147  }
148 
149  if (!$config->cacheroot) {
150  $config->cacheroot = $config->dataroot . 'caches';
151  }
152 
153  if (!$config->assetroot) {
154  $config->assetroot = $config->cacheroot . 'views_simplecache';
155  }
156 
157  if (!$config->wwwroot) {
158  $config->wwwroot = $this->request->sniffElggUrl();
159  }
160 
161  if (!$config->plugins_path) {
162  $config->plugins_path = Paths::project() . 'mod/';
163  }
164 
165  // move sensitive credentials into isolated services
166  $this->set('dbConfig', DbConfig::fromElggConfig($config));
167 
168  // get this stuff out of config!
169  foreach ($config::SENSITIVE_PROPERTIES as $name) {
170  unset($config->{$name});
171  }
172 
173  return $config;
174  }
175 
179  public static function factory(array $options = []) {
180  $container = parent::factory($options);
181 
182  if (isset($options['config'])) {
183  $config = $options['config'];
184  $container->set('config', function(ContainerInterface $c) use ($config) {
185  return $c->initConfig($config);
186  });
187  }
188 
189  return $container;
190  }
191 
195  public static function getDefinitionSources(): array {
196  return [\Elgg\Project\Paths::elgg() . 'engine/internal_services.php'];
197  }
198 }
static project()
Get the project root (where composer is installed) path with "/".
Definition: Paths.php:25
A generic parent class for Configuration exceptions.
static elgg()
Get the Elgg codebase path with "/".
Definition: Paths.php:44
static fromElggConfig(Config $config)
Construct from an Elgg Config.
Definition: DbConfig.php:85
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
Base DI Container class.
Definition: DiContainer.php:13
static factory(array $options=[])
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
initConfig(Config $config)
Validate, normalize, fill in missing values, and lock some.
$container
Definition: delete.php:24