bootstrap.php
12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 0.10.8
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
/*
* Configure paths required to find CakePHP + general filepath constants
*/
require __DIR__ . '/paths.php';
// ORIG
// Use composer to load the autoloader.
//require ROOT . DS . 'vendor' . DS . 'autoload.php';
/*
* Bootstrap CakePHP.
*
* Does the various bits of setup that CakePHP needs to do.
* This includes:
*
* - Registering the CakePHP autoloader.
* - Setting the default application paths.
*/
require CORE_PATH . 'config' . DS . 'bootstrap.php';
use Cake\Cache\Cache;
use Cake\Console\ConsoleErrorHandler;
// ORIG
//use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Database\Type;
use Cake\Datasource\ConnectionManager;
use Cake\Error\ErrorHandler;
use Cake\Http\ServerRequest;
use Cake\Log\Log;
use Cake\Mailer\Email;
use Cake\Mailer\TransportFactory;
// ORIG
//use Cake\Routing\DispatcherFactory;
use Cake\Utility\Inflector;
use Cake\Utility\Security;
// ORIG
use Cake\Core\Plugin;
/*
* https://github.com/guemidiborhane/yaml-config
*
* Installation :
* php composer.phar require chobo1210/yaml "dev-master"
*
* Utilisation, voir plus loin la ligne :
* Configure::config('yaml', new YamlConfig());
* ...
*/
use Yaml\Configure\Engine\YamlConfig;
/* EP 2021-11 : mes propres constantes */
define('CONFIG_MATERIEL_FIELDS_FILE_NAME', 'app_labinvent_mandatory_fields');
/*
* Uncomment block of code below if you want to use `.env` file during development.
* You should copy `config/.env.example` to `config/.env` and set/modify the
* variables as required.
*
* It is HIGHLY discouraged to use a .env file in production, due to security risks
* and decreased performance on each request. The purpose of the .env file is to emulate
* the presence of the environment variables like they would be present in production.
*/
// if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
// $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
// $dotenv->parse()
// ->putenv()
// ->toEnv()
// ->toServer();
// }
/*
* Read configuration file and inject configuration into various
* CakePHP classes.
*
* By default there is only one configuration file. It is often a good
* idea to create multiple configuration files, and separate the configuration
* that changes from configuration that does not. This makes deployment simpler.
*/
try {
Configure::config('default', new PhpConfig());
Configure::load('app', 'default', false);
} catch (\Exception $e) {
exit($e->getMessage() . "\n");
}
/*
* Load an environment local configuration file to provide overrides to your configuration.
* Notice: For security reasons app_local.php will not be included in your git repo.
*/
if (file_exists(CONFIG . 'app_local.php')) {
Configure::load('app_local', 'default');
}
/*
* When debug = true the metadata cache should only last
* for a short time.
*/
if (Configure::read('debug')) {
Configure::write('Cache._cake_model_.duration', '+2 minutes');
Configure::write('Cache._cake_core_.duration', '+2 minutes');
// disable router cache during development
Configure::write('Cache._cake_routes_.duration', '+2 seconds');
}
// ORIG
/*
// When debug = false the metadata cache should last
// for a very very long time, as we don't want
// to refresh the cache while users are doing requests.
if (!Configure::read('debug')) {
Configure::write('Cache._cake_model_.duration', '+1 years');
Configure::write('Cache._cake_core_.duration', '+1 years');
}
*/
# Affiche "true" si on est en mode test
# (cette constante est définie dans /tests/bootstrap.php)
//debug ( defined('_IN_TEST_MODE') );
// (EP 2021 09 Ajout nouveaux fichiers config pour les champs obligatoires (et les autorisations))
//$config_mandatory_fields_file_name = 'app_labinvent_mandatory_fields';
// Si le fichier de conf n'existe pas, on le crée en copiant le fichier par défaut
//if ( !file_exists(CONFIG.DS.$config_mandatory_fields_file_name.'.yml') )
//$config_matos_full_file_name = $config_matos_full_file_name_default = CONFIG.DS.CONFIG_MATERIEL_FIELDS_FILE_NAME;
$config_matos_file_name = $config_matos_file_name_default = CONFIG_MATERIEL_FIELDS_FILE_NAME;
//$config_matos_full_file_name_default = $config_matos_full_file_name;
if (defined('_IN_TEST_MODE')) $config_matos_file_name .= '_test';
//if ( !file_exists($config_matos_full_file_name) ) copy($config_matos_full_file_name_default, $config_matos_full_file_name);
try {
Configure::config('my_yaml_engine', new YamlConfig());
//Configure::load($config_mandatory_fields_file_name, 'yaml', true);
Configure::load($config_matos_file_name, 'my_yaml_engine');
//Configure::load(CONFIG_MATERIEL_FIELDS_FILE_NAME, 'my_yaml_engine');
//Configure::load('app_labinvent_mandatory_fields_IP2I', 'yaml');
//Configure::load('app_labinvent_authorizations', 'yaml');
} catch (\Exception $e) {
$config_matos_file_name .= '.yml';
$config_matos_file_name_default .= '.default.yml';
echo("<br>config/bootstrap.php: Impossible de charger le fichier de configuration des champs matériels (".CONFIG.DS.$config_matos_file_name.")");
echo("<br>- soit ce fichier n'est pas accessible en lecture par le serveur web (attention, il faut aussi qu'il soit accessible en écriture)");
echo("<br>- soit il n'existe pas => dans ce cas, créez le en faisant une copie du fichier de configuration par défaut :");
echo("<br> cd ".CONFIG);
echo("<br> cp $config_matos_file_name_default $config_matos_file_name");
echo("<br> chown webserver_user_name $config_matos_file_name");
echo("<br> chmod 600 $config_matos_file_name");
echo("<br> (si vous ne voulez pas faire le chown, faite plutot un chmod 666, moins propre, mais marche aussi)");
die();
}
/* Pour voir quelle config on lit (test ou prod ?)
$data = Configure::read('MANDATORY_AND_READONLY_FIELDS.MANDATORY_FIELDS_FOR_LOT2');
debug($data);
*/
/*
* Set the default server timezone. Using UTC makes time calculations / conversions easier.
* Check http://php.net/manual/en/timezones.php for list of valid timezone strings.
*/
date_default_timezone_set(Configure::read('App.defaultTimezone'));
//date_default_timezone_set('UTC'); // GMT+0
// ORIG
//date_default_timezone_set('Europe/Paris');
/*
* Configure the mbstring extension to use the correct encoding.
*/
mb_internal_encoding(Configure::read('App.encoding'));
/*
* Set the default locale. This controls how dates, number and currency is
* formatted and sets the default language to use for translations.
*/
ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
/*
* Register application error and exception handlers.
*/
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
(new ConsoleErrorHandler(Configure::read('Error')))->register();
} else {
(new ErrorHandler(Configure::read('Error')))->register();
}
/*
* Include the CLI bootstrap overrides.
*/
if ($isCli) {
require __DIR__ . '/bootstrap_cli.php';
}
/*
* Set the full base URL.
* This URL is used as the base of all absolute links.
*
* If you define fullBaseUrl in your config file you can remove this.
*/
if (!Configure::read('App.fullBaseUrl')) {
$s = null;
if (env('HTTPS')) {
$s = 's';
}
$httpHost = env('HTTP_HOST');
if (isset($httpHost)) {
Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
}
unset($httpHost, $s);
}
Cache::setConfig(Configure::consume('Cache'));
ConnectionManager::setConfig(Configure::consume('Datasources'));
TransportFactory::setConfig(Configure::consume('EmailTransport'));
Email::setConfig(Configure::consume('Email'));
Log::setConfig(Configure::consume('Log'));
Security::setSalt(Configure::consume('Security.salt'));
/*
* The default crypto extension in 3.0 is OpenSSL.
* If you are migrating from 2.x uncomment this code to
* use a more compatible Mcrypt based implementation
*/
//Security::engine(new \Cake\Utility\Crypto\Mcrypt());
/*
* Setup detectors for mobile and tablet.
*/
ServerRequest::addDetector('mobile', function ($request) {
$detector = new \Detection\MobileDetect();
return $detector->isMobile();
});
ServerRequest::addDetector('tablet', function ($request) {
$detector = new \Detection\MobileDetect();
return $detector->isTablet();
});
/**
* ORIG only
* Connect middleware/dispatcher filters.
*/
/*
DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
*/
/*
* Enable immutable time objects in the ORM.
*
* You can enable default locale format parsing by adding calls
* to `useLocaleParser()`. This enables the automatic conversion of
* locale specific date formats. For details see
* @link https://book.cakephp.org/3/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
*/
Type::build('time')
->useImmutable();
// ORIG
// ->useLocaleParser();
Type::build('date')
->useImmutable();
// ORIG
// ->useLocaleParser();
Type::build('datetime')
->useImmutable();
// ORIG
// ->useLocaleParser();
// 3.10 NEW
Type::build('timestamp')
->useImmutable();
/*
* Custom Inflector rules, can be set to correctly pluralize or singularize
* table, model, controller names or whatever other string is passed to the
* inflection functions.
*/
//Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
//Inflector::rules('irregular', ['red' => 'redlings']);
//Inflector::rules('uninflected', ['dontinflectme']);
//Inflector::rules('transliteration', ['/å/' => 'aa']);
// (EP) je sais pas trop comment faire ça...
Inflector::rules('irregular', ['SurCategory' => 'Domaine']);
Inflector::rules('irregular', ['SurCategories' => 'Domaines']);
/* ORIG only */
/* (EP)
* TODO:
* Depuis cakephp3.7 les plugins sont à mettre dans src/Application.php
* cf https://book.cakephp.org/3.0/en/migrations.html
*/
//Plugin::load('Migrations');
/* (EP)
* Pour générer du pdf (à la place de fpdf qui ne marche pas au CRAL)
*/
//Plugin::load('Dompdf');
/*
// DebugKit (cf https://book.cakephp.org/debugkit/3/fr/index.html)
// Only try to load DebugKit in development mode
// Debug Kit should not be installed on a production system
if (Configure::read('debug')) {
// Whitelister mes sites locaux :
Configure::write('DebugKit.safeTld', ['localhost', 'dev', 'invalid', 'test', 'example', 'local', 'devv']);
/S (EP 20200316 added pour éviter l'erreur suivante retrouvée dans logs/error.log :
* 2020-03-16 12:20:28 Warning: DebugKit is disabling itself as your host `labinvent.devv` is not in the known safe list of top-level-domains
* (localhost, invalid, test, example, local). If you would like to force DebugKit on
* use the `DebugKit.forceEnable` Configure option.
S/
//Configure::write('DebugKit.forceEnable', true);
// Autres options dispo :
//Configure::write('DebugKit.ignoreAuthorization', true);
//Configure::write('DebugKit.panels', ['DebugKit.Packages' => false]);
// Maintenant on peut charger DebugKit normalement
//Plugin::load('DebugKit', ['bootstrap' => true]);
Plugin::load('DebugKit', ['bootstrap' => true, 'routes' => true]);
}
*/
/*
* Bootstrap-ui (EP added 28/1/2020)
* https://github.com/FriendsOfCake/bootstrap-ui/tree/develop
*/
//Cake\Core\Plugin::load('BootstrapUI');
//Plugin::load('BootstrapUI');
//Plugin::load('BootstrapUI', ['autoload' => true]);
/* ORIG
// Activer Stats via src/Routing/Filter/SessionTimeoutFilter.php
$SessionTimeoutON = false;
//$SessionTimeoutON = true;
// (EP20201022) Pour gérer le timeout auto
if ($SessionTimeoutON)
DispatcherFactory::add('SessionTimeout');
*/