Elgg  Version 4.3
InternalContainer.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Di;
4 
6 use Elgg\Config;
11 
136 
146  public function initConfig(Config $config): Config {
147  $this->timer->begin([]);
148 
149  if (!$config->dataroot && !$config->installer_running) {
150  throw new ConfigurationException('Config value "dataroot" is required.');
151  }
152 
153  if (!$config->cacheroot) {
154  $config->cacheroot = $config->dataroot . 'caches';
155  }
156 
157  if (!$config->assetroot) {
158  $config->assetroot = $config->cacheroot . 'views_simplecache';
159  }
160 
161  if (!$config->wwwroot) {
162  $config->wwwroot = $this->request->sniffElggUrl();
163  }
164 
165  if (!$config->plugins_path) {
166  $config->plugins_path = Paths::project() . 'mod/';
167  }
168 
169  $config->path = Paths::project(); // deprecated
170  $config->pluginspath = $config->plugins_path; // deprecated alias
171  $config->url = $config->wwwroot; // deprecated alias
172 
173  // move sensitive credentials into isolated services
174  $this->set('dbConfig', DbConfig::fromElggConfig($config));
175  $secret = \Elgg\Database\SiteSecret::fromConfig($config);
176  if ($secret) {
177  $this->set('siteSecret', $secret);
178  } else {
179  $this->set('siteSecret', function(ContainerInterface $c) {
180  return \Elgg\Database\SiteSecret::fromDatabase($c->configTable);
181  });
182  }
183 
184  // get this stuff out of config!
185  foreach ($config::SENSITIVE_PROPERTIES as $name) {
186  unset($config->{$name});
187  }
188 
189  return $config;
190  }
191 
195  public static function factory(array $options = []) {
196  $container = parent::factory($options);
197 
198  if (isset($options['config'])) {
199  $config = $options['config'];
200  $container->set('config', function(ContainerInterface $c) use ($config) {
201  return $c->initConfig($config);
202  });
203  }
204 
205  return $container;
206  }
207 
211  public static function getDefinitionSources(): array {
212  return [\Elgg\Project\Paths::elgg() . 'engine/internal_services.php'];
213  }
214 }
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:54
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
Base DI Container class.
Definition: DiContainer.php:13
static factory(array $options=[])
$options
Elgg admin footer.
Definition: footer.php:6
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
initConfig(Config $config)
Validate, normalize, fill in missing values, and lock some.
$container
Definition: delete.php:23