Elgg  Version master
BootService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
10 
17 class BootService {
18 
19  use Profilable;
20 
26  public function __construct(protected BootCache $cache) {
27  }
28 
37  public function boot(InternalContainer $services) {
38  $config = $services->config;
39 
40  // we were using NOTICE temporarily so we can't just check for null
41  if (!$config->hasInitialValue('debug') && !$config->debug) {
42  $config->debug = '';
43  }
44 
45  // copy all table values into config
46  foreach ($services->configTable->getAll() as $name => $value) {
47  $config->$name = $value;
48  }
49 
50  // prevent some data showing up in $config
51  foreach ($config::SENSITIVE_PROPERTIES as $name) {
52  unset($config->{$name});
53  }
54 
55  // early config is done, now get the core boot data
56  $data = $this->getBootData($config, $config->hasValue('installed'));
57 
58  $site = $data->getSite();
59  if ($site) {
60  $config->site = $site;
61  } else {
62  // must be set in config
63  $site = $config->site;
64  if (!$site instanceof \ElggSite) {
65  throw new RuntimeException('Before installation, config->site must have an unsaved ElggSite.');
66  }
67  }
68 
69  foreach ($data->getPluginMetadata() as $guid => $metadata) {
70  $services->metadataCache->save($guid, $metadata);
71  }
72 
73  $services->plugins->setBootPlugins($data->getActivePlugins(), false);
74 
75  // use value in settings.php if available
76  $debug = $config->getInitialValue('debug') ?? ($config->debug ?: LogLevel::CRITICAL);
77  $services->logger->setLevel($debug);
78 
79  $services->views->configureFromCache();
80  }
81 
87  public function clearCache() {
88  $this->cache->clear();
89  _elgg_services()->plugins->setBootPlugins(null);
90  _elgg_services()->config->_boot_cache_hit = false;
91  }
92 
101  private function getBootData(Config $config, bool $installed) {
102  $this->beginTimer([__METHOD__]);
103 
104  $config->_boot_cache_hit = false;
105 
106  $data = null;
107  if ($config->boot_cache_ttl > 0) {
108  $data = $this->cache->load('boot_data');
109  }
110 
111  if (!isset($data)) {
112  $data = new BootData();
113  $data->populate(_elgg_services()->entityTable, _elgg_services()->plugins, $installed);
114  if ($config->boot_cache_ttl && $installed) {
115  $this->cache->save('boot_data', $data, $config->boot_cache_ttl);
116  }
117  } else {
118  $config->_boot_cache_hit = true;
119  }
120 
121  $this->endTimer([__METHOD__]);
122 
123  return $data;
124  }
125 }
trait Profilable
Make an object accept a timer.
Definition: Profilable.php:12
Exception thrown if an error which can only be found on runtime occurs.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$site
Definition: icons.php:5
boot(InternalContainer $services)
Boots the engine.
Definition: BootService.php:37
$value
Definition: generic.php:51
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
__construct(protected BootCache $cache)
Constructs the bootservice.
Definition: BootService.php:26
load(stdClass $row)
Loads attributes from the entities table into the object.
Definition: ElggEntity.php:824
Boot Cache.
Definition: BootCache.php:13
clearCache()
Clear the cache item.
Definition: BootService.php:87
beginTimer(array $keys)
Start the timer (when enabled)
Definition: Profilable.php:43
$metadata
Output annotation metadata.
Definition: metadata.php:9
Boots Elgg and manages a cache of data needed during boot.
Definition: BootService.php:17
Serializable collection of data used to boot Elgg.
Definition: BootData.php:15
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
endTimer(array $keys)
Ends the timer (when enabled)
Definition: Profilable.php:59