Skip to content

Commit 2011746

Browse files
authored
Merge pull request #1029 from cakephp/5.x-bootstrap
improve bootstrap docs
2 parents 6b774dc + cad7cb3 commit 2011746

File tree

2 files changed

+46
-75
lines changed

2 files changed

+46
-75
lines changed

config/bootstrap.php

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
* @license https://opensource.org/licenses/mit-license.php MIT License
1616
*/
1717

18+
/*
19+
* This file is loaded by your src/Application.php bootstrap method.
20+
* Feel free to extend/extract parts of the bootstrap process into your own files
21+
* to suit your needs/preferences.
22+
*/
23+
1824
/*
1925
* Configure paths required to find CakePHP + general filepath constants
2026
*/
2127
require __DIR__ . DIRECTORY_SEPARATOR . 'paths.php';
2228

2329
/*
24-
* Bootstrap CakePHP.
25-
*
26-
* Does the various bits of setup that CakePHP needs to do.
27-
* This includes:
28-
*
29-
* - Registering the CakePHP autoloader.
30-
* - Setting the default application paths.
30+
* Bootstrap CakePHP
31+
* Currently all this does is initialize the router (without loading your routes)
3132
*/
3233
require CORE_PATH . 'config' . DS . 'bootstrap.php';
3334

@@ -44,8 +45,8 @@
4445
use Cake\Routing\Router;
4546
use Cake\Utility\Security;
4647

47-
/**
48-
* Load global functions.
48+
/*
49+
* Load global functions for collections, translations, debugging etc.
4950
*/
5051
require CAKE . 'functions.php';
5152

@@ -72,12 +73,11 @@
7273
// }
7374

7475
/*
75-
* Read configuration file and inject configuration into various
76-
* CakePHP classes.
76+
* Initializes default Config store and loads the main configuration file (app.php)
7777
*
78-
* By default there is only one configuration file. It is often a good
79-
* idea to create multiple configuration files, and separate the configuration
80-
* that changes from configuration that does not. This makes deployment simpler.
78+
* CakePHP contains 2 configuration files after project creation:
79+
* - `config/app.php` for the default application configuration.
80+
* - `config/app_local.php` for environment specific configuration.
8181
*/
8282
try {
8383
Configure::config('default', new PhpConfig());
@@ -95,8 +95,7 @@
9595
}
9696

9797
/*
98-
* When debug = true the metadata cache should only last
99-
* for a short time.
98+
* When debug = true the metadata cache should only last for a short time.
10099
*/
101100
if (Configure::read('debug')) {
102101
Configure::write('Cache._cake_model_.duration', '+2 minutes');
@@ -127,15 +126,26 @@
127126
(new ExceptionTrap(Configure::read('Error')))->register();
128127

129128
/*
130-
* Include the CLI bootstrap overrides.
129+
* CLI/Command specific configuration.
131130
*/
132131
if (PHP_SAPI === 'cli') {
133-
require CONFIG . 'bootstrap_cli.php';
132+
// Set the fullBaseUrl to allow URLs to be generated in commands.
133+
// This is useful when sending email from commands.
134+
// Configure::write('App.fullBaseUrl', php_uname('n'));
135+
136+
// Set logs to different files so they don't have permission conflicts.
137+
if (Configure::check('Log.debug')) {
138+
Configure::write('Log.debug.file', 'cli-debug');
139+
}
140+
if (Configure::check('Log.error')) {
141+
Configure::write('Log.error.file', 'cli-error');
142+
}
134143
}
135144

136145
/*
137146
* Set the full base URL.
138147
* This URL is used as the base of all absolute links.
148+
* Can be very useful for CLI/Commandline applications.
139149
*/
140150
$fullBaseUrl = Configure::read('App.fullBaseUrl');
141151
if (!$fullBaseUrl) {
@@ -165,6 +175,10 @@
165175
}
166176
unset($fullBaseUrl);
167177

178+
/*
179+
* Apply the loaded configuration settings to their respective systems.
180+
* This will also remove the loaded config data from memory.
181+
*/
168182
Cache::setConfig(Configure::consume('Cache'));
169183
ConnectionManager::setConfig(Configure::consume('Datasources'));
170184
TransportFactory::setConfig(Configure::consume('EmailTransport'));
@@ -191,37 +205,29 @@
191205
/*
192206
* You can enable default locale format parsing by adding calls
193207
* to `useLocaleParser()`. This enables the automatic conversion of
194-
* locale specific date formats. For details see
208+
* locale specific date formats when processing request data. For details see
195209
* @link https://book.cakephp.org/5/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
196210
*/
197-
// \Cake\Database\TypeFactory::build('time')
198-
// ->useLocaleParser();
199-
// \Cake\Database\TypeFactory::build('date')
200-
// ->useLocaleParser();
201-
// \Cake\Database\TypeFactory::build('datetime')
202-
// ->useLocaleParser();
203-
// \Cake\Database\TypeFactory::build('timestamp')
204-
// ->useLocaleParser();
205-
// \Cake\Database\TypeFactory::build('datetimefractional')
206-
// ->useLocaleParser();
207-
// \Cake\Database\TypeFactory::build('timestampfractional')
208-
// ->useLocaleParser();
209-
// \Cake\Database\TypeFactory::build('datetimetimezone')
210-
// ->useLocaleParser();
211-
// \Cake\Database\TypeFactory::build('timestamptimezone')
212-
// ->useLocaleParser();
211+
// \Cake\Database\TypeFactory::build('time')->useLocaleParser();
212+
// \Cake\Database\TypeFactory::build('date')->useLocaleParser();
213+
// \Cake\Database\TypeFactory::build('datetime')->useLocaleParser();
214+
// \Cake\Database\TypeFactory::build('timestamp')->useLocaleParser();
215+
// \Cake\Database\TypeFactory::build('datetimefractional')->useLocaleParser();
216+
// \Cake\Database\TypeFactory::build('timestampfractional')->useLocaleParser();
217+
// \Cake\Database\TypeFactory::build('datetimetimezone')->useLocaleParser();
218+
// \Cake\Database\TypeFactory::build('timestamptimezone')->useLocaleParser();
213219

214220
/*
215221
* Custom Inflector rules, can be set to correctly pluralize or singularize
216222
* table, model, controller names or whatever other string is passed to the
217223
* inflection functions.
218224
*/
219-
//Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
220-
//Inflector::rules('irregular', ['red' => 'redlings']);
221-
//Inflector::rules('uninflected', ['dontinflectme']);
225+
// \Cake\Utility\Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
226+
// \Cake\Utility\Inflector::rules('irregular', ['red' => 'redlings']);
227+
// \Cake\Utility\Inflector::rules('uninflected', ['dontinflectme']);
222228

223229
// set a custom date and time format
224230
// see https://book.cakephp.org/5/en/core-libraries/time.html#setting-the-default-locale-and-format-string
225231
// and https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax
226-
//\Cake\I18n\Date::setToStringFormat('dd.MM.yyyy');
227-
//\Cake\I18n\Time::setToStringFormat('dd.MM.yyyy HH:mm');
232+
// \Cake\I18n\Date::setToStringFormat('dd.MM.yyyy');
233+
// \Cake\I18n\Time::setToStringFormat('dd.MM.yyyy HH:mm');

config/bootstrap_cli.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)