3 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
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.
10 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11 * @link http://cakephp.org CakePHP(tm) Project
13 * @license http://www.opensource.org/licenses/mit-license.php MIT License
16 // You can remove this if you are confident that your PHP version is sufficient.
17 if (version_compare(PHP_VERSION, '5.6.0') < 0) {
18 trigger_error('Your PHP version must be equal or higher than 5.6.0 to use CakePHP.', E_USER_ERROR);
22 * You can remove this if you are confident you have intl installed.
24 if (!extension_loaded('intl')) {
25 trigger_error('You must enable the intl extension to use CakePHP.', E_USER_ERROR);
29 * You can remove this if you are confident you have mbstring installed.
31 if (!extension_loaded('mbstring')) {
32 trigger_error('You must enable the mbstring extension to use CakePHP.', E_USER_ERROR);
36 * Configure paths required to find CakePHP + general filepath
39 require __DIR__ . '/paths.php';
44 * Does the various bits of setup that CakePHP needs to do.
47 * - Registering the CakePHP autoloader.
48 * - Setting the default application paths.
50 require CORE_PATH . 'config' . DS . 'bootstrap.php';
53 use Cake\Console\ConsoleErrorHandler;
55 use Cake\Core\Configure;
56 use Cake\Core\Configure\Engine\PhpConfig;
58 use Cake\Database\Type;
59 use Cake\Datasource\ConnectionManager;
60 use Cake\Error\ErrorHandler;
62 use Cake\Mailer\Email;
63 use Cake\Network\Request;
64 use Cake\Utility\Inflector;
65 use Cake\Utility\Security;
68 * Read configuration file and inject configuration into various
71 * By default there is only one configuration file. It is often a good
72 * idea to create multiple configuration files, and separate the configuration
73 * that changes from configuration that does not. This makes deployment simpler.
76 Configure::config('default', new PhpConfig());
77 Configure::load('app', 'default', false);
78 } catch (\Exception $e) {
79 exit($e->getMessage() . "\n");
83 * Load an environment local configuration file.
84 * You can use a file like app_local.php to provide local overrides to your
85 * shared configuration.
87 //Configure::load('app_local', 'default');
90 * When debug = true the metadata cache should only last
93 if (Configure::read('debug')) {
94 Configure::write('Cache._cake_model_.duration', '+2 minutes');
95 Configure::write('Cache._cake_core_.duration', '+2 minutes');
99 * Set server timezone to UTC. You can change it to another timezone of your
100 * choice but using UTC makes time calculations / conversions easier.
102 date_default_timezone_set('UTC');
105 * Configure the mbstring extension to use the correct encoding.
107 mb_internal_encoding(Configure::read('App.encoding'));
110 * Set the default locale. This controls how dates, number and currency is
111 * formatted and sets the default language to use for translations.
113 ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
116 * Register application error and exception handlers.
118 $isCli = PHP_SAPI === 'cli';
120 (new ConsoleErrorHandler(Configure::read('Error')))->register();
122 (new ErrorHandler(Configure::read('Error')))->register();
126 * Include the CLI bootstrap overrides.
129 require __DIR__ . '/bootstrap_cli.php';
133 * Set the full base URL.
134 * This URL is used as the base of all absolute links.
136 * If you define fullBaseUrl in your config file you can remove this.
138 if (!Configure::read('App.fullBaseUrl')) {
144 $httpHost = env('HTTP_HOST');
145 if (isset($httpHost)) {
146 Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
148 unset($httpHost, $s);
151 Cache::setConfig(Configure::consume('Cache'));
152 ConnectionManager::setConfig(Configure::consume('Datasources'));
153 Email::setConfigTransport(Configure::consume('EmailTransport'));
154 Email::setConfig(Configure::consume('Email'));
155 Log::setConfig(Configure::consume('Log'));
156 Security::salt(Configure::consume('Security.salt'));
159 * The default crypto extension in 3.0 is OpenSSL.
160 * If you are migrating from 2.x uncomment this code to
161 * use a more compatible Mcrypt based implementation
163 //Security::engine(new \Cake\Utility\Crypto\Mcrypt());
166 * Setup detectors for mobile and tablet.
168 Request::addDetector('mobile', function ($request) {
169 $detector = new \Detection\MobileDetect();
171 return $detector->isMobile();
173 Request::addDetector('tablet', function ($request) {
174 $detector = new \Detection\MobileDetect();
176 return $detector->isTablet();
180 * Enable immutable time objects in the ORM.
182 * You can enable default locale format parsing by adding calls
183 * to `useLocaleParser()`. This enables the automatic conversion of
184 * locale specific date formats. For details see
185 * @link http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
191 Type::build('datetime')
193 Type::build('timestamp')
197 * Custom Inflector rules, can be set to correctly pluralize or singularize
198 * table, model, controller names or whatever other string is passed to the
199 * inflection functions.
201 //Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
202 //Inflector::rules('irregular', ['red' => 'redlings']);
203 //Inflector::rules('uninflected', ['dontinflectme']);
204 //Inflector::rules('transliteration', ['/å/' => 'aa']);
207 * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
208 * Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more
209 * advanced ways of loading plugins
211 * Plugin::loadAll(); // Loads all plugins at once
212 * Plugin::load('Migrations'); //Loads a single plugin named Migrations
217 * Only try to load DebugKit in development mode
218 * Debug Kit should not be installed on a production system
220 if (Configure::read('debug')) {
221 Plugin::load('DebugKit', ['bootstrap' => true]);
224 // added for cache key construction from array using table model.
225 // hmmm: could go into a trait or some other reusable asset?
226 function bootMultiImplode($glue, $pieces) {
228 if (is_array ( $pieces )) {
230 while ( list ( $key, $value ) = each ( $pieces ) ) {
231 if (is_numeric ( $key )) {
232 $string .= $glue . bootMultiImplode ( $glue, $value );
234 // add string keys to string
235 $string .= $glue . $key . $glue . bootMultiImplode ( $glue, $value );
243 return trim($string, $glue);