Merge branch 'master' of feistymeow.org:feisty_meow
[feisty_meow.git] / production / example_apps / shared_calendar / config / bootstrap.php
1 <?php
2 /**
3  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4  * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
11  * @link          http://cakephp.org CakePHP(tm) Project
12  * @since         0.10.8
13  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
14  */
15
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);
19 }
20
21 /*
22  *  You can remove this if you are confident you have intl installed.
23  */
24 if (!extension_loaded('intl')) {
25     trigger_error('You must enable the intl extension to use CakePHP.', E_USER_ERROR);
26 }
27
28 /*
29  * You can remove this if you are confident you have mbstring installed.
30  */
31 if (!extension_loaded('mbstring')) {
32     trigger_error('You must enable the mbstring extension to use CakePHP.', E_USER_ERROR);
33 }
34
35 /*
36  * Configure paths required to find CakePHP + general filepath
37  * constants
38  */
39 require __DIR__ . '/paths.php';
40
41 /*
42  * Bootstrap CakePHP.
43  *
44  * Does the various bits of setup that CakePHP needs to do.
45  * This includes:
46  *
47  * - Registering the CakePHP autoloader.
48  * - Setting the default application paths.
49  */
50 require CORE_PATH . 'config' . DS . 'bootstrap.php';
51
52 use Cake\Cache\Cache;
53 use Cake\Console\ConsoleErrorHandler;
54 use Cake\Core\App;
55 use Cake\Core\Configure;
56 use Cake\Core\Configure\Engine\PhpConfig;
57 use Cake\Core\Plugin;
58 use Cake\Database\Type;
59 use Cake\Datasource\ConnectionManager;
60 use Cake\Error\ErrorHandler;
61 use Cake\Log\Log;
62 use Cake\Mailer\Email;
63 use Cake\Network\Request;
64 use Cake\Utility\Inflector;
65 use Cake\Utility\Security;
66
67 /*
68  * Read configuration file and inject configuration into various
69  * CakePHP classes.
70  *
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.
74  */
75 try {
76     Configure::config('default', new PhpConfig());
77     Configure::load('app', 'default', false);
78 } catch (\Exception $e) {
79     exit($e->getMessage() . "\n");
80 }
81
82 /*
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.
86  */
87 //Configure::load('app_local', 'default');
88
89 /*
90  * When debug = true the metadata cache should only last
91  * for a short time.
92  */
93 if (Configure::read('debug')) {
94     Configure::write('Cache._cake_model_.duration', '+2 minutes');
95     Configure::write('Cache._cake_core_.duration', '+2 minutes');
96 }
97
98 /*
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.
101  */
102 date_default_timezone_set('UTC');
103
104 /*
105  * Configure the mbstring extension to use the correct encoding.
106  */
107 mb_internal_encoding(Configure::read('App.encoding'));
108
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 /*
116  * Register application error and exception handlers.
117  */
118 $isCli = PHP_SAPI === 'cli';
119 if ($isCli) {
120     (new ConsoleErrorHandler(Configure::read('Error')))->register();
121 } else {
122     (new ErrorHandler(Configure::read('Error')))->register();
123 }
124
125 /*
126  * Include the CLI bootstrap overrides.
127  */
128 if ($isCli) {
129     require __DIR__ . '/bootstrap_cli.php';
130 }
131
132 /*
133  * Set the full base URL.
134  * This URL is used as the base of all absolute links.
135  *
136  * If you define fullBaseUrl in your config file you can remove this.
137  */
138 if (!Configure::read('App.fullBaseUrl')) {
139     $s = null;
140     if (env('HTTPS')) {
141         $s = 's';
142     }
143
144     $httpHost = env('HTTP_HOST');
145     if (isset($httpHost)) {
146         Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
147     }
148     unset($httpHost, $s);
149 }
150
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'));
157
158 /*
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
162  */
163 //Security::engine(new \Cake\Utility\Crypto\Mcrypt());
164
165 /*
166  * Setup detectors for mobile and tablet.
167  */
168 Request::addDetector('mobile', function ($request) {
169     $detector = new \Detection\MobileDetect();
170
171     return $detector->isMobile();
172 });
173 Request::addDetector('tablet', function ($request) {
174     $detector = new \Detection\MobileDetect();
175
176     return $detector->isTablet();
177 });
178
179 /*
180  * Enable immutable time objects in the ORM.
181  *
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
186  */
187 Type::build('time')
188     ->useImmutable();
189 Type::build('date')
190     ->useImmutable();
191 Type::build('datetime')
192     ->useImmutable();
193 Type::build('timestamp')
194     ->useImmutable();
195
196 /*
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.
200  */
201 //Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
202 //Inflector::rules('irregular', ['red' => 'redlings']);
203 //Inflector::rules('uninflected', ['dontinflectme']);
204 //Inflector::rules('transliteration', ['/å/' => 'aa']);
205
206 /*
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
210  *
211  * Plugin::loadAll(); // Loads all plugins at once
212  * Plugin::load('Migrations'); //Loads a single plugin named Migrations
213  *
214  */
215
216 /*
217  * Only try to load DebugKit in development mode
218  * Debug Kit should not be installed on a production system
219  */
220 if (Configure::read('debug')) {
221     Plugin::load('DebugKit', ['bootstrap' => true]);
222 }
223
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) {
227         $string = '';
228         if (is_array ( $pieces )) {
229                 reset ( $pieces );
230                 while ( list ( $key, $value ) = each ( $pieces ) ) {
231                         if (is_numeric ( $key )) {
232                                 $string .= $glue . bootMultiImplode ( $glue, $value );
233                         } else {
234                                 // add string keys to string
235                                 $string .= $glue . $key . $glue . bootMultiImplode ( $glue, $value );
236                         }
237                 }
238         } else {
239                 
240                 return $pieces;
241         }
242         
243         return trim($string, $glue);
244 }