Elgg\Application::bootCore PHP Method

bootCore() public method

This method loads the full Elgg engine, checks the installation state, and triggers a series of events to finish booting Elgg: - {@elgg_event boot system} - {@elgg_event init system} - {@elgg_event ready system} If Elgg is not fully installed, the browser will be redirected to an installation page.
public bootCore ( ) : void
return void
    public function bootCore()
    {
        $config = $this->services->config;
        if ($this->isTestingApplication()) {
            throw new \RuntimeException('Unit tests should not call ' . __METHOD__);
        }
        if ($config->getVolatile('boot_complete')) {
            return;
        }
        $this->loadSettings();
        $config->set('boot_complete', false);
        // This will be overridden by the DB value but may be needed before the upgrade script can be run.
        $config->set('default_limit', 10);
        // in case not loaded already
        $this->loadCore();
        $events = $this->services->events;
        // Connect to database, load language files, load configuration, init session
        // Plugins can't use this event because they haven't been loaded yet.
        $events->trigger('boot', 'system');
        // Load the plugins that are active
        $this->services->plugins->load();
        $root = Directory\Local::root();
        if ($root->getPath() != self::elggDir()->getPath()) {
            // Elgg is installed as a composer dep, so try to treat the root directory
            // as a custom plugin that is always loaded last and can't be disabled...
            if (!elgg_get_config('system_cache_loaded')) {
                // configure view locations for the custom plugin (not Elgg core)
                $viewsFile = $root->getFile('views.php');
                if ($viewsFile->exists()) {
                    $viewsSpec = $viewsFile->includeFile();
                    if (is_array($viewsSpec)) {
                        _elgg_services()->views->mergeViewsSpec($viewsSpec);
                    }
                }
                // find views for the custom plugin (not Elgg core)
                _elgg_services()->views->registerPluginViews($root->getPath());
            }
            if (!elgg_get_config('i18n_loaded_from_cache')) {
                _elgg_services()->translator->registerPluginTranslations($root->getPath());
            }
            // This is root directory start.php
            $root_start = $root->getPath("start.php");
            if (is_file($root_start)) {
                require $root_start;
            }
        }
        // @todo move loading plugins into a single boot function that replaces 'boot', 'system' event
        // and then move this code in there.
        // This validates the view type - first opportunity to do it is after plugins load.
        $viewtype = elgg_get_viewtype();
        if (!elgg_is_registered_viewtype($viewtype)) {
            elgg_set_viewtype('default');
        }
        $this->allowPathRewrite();
        // Allows registering handlers strictly before all init, system handlers
        $events->trigger('plugins_boot', 'system');
        // Complete the boot process for both engine and plugins
        $events->trigger('init', 'system');
        $config->set('boot_complete', true);
        // System loaded and ready
        $events->trigger('ready', 'system');
    }

Usage Example

Example #1
0
 /**
  * Handle a request for a cached view
  *
  * @param array $path URL path
  * @return void
  */
 public function handleRequest($path)
 {
     $config = $this->config;
     $request = $this->parsePath($path);
     if (!$request) {
         $this->send403();
     }
     $ts = $request['ts'];
     $view = $request['view'];
     $viewtype = $request['viewtype'];
     $contentType = $this->getContentType($view);
     if (!empty($contentType)) {
         header("Content-Type: {$contentType}", true);
     }
     // this may/may not have to connect to the DB
     $this->setupSimplecache();
     // we can't use $config->get yet. It fails before the core is booted
     if (!$config->getVolatile('simplecache_enabled')) {
         $this->application->bootCore();
         if (!\_elgg_is_view_cacheable($view)) {
             $this->send403();
         } else {
             echo $this->renderView($view, $viewtype);
         }
         exit;
     }
     $etag = "\"{$ts}\"";
     // If is the same ETag, content didn't change.
     if (isset($this->server_vars['HTTP_IF_NONE_MATCH']) && trim($this->server_vars['HTTP_IF_NONE_MATCH']) === $etag) {
         header("HTTP/1.1 304 Not Modified");
         exit;
     }
     $filename = $config->getVolatile('dataroot') . 'views_simplecache/' . md5("{$viewtype}|{$view}");
     if (file_exists($filename)) {
         $this->sendCacheHeaders($etag);
         readfile($filename);
         exit;
     }
     $this->application->bootCore();
     elgg_set_viewtype($viewtype);
     if (!\_elgg_is_view_cacheable($view)) {
         $this->send403();
     }
     $cache_timestamp = (int) $config->get('lastcache');
     if ($cache_timestamp == $ts) {
         $this->sendCacheHeaders($etag);
         $content = $this->getProcessedView($view, $viewtype);
         $dir_name = $config->getDataPath() . 'views_simplecache/';
         if (!is_dir($dir_name)) {
             mkdir($dir_name, 0700);
         }
         file_put_contents($filename, $content);
     } else {
         // if wrong timestamp, don't send HTTP cache
         $content = $this->renderView($view, $viewtype);
     }
     echo $content;
     exit;
 }
All Usage Examples Of Elgg\Application::bootCore