Elgg  Version 6.2
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  // reset services which could depend on config values
56  // need to reset the ServerCache in order to be able to save SRI calculations
57  $services->reset('serverCache');
58 
59  // early config is done, now get the core boot data
60  $data = $this->getBootData($config, $config->hasValue('installed'));
61 
62  $site = $data->getSite();
63  if ($site) {
64  $config->site = $site;
65  } else {
66  // must be set in config
67  $site = $config->site;
68  if (!$site instanceof \ElggSite) {
69  throw new RuntimeException('Before installation, config->site must have an unsaved ElggSite.');
70  }
71  }
72 
73  foreach ($data->getPluginMetadata() as $guid => $metadata) {
74  $services->metadataCache->save($guid, $metadata);
75  }
76 
77  $services->plugins->setBootPlugins($data->getActivePlugins(), false);
78 
79  // use value in settings.php if available
80  $debug = $config->getInitialValue('debug') ?? ($config->debug ?: LogLevel::CRITICAL);
81  $services->logger->setLevel($debug);
82 
83  $services->views->configureFromCache();
84  }
85 
91  public function clearCache() {
92  $this->cache->clear();
93  _elgg_services()->plugins->setBootPlugins(null);
94  _elgg_services()->config->_boot_cache_hit = false;
95  }
96 
105  private function getBootData(Config $config, bool $installed) {
106  $this->beginTimer([__METHOD__]);
107 
108  $config->_boot_cache_hit = false;
109 
110  $data = null;
111  if ($config->boot_cache_ttl > 0) {
112  $data = $this->cache->load('boot_data');
113  }
114 
115  if (!isset($data)) {
116  $data = new BootData();
117  $data->populate(_elgg_services()->entityTable, _elgg_services()->plugins, $installed);
118  if ($config->boot_cache_ttl && $installed) {
119  $this->cache->save('boot_data', $data, $config->boot_cache_ttl);
120  }
121  } else {
122  $config->_boot_cache_hit = true;
123  }
124 
125  $this->endTimer([__METHOD__]);
126 
127  return $data;
128  }
129 }
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:91
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:353
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
endTimer(array $keys)
Ends the timer (when enabled)
Definition: Profilable.php:59