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