Elgg  Version master
BootService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
11 
18 class BootService {
19 
20  use Profilable;
21  use Cacheable;
22 
28  public function __construct(BaseCache $cache) {
29  $this->cache = $cache;
30  }
31 
40  public function boot(InternalContainer $services) {
41  $config = $services->config;
42 
43  // we were using NOTICE temporarily so we can't just check for null
44  if (!$config->hasInitialValue('debug') && !$config->debug) {
45  $config->debug = '';
46  }
47 
48  // copy all table values into config
49  foreach ($services->configTable->getAll() as $name => $value) {
50  $config->$name = $value;
51  }
52 
53  // prevent some data showing up in $config
54  foreach ($config::SENSITIVE_PROPERTIES as $name) {
55  unset($config->{$name});
56  }
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->dataCache->metadata->save($guid, $metadata);
74  }
75 
76  $services->plugins->setBootPlugins($data->getActivePlugins(), false);
77 
78  // use value in settings.php if available
79  $debug = $config->getInitialValue('debug') ?? ($config->debug ?: LogLevel::CRITICAL);
80  $services->logger->setLevel($debug);
81 
82  $services->views->configureFromCache();
83  }
84 
90  public function clearCache() {
91  $this->cache->clear();
92  _elgg_services()->plugins->setBootPlugins(null);
93  _elgg_services()->config->_boot_cache_hit = false;
94  }
95 
104  private function getBootData(Config $config, bool $installed) {
105  $this->beginTimer([__METHOD__]);
106 
107  $config->_boot_cache_hit = false;
108 
109  $data = null;
110  if ($config->boot_cache_ttl > 0) {
111  $data = $this->cache->load('boot_data');
112  }
113 
114  if (!isset($data)) {
115  $data = new BootData();
116  $data->populate(_elgg_services()->entityTable, _elgg_services()->plugins, $installed);
117  if ($config->boot_cache_ttl && $installed) {
118  $this->cache->save('boot_data', $data, $config->boot_cache_ttl);
119  }
120  } else {
121  $config->_boot_cache_hit = true;
122  }
123 
124  $this->endTimer([__METHOD__]);
125 
126  return $data;
127  }
128 }
trait Profilable
Make an object accept a timer.
Definition: Profilable.php:12
__construct(BaseCache $cache)
Constructs the bootservice.
Definition: BootService.php:28
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:40
$value
Definition: generic.php:51
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
load(stdClass $row)
Loads attributes from the entities table into the object.
The Elgg cache base class.
Definition: BaseCache.php:9
clearCache()
Clear the cache item.
Definition: BootService.php:90
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:18
Serializable collection of data used to boot Elgg.
Definition: BootData.php:16
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
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:59