SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/core/Bootstrap.php

Kohana process control file, loaded by the front controller.

$Id: Bootstrap.php 4409 2009-06-06 00:48:26Z zombor $
  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. /**
  15.  * Kohana process control file, loaded by the front controller.
  16.  *
  17.  * $Id: Bootstrap.php 4409 2009-06-06 00:48:26Z zombor $
  18.  *
  19.  * @package Core
  20.  * @author Kohana Team
  21.  * @copyright (c) 2007 Kohana Team
  22.  * @license http://kohanaphp.com/license.html
  23.  */
  24.  
  25. use Sprout\Helpers\Notification;
  26. use Sprout\Helpers\PageRouting;
  27. use Sprout\Helpers\Router;
  28. use Sprout\Helpers\Ssl;
  29. use Sprout\Helpers\SubsiteSelector;
  30. use Sprout\Helpers\Sprout;
  31. use Sprout\Helpers\Url;
  32.  
  33. // Register autoloader.
  34. require DOCROOT . 'vendor/autoload.php';
  35.  
  36. // Load core files
  37. require APPPATH . 'core/utf8.php';
  38. require APPPATH . 'core/Event.php';
  39. require APPPATH . 'core/Kohana.php';
  40.  
  41.  
  42. // Protect against XXE attacks by disallowing external entities to be loaded
  43. // See also https://en.wikipedia.org/wiki/XML_external_entity_attack
  44. // PHP-8+ deprecated this because it's disabled by default.
  45. if (PHP_VERSION_ID < 80000) {
  46. libxml_disable_entity_loader(true);
  47. }
  48.  
  49. // Prepare the environment (inc. error/exception handling, output buffering, and auto-loader)
  50. Kohana::setup();
  51.  
  52. // Determine the URI (stored in Router::$current_uri)
  53. Router::findUri();
  54.  
  55. // Redirect to alternate hostname and/or protocol if requred
  56. Router::originCleanup();
  57.  
  58. // Mini verion of framework when using the welcome system
  59. // that avoids lots of code paths which use a database.
  60. if (Sprout::moduleInstalled('Welcome')) {
  61. Kohana::disableCache();
  62. if (Router::$current_uri === '' or strpos(Router::$current_uri, 'welcome/') === 0) {
  63. Router::setup();
  64. Kohana::instance();
  65. Event::run('system.shutdown');
  66. exit(1);
  67. }
  68. } else {
  69. // If the user has just finished setting up
  70. if (strpos(Router::$current_uri, 'welcome/checklist') === 0) {
  71. Notification::error('Welcome-Module not enabled! Enable it via <a href="http://docs.getsproutcms.com/installation">config file</a>.', 'html');
  72. Notification::confirm('Or please log in to admin area using the form below.');
  73. Url::redirect('admin/');
  74. }
  75. }
  76.  
  77. // Choose the subsite to use, based on domain, directory, mobile etc.
  78. SubsiteSelector::selectSubsite();
  79.  
  80. // Any redirects etc before the Kohana URLs
  81. require APPPATH . '/sprout_load.php';
  82. PageRouting::prerouting();
  83.  
  84. // Kohana routes and controller/method URLs
  85. // Key vars are Router::$controller and Router::$method
  86. Router::setup();
  87.  
  88. // Postrouting such as page URLs
  89. PageRouting::postrouting();
  90.  
  91. // Check if this controller requires SSL
  92. Ssl::check();
  93.  
  94. // 404?
  95. if (Router::$controller === NULL) {
  96. Event::run('system.404');
  97. }
  98.  
  99. // Run the method
  100. Kohana::instance();
  101.  
  102. // Clean up and exit
  103. Event::run('system.shutdown');
  104.  
  105.