Elgg  Version 4.3
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  use Cacheable;
21 
27  public function __construct(\ElggCache $cache) {
28  $this->cache = $cache;
29  }
30 
39  public function boot(InternalContainer $services) {
40  $config = $services->config;
41 
42  // we were using NOTICE temporarily so we can't just check for null
43  if (!$config->hasInitialValue('debug') && !$config->debug) {
44  $config->debug = '';
45  }
46 
47  // copy all table values into config
48  foreach ($services->configTable->getAll() as $name => $value) {
49  $config->$name = $value;
50  }
51 
52  // prevent some data showing up in $config
53  foreach ($config::SENSITIVE_PROPERTIES as $name) {
54  unset($config->{$name});
55  }
56 
57  // early config is done, now get the core boot data
58  $data = $this->getBootData($config, $services->db, $config->hasValue('installed'));
59 
60  $site = $data->getSite();
61  if ($site) {
62  $config->site = $site;
63  } else {
64  // must be set in config
65  $site = $config->site;
66  if (!$site instanceof \ElggSite) {
67  throw new RuntimeException('Before installation, config->site must have an unsaved ElggSite.');
68  }
69  }
70 
71  $config->sitename = $site->name; // deprecated
72  $config->sitedescription = $site->description; // deprecated
73 
74  foreach ($data->getPluginSettings() as $guid => $entity_settings) {
75  $services->privateSettingsCache->save($guid, $entity_settings);
76  }
77 
78  foreach ($data->getPluginMetadata() as $guid => $metadata) {
79  $services->dataCache->metadata->save($guid, $metadata);
80  }
81 
82  $services->plugins->setBootPlugins($data->getActivePlugins(), false);
83 
84  // use value in settings.php if available
85  $debug = $config->getInitialValue('debug') ?? ($config->debug ?: LogLevel::CRITICAL);
86  $services->logger->setLevel($debug);
87 
88  if ($config->system_cache_enabled) {
89  $config->system_cache_loaded = $services->views->configureFromCache($services->serverCache);
90  }
91  }
92 
98  public function clearCache() {
99  $this->cache->clear();
100  _elgg_services()->plugins->setBootPlugins(null);
101  _elgg_services()->config->system_cache_loaded = false;
102  _elgg_services()->config->_boot_cache_hit = false;
103  }
104 
114  private function getBootData(Config $config, Database $db, $installed) {
115  $this->beginTimer([__METHOD__]);
116 
117  $config->_boot_cache_hit = false;
118 
119  $data = null;
120  if ($config->boot_cache_ttl > 0) {
121  $data = $this->cache->load('boot_data');
122  }
123 
124  if (!isset($data)) {
125  $data = new BootData();
126  $data->populate($config, $db, _elgg_services()->entityTable, _elgg_services()->plugins, $installed);
127  if ($config->boot_cache_ttl && $installed) {
128  $this->cache->save('boot_data', $data, $config->boot_cache_ttl);
129  }
130  } else {
131  $config->_boot_cache_hit = true;
132  }
133 
134  $this->endTimer([__METHOD__]);
135 
136  return $data;
137  }
138 }
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
The Elgg database.
Definition: Database.php:25
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:53
$site
Definition: icons.php:5
boot(InternalContainer $services)
Boots the engine.
Definition: BootService.php:39
$value
Definition: generic.php:51
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
__construct(\ElggCache $cache)
Constructs the bootservice.
Definition: BootService.php:27
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
clearCache()
Clear the cache item.
Definition: BootService.php:98
beginTimer(array $keys)
Start the timer (when enabled)
Definition: Profilable.php:46
$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:16
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
trait Cacheable
Utility trait for injecting cache.
Definition: Cacheable.php:13
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
endTimer(array $keys)
Ends the timer (when enabled)
Definition: Profilable.php:62