bootstrap.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 0.10.8
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. /*
  16. * Configure paths required to find CakePHP + general filepath constants
  17. */
  18. require __DIR__ . '/paths.php';
  19. /*
  20. * Bootstrap CakePHP.
  21. *
  22. * Does the various bits of setup that CakePHP needs to do.
  23. * This includes:
  24. *
  25. * - Registering the CakePHP autoloader.
  26. * - Setting the default application paths.
  27. */
  28. require CORE_PATH . 'config' . DS . 'bootstrap.php';
  29. use Cake\Cache\Cache;
  30. use Cake\Console\ConsoleErrorHandler;
  31. use Cake\Core\Configure;
  32. use Cake\Core\Configure\Engine\PhpConfig;
  33. use Cake\Core\Plugin;
  34. use Cake\Database\Type;
  35. use Cake\Datasource\ConnectionManager;
  36. use Cake\Error\ErrorHandler;
  37. use Cake\Http\ServerRequest;
  38. use Cake\Log\Log;
  39. use Cake\Mailer\Mailer;
  40. use Cake\Mailer\TransportFactory;
  41. use Cake\Utility\Inflector;
  42. use Cake\Utility\Security;
  43. /**
  44. * Uncomment block of code below if you want to use `.env` file during development.
  45. * You should copy `config/.env.default to `config/.env` and set/modify the
  46. * variables as required.
  47. *
  48. * It is HIGHLY discouraged to use a .env file in production, due to security risks
  49. * and decreased performance on each request. The purpose of the .env file is to emulate
  50. * the presence of the environment variables like they would be present in production.
  51. */
  52. // if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
  53. // $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
  54. // $dotenv->parse()
  55. // ->putenv()
  56. // ->toEnv()
  57. // ->toServer();
  58. // }
  59. /*
  60. * Read configuration file and inject configuration into various
  61. * CakePHP classes.
  62. *
  63. * By default there is only one configuration file. It is often a good
  64. * idea to create multiple configuration files, and separate the configuration
  65. * that changes from configuration that does not. This makes deployment simpler.
  66. */
  67. try {
  68. Configure::config('default', new PhpConfig());
  69. Configure::load('app', 'default', false);
  70. } catch (\Exception $e) {
  71. exit($e->getMessage() . "\n");
  72. }
  73. /*
  74. * Load an environment local configuration file.
  75. * You can use a file like app_local.php to provide local overrides to your
  76. * shared configuration.
  77. */
  78. //Configure::load('app_local', 'default');
  79. /*
  80. * When debug = true the metadata cache should only last
  81. * for a short time.
  82. */
  83. if (Configure::read('debug')) {
  84. Configure::write('Cache._cake_model_.duration', '+2 minutes');
  85. Configure::write('Cache._cake_core_.duration', '+2 minutes');
  86. // disable router cache during development
  87. Configure::write('Cache._cake_routes_.duration', '+2 seconds');
  88. }
  89. /*
  90. * Set the default server timezone. Using UTC makes time calculations / conversions easier.
  91. * Check http://php.net/manual/en/timezones.php for list of valid timezone strings.
  92. */
  93. date_default_timezone_set(Configure::read('App.defaultTimezone'));
  94. /*
  95. * Configure the mbstring extension to use the correct encoding.
  96. */
  97. mb_internal_encoding(Configure::read('App.encoding'));
  98. /*
  99. * Set the default locale. This controls how dates, number and currency is
  100. * formatted and sets the default language to use for translations.
  101. */
  102. ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
  103. /*
  104. * Register application error and exception handlers.
  105. */
  106. $isCli = PHP_SAPI === 'cli';
  107. if ($isCli) {
  108. (new ConsoleErrorHandler(Configure::read('Error')))->register();
  109. } else {
  110. (new ErrorHandler(Configure::read('Error')))->register();
  111. }
  112. /*
  113. * Include the CLI bootstrap overrides.
  114. */
  115. if ($isCli) {
  116. require __DIR__ . '/bootstrap_cli.php';
  117. }
  118. /*
  119. * Set the full base URL.
  120. * This URL is used as the base of all absolute links.
  121. *
  122. * If you define fullBaseUrl in your config file you can remove this.
  123. */
  124. $fullBaseUrl = Configure::read('App.fullBaseUrl');
  125. if (!$fullBaseUrl) {
  126. $s = null;
  127. if (env('HTTPS')) {
  128. $s = 's';
  129. }
  130. $httpHost = env('HTTP_HOST');
  131. if (isset($httpHost)) {
  132. Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
  133. }
  134. unset($httpHost, $s);
  135. }
  136. if ($fullBaseUrl) {
  137. Router::fullBaseUrl($fullBaseUrl);
  138. }
  139. unset($fullBaseUrl);
  140. Cache::setConfig(Configure::consume('Cache'));
  141. ConnectionManager::setConfig(Configure::consume('Datasources'));
  142. TransportFactory::setConfig(Configure::consume('EmailTransport'));
  143. Mailer::setConfig(Configure::consume('Email'));
  144. Log::setConfig(Configure::consume('Log'));
  145. Security::setSalt(Configure::consume('Security.salt'));
  146. /*
  147. * You can set whether the ORM uses immutable or mutable Time types.
  148. * The default changed in 4.0 to immutable types. You can uncomment
  149. * below to switch back to mutable types.
  150. *
  151. * You can enable default locale format parsing by adding calls
  152. * to `useLocaleParser()`. This enables the automatic conversion of
  153. * locale specific date formats. For details see
  154. * @link https://book.cakephp.org/4/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
  155. */
  156. // TypeFactory::build('time')
  157. // ->useMutable();
  158. // TypeFactory::build('date')
  159. // ->useMutable();
  160. // TypeFactory::build('datetime')
  161. // ->useMutable();
  162. // TypeFactory::build('timestamp')
  163. // ->useMutable();
  164. // TypeFactory::build('datetimefractional')
  165. // ->useMutable();
  166. // TypeFactory::build('timestampfractional')
  167. // ->useMutable();
  168. // TypeFactory::build('datetimetimezone')
  169. // ->useMutable();
  170. // TypeFactory::build('timestamptimezone')
  171. // ->useMutable();
  172. /*
  173. * Custom Inflector rules, can be set to correctly pluralize or singularize
  174. * table, model, controller names or whatever other string is passed to the
  175. * inflection functions.
  176. */
  177. //Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
  178. //Inflector::rules('irregular', ['red' => 'redlings']);
  179. //Inflector::rules('uninflected', ['dontinflectme']);
  180. //Inflector::rules('transliteration', ['/å/' => 'aa']);