bootstrap.php 6.1 KB

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