bootstrap.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 0.10.8
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. /*
  17. * Configure paths required to find CakePHP + general filepath constants
  18. */
  19. require __DIR__ . DIRECTORY_SEPARATOR . 'paths.php';
  20. /*
  21. * Bootstrap CakePHP.
  22. *
  23. * Does the various bits of setup that CakePHP needs to do.
  24. * This includes:
  25. *
  26. * - Registering the CakePHP autoloader.
  27. * - Setting the default application paths.
  28. */
  29. require CORE_PATH . 'config' . DS . 'bootstrap.php';
  30. use Cake\Cache\Cache;
  31. use Cake\Core\Configure;
  32. use Cake\Core\Configure\Engine\PhpConfig;
  33. use Cake\Database\Type\StringType;
  34. use Cake\Database\TypeFactory;
  35. use Cake\Datasource\ConnectionManager;
  36. use Cake\Error\ErrorTrap;
  37. use Cake\Error\ExceptionTrap;
  38. use Cake\Http\ServerRequest;
  39. use Cake\Log\Log;
  40. use Cake\Mailer\Mailer;
  41. use Cake\Mailer\TransportFactory;
  42. use Cake\Routing\Router;
  43. use Cake\Utility\Security;
  44. /**
  45. * Load global functions.
  46. */
  47. require CAKE . 'functions.php';
  48. /*
  49. * See https://github.com/josegonzalez/php-dotenv for API details.
  50. *
  51. * Uncomment block of code below if you want to use `.env` file during development.
  52. * You should copy `config/.env.example` to `config/.env` and set/modify the
  53. * variables as required.
  54. *
  55. * The purpose of the .env file is to emulate the presence of the environment
  56. * variables like they would be present in production.
  57. *
  58. * If you use .env files, be careful to not commit them to source control to avoid
  59. * security risks. See https://github.com/josegonzalez/php-dotenv#general-security-information
  60. * for more information for recommended practices.
  61. */
  62. // if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
  63. // $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
  64. // $dotenv->parse()
  65. // ->putenv()
  66. // ->toEnv()
  67. // ->toServer();
  68. // }
  69. /*
  70. * Read configuration file and inject configuration into various
  71. * CakePHP classes.
  72. *
  73. * By default there is only one configuration file. It is often a good
  74. * idea to create multiple configuration files, and separate the configuration
  75. * that changes from configuration that does not. This makes deployment simpler.
  76. */
  77. try {
  78. Configure::config('default', new PhpConfig());
  79. Configure::load('app', 'default', false);
  80. } catch (\Exception $e) {
  81. exit($e->getMessage() . "\n");
  82. }
  83. /*
  84. * Load an environment local configuration file to provide overrides to your configuration.
  85. * Notice: For security reasons app_local.php **should not** be included in your git repo.
  86. */
  87. if (file_exists(CONFIG . 'app_local.php')) {
  88. Configure::load('app_local', 'default');
  89. }
  90. /*
  91. * When debug = true the metadata cache should only last
  92. * for a short time.
  93. */
  94. if (Configure::read('debug')) {
  95. Configure::write('Cache._cake_model_.duration', '+2 minutes');
  96. Configure::write('Cache._cake_core_.duration', '+2 minutes');
  97. // disable router cache during development
  98. Configure::write('Cache._cake_routes_.duration', '+2 seconds');
  99. }
  100. /*
  101. * Set the default server timezone. Using UTC makes time calculations / conversions easier.
  102. * Check https://php.net/manual/en/timezones.php for list of valid timezone strings.
  103. */
  104. date_default_timezone_set(Configure::read('App.defaultTimezone'));
  105. /*
  106. * Configure the mbstring extension to use the correct encoding.
  107. */
  108. mb_internal_encoding(Configure::read('App.encoding'));
  109. /*
  110. * Set the default locale. This controls how dates, number and currency is
  111. * formatted and sets the default language to use for translations.
  112. */
  113. ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
  114. /*
  115. * Register application error and exception handlers.
  116. */
  117. (new ErrorTrap(Configure::read('Error')))->register();
  118. (new ExceptionTrap(Configure::read('Error')))->register();
  119. /*
  120. * Include the CLI bootstrap overrides.
  121. */
  122. if (PHP_SAPI === 'cli') {
  123. require CONFIG . 'bootstrap_cli.php';
  124. }
  125. /*
  126. * Set the full base URL.
  127. * This URL is used as the base of all absolute links.
  128. */
  129. $fullBaseUrl = Configure::read('App.fullBaseUrl');
  130. if (!$fullBaseUrl) {
  131. /*
  132. * When using proxies or load balancers, SSL/TLS connections might
  133. * get terminated before reaching the server. If you trust the proxy,
  134. * you can enable `$trustProxy` to rely on the `X-Forwarded-Proto`
  135. * header to determine whether to generate URLs using `https`.
  136. *
  137. * See also https://book.cakephp.org/4/en/controllers/request-response.html#trusting-proxy-headers
  138. */
  139. $trustProxy = false;
  140. $s = null;
  141. if (env('HTTPS') || ($trustProxy && env('HTTP_X_FORWARDED_PROTO') === 'https')) {
  142. $s = 's';
  143. }
  144. $httpHost = env('HTTP_HOST');
  145. if (isset($httpHost)) {
  146. $fullBaseUrl = 'http' . $s . '://' . $httpHost;
  147. }
  148. unset($httpHost, $s);
  149. }
  150. if ($fullBaseUrl) {
  151. Router::fullBaseUrl($fullBaseUrl);
  152. }
  153. unset($fullBaseUrl);
  154. Cache::setConfig(Configure::consume('Cache'));
  155. ConnectionManager::setConfig(Configure::consume('Datasources'));
  156. TransportFactory::setConfig(Configure::consume('EmailTransport'));
  157. Mailer::setConfig(Configure::consume('Email'));
  158. Log::setConfig(Configure::consume('Log'));
  159. Security::setSalt(Configure::consume('Security.salt'));
  160. /*
  161. * Setup detectors for mobile and tablet.
  162. * If you don't use these checks you can safely remove this code
  163. * and the mobiledetect package from composer.json.
  164. */
  165. ServerRequest::addDetector('mobile', function ($request) {
  166. $detector = new \Detection\MobileDetect();
  167. return $detector->isMobile();
  168. });
  169. ServerRequest::addDetector('tablet', function ($request) {
  170. $detector = new \Detection\MobileDetect();
  171. return $detector->isTablet();
  172. });
  173. /*
  174. * You can enable default locale format parsing by adding calls
  175. * to `useLocaleParser()`. This enables the automatic conversion of
  176. * locale specific date formats. For details see
  177. * @link https://book.cakephp.org/4/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
  178. */
  179. // \Cake\Database\TypeFactory::build('time')
  180. // ->useLocaleParser();
  181. // \Cake\Database\TypeFactory::build('date')
  182. // ->useLocaleParser();
  183. // \Cake\Database\TypeFactory::build('datetime')
  184. // ->useLocaleParser();
  185. // \Cake\Database\TypeFactory::build('timestamp')
  186. // ->useLocaleParser();
  187. // \Cake\Database\TypeFactory::build('datetimefractional')
  188. // ->useLocaleParser();
  189. // \Cake\Database\TypeFactory::build('timestampfractional')
  190. // ->useLocaleParser();
  191. // \Cake\Database\TypeFactory::build('datetimetimezone')
  192. // ->useLocaleParser();
  193. // \Cake\Database\TypeFactory::build('timestamptimezone')
  194. // ->useLocaleParser();
  195. /*
  196. * Custom Inflector rules, can be set to correctly pluralize or singularize
  197. * table, model, controller names or whatever other string is passed to the
  198. * inflection functions.
  199. */
  200. //Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
  201. //Inflector::rules('irregular', ['red' => 'redlings']);
  202. //Inflector::rules('uninflected', ['dontinflectme']);
  203. // set a custom date and time format
  204. // see https://book.cakephp.org/4/en/core-libraries/time.html#setting-the-default-locale-and-format-string
  205. // and https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax
  206. //\Cake\I18n\FrozenDate::setToStringFormat('dd.MM.yyyy');
  207. //\Cake\I18n\FrozenTime::setToStringFormat('dd.MM.yyyy HH:mm');