Elgg  Version 3.0
BootHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Application;
4 
6 use Elgg\Event;
7 
13 class BootHandler {
14 
18  protected $app;
19 
25  public function __construct(Application $app) {
26  $this->app = $app;
27  }
28 
40  public function __invoke() {
41  $config = $this->app->_services->config;
42 
43  if ($config->boot_complete) {
44  return;
45  }
46 
47  $this->bootServices();
48  $this->bootPlugins();
49  $this->bootApplication();
50  }
51 
61  public function bootServices() {
62  $config = $this->app->_services->config;
63 
64  if ($config->_service_boot_complete) {
65  return;
66  }
67 
68  // in case not loaded already
69  $setups = $this->app->loadCore();
70 
71  $hooks = $this->app->_services->hooks;
72  $events = $this->app->_services->events;
73 
74  foreach ($setups as $setup) {
75  if ($setup instanceof \Closure) {
76  $setup($events, $hooks);
77  }
78  }
79 
80  if (!$this->app->_services->db) {
81  // no database boot!
83  $this->app->_services->session->start();
84  $this->app->_services->translator->bootTranslations();
85 
86  _elgg_init();
89 
90  $config->boot_complete = true;
91  $config->lock('boot_complete');
92 
93  return;
94  }
95 
96  $this->setEntityClasses();
97 
98  // Connect to database, load language files, load configuration, init session
99  $this->app->_services->boot->boot($this->app->_services);
100 
101  $config->_service_boot_complete = true;
102  $config->lock('_service_boot_complete');
103  }
104 
109  public function bootPlugins() {
110  $config = $this->app->_services->config;
111 
112  if ($config->_plugins_boot_complete || !$this->app->_services->db) {
113  return;
114  }
115 
116  $events = $this->app->_services->events;
117 
118  $events->registerHandler('plugins_load:before', 'system', 'elgg_views_boot');
119  $events->registerHandler('plugins_load:after', 'system', function() {
120  _elgg_session_boot($this->app->_services);
121  });
122 
123  $events->registerHandler('plugins_boot', 'system', '_elgg_register_routes');
124  $events->registerHandler('plugins_boot', 'system', '_elgg_register_actions');
125 
126  // Setup all boot sequence handlers for active plugins
127  $this->app->_services->plugins->build();
128 
129  // Register plugin classes, entities etc
130  // Call PluginBootstrap::load()
131  // After event completes, Elgg session is booted
132  $events->triggerSequence('plugins_load', 'system');
133 
134  // Boot plugin, setup languages and views
135  // Include start.php
136  // Call PluginBootstrap::boot()
137  $events->triggerSequence('plugins_boot', 'system');
138 
139  $config->_plugins_boot_complete = true;
140  $config->lock('_plugins_boot_complete');
141  }
142 
147  public function bootApplication() {
148  $config = $this->app->_services->config;
149 
150  if ($config->_application_boot_complete || !$this->app->_services->db) {
151  return;
152  }
153 
154  $events = $this->app->_services->events;
155 
156  $this->app->_services->views->clampViewtypeToPopulatedViews();
157  $this->app->allowPathRewrite();
158 
159  // Complete the boot process for both engine and plugins
160  $events->triggerSequence('init', 'system');
161 
162  $config->boot_complete = true;
163  $config->lock('boot_complete');
164 
165  // System loaded and ready
166  $events->triggerSequence('ready', 'system');
167 
168  $config->_application_boot_complete = true;
169  $config->lock('_application_boot_complete');
170  }
171 
176  public function setEntityClasses() {
177  elgg_set_entity_class('user', 'user', \ElggUser::class);
178  elgg_set_entity_class('group', 'group', \ElggGroup::class);
179  elgg_set_entity_class('site', 'site', \ElggSite::class);
180  elgg_set_entity_class('object', 'plugin', \ElggPlugin::class);
181  elgg_set_entity_class('object', 'file', \ElggFile::class);
182  elgg_set_entity_class('object', 'widget', \ElggWidget::class);
183  elgg_set_entity_class('object', 'comment', \ElggComment::class);
184  elgg_set_entity_class('object', 'elgg_upgrade', \ElggUpgrade::class);
185  }
186 }
elgg_views_boot()
Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades...
Definition: views.php:1753
__construct(Application $app)
Constructor.
Definition: BootHandler.php:25
bootServices()
Boot core services.
Definition: BootHandler.php:61
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
__invoke()
Full application boot Boots services, plugins and trigger init/ready events.
Definition: BootHandler.php:40
setEntityClasses()
Set core entity classes.
bootApplication()
Finish bootstrapping the application.
_elgg_input_init()
Initialize the input library.
Definition: input.php:385
elgg_set_entity_class($type, $subtype, $class="")
Sets class constructor name for entities with given type and subtype.
Definition: entities.php:39
Load, boot, and implement a front controller for an Elgg application.
Definition: Application.php:50
_elgg_nav_init()
Navigation initialization.
class
Definition: placeholder.php:21
_elgg_init()
Elgg&#39;s main init.
Definition: elgglib.php:1551
Handles application boot sequence.
Definition: BootHandler.php:13