Skip to content

Commit 3b53427

Browse files
committed
#update-cms-tutorial remove loadIdentifier deprecation, update config/app.php with the latest from the cakephp/app skeleton
1 parent d9c5262 commit 3b53427

2 files changed

Lines changed: 144 additions & 76 deletions

File tree

config/app.php

Lines changed: 110 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
use Cake\Cache\Engine\FileEngine;
64
use Cake\Database\Connection;
75
use Cake\Database\Driver\Mysql;
8-
use Cake\Error\ExceptionRenderer;
96
use Cake\Log\Engine\FileLog;
107
use Cake\Mailer\Transport\MailTransport;
11-
128
use function Cake\Core\env;
139

1410
return [
@@ -21,7 +17,7 @@
2117
* Development Mode:
2218
* true: Errors and warnings shown.
2319
*/
24-
'debug' => true, //filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),
20+
'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),
2521

2622
/*
2723
* Configure basic information about the application.
@@ -30,7 +26,7 @@
3026
* - defaultLocale - The default locale for translation, formatting currencies and numbers, date and time.
3127
* - encoding - The encoding used for HTML + database connections.
3228
* - base - The base directory the app resides in. If false this
33-
* will be auto detected.
29+
* will be auto-detected.
3430
* - dir - Name of app directory.
3531
* - webroot - The webroot directory.
3632
* - wwwRoot - The file path to webroot.
@@ -44,10 +40,10 @@
4440
* CakePHP generates required value based on `HTTP_HOST` environment variable.
4541
* However, you can define it manually to optimize performance or if you
4642
* are concerned about people manipulating the `Host` header.
47-
* - imageBaseUrl - Web path to the public images directory under webroot.
48-
* - cssBaseUrl - Web path to the public css directory under webroot.
49-
* - jsBaseUrl - Web path to the public js directory under webroot.
50-
* - paths - Configure paths for non class based resources. Supports the
43+
* - imageBaseUrl - Web path to the public images/ directory under webroot.
44+
* - cssBaseUrl - Web path to the public css/ directory under webroot.
45+
* - jsBaseUrl - Web path to the public js/ directory under webroot.
46+
* - paths - Configure paths for non class-based resources. Supports the
5147
* `plugins`, `templates`, `locales` subkeys, which allow the definition of
5248
* paths for plugins, view templates and locale files respectively.
5349
*/
@@ -112,9 +108,9 @@
112108
* Duration will be set to '+2 minutes' in bootstrap.php when debug = true
113109
* If you set 'className' => 'Null' core cache will be disabled.
114110
*/
115-
'_cake_core_' => [
111+
'_cake_translations_' => [
116112
'className' => FileEngine::class,
117-
'prefix' => 'myapp_cake_core_',
113+
'prefix' => 'myapp_cake_translations_',
118114
'path' => CACHE . 'persistent' . DS,
119115
'serialize' => true,
120116
'duration' => '+1 years',
@@ -135,20 +131,6 @@
135131
'duration' => '+1 years',
136132
'url' => env('CACHE_CAKEMODEL_URL', null),
137133
],
138-
139-
/*
140-
* Configure the cache for routes. The cached routes collection is built the
141-
* first time the routes are processed through `config/routes.php`.
142-
* Duration will be set to '+2 seconds' in bootstrap.php when debug = true
143-
*/
144-
'_cake_routes_' => [
145-
'className' => FileEngine::class,
146-
'prefix' => 'myapp_cake_routes_',
147-
'path' => CACHE,
148-
'serialize' => true,
149-
'duration' => '+1 years',
150-
'url' => env('CACHE_CAKEROUTES_URL', null),
151-
],
152134
],
153135

154136
/*
@@ -165,29 +147,51 @@
165147
* Options:
166148
*
167149
* - `errorLevel` - int - The level of errors you are interested in capturing.
168-
* - `trace` - boolean - Whether or not backtraces should be included in
150+
* - `trace` - boolean - Whether backtraces should be included in
169151
* logged errors/exceptions.
170-
* - `log` - boolean - Whether or not you want exceptions logged.
171-
* - `exceptionRenderer` - string - The class responsible for rendering
172-
* uncaught exceptions. If you choose a custom class you should place
173-
* the file for that class in src/Error. This class needs to implement a
174-
* render method.
152+
* - `log` - boolean - Whether you want exceptions logged.
153+
* - `exceptionRenderer` - string - The class responsible for rendering uncaught exceptions.
154+
* The chosen class will be used for both CLI and web environments. If you want different
155+
* classes used in CLI and web environments you'll need to write that conditional logic as well.
156+
* The conventional location for custom renderers is in `src/Error`. Your exception renderer needs to
157+
* implement the `render()` method and return either a string or Http\Response.
158+
* `errorRenderer` - string - The class responsible for rendering PHP errors. The selected
159+
* class will be used for both web and CLI contexts. If you want different classes for each environment
160+
* you'll need to write that conditional logic as well. Error renderers need to
161+
* to implement the `Cake\Error\ErrorRendererInterface`.
175162
* - `skipLog` - array - List of exceptions to skip for logging. Exceptions that
176163
* extend one of the listed exceptions will also be skipped for logging.
177164
* E.g.:
178165
* `'skipLog' => ['Cake\Http\Exception\NotFoundException', 'Cake\Http\Exception\UnauthorizedException']`
179-
* - `extraFatalErrorMemory` - int - The number of megabytes to increase
180-
* the memory limit by when a fatal error is encountered. This allows
166+
* - `extraFatalErrorMemory` - int - The number of megabytes to increase the memory limit by
167+
* when a fatal error is encountered. This allows
181168
* breathing room to complete logging or error handling.
169+
* - `ignoredDeprecationPaths` - array - A list of glob-compatible file paths that deprecations
170+
* should be ignored in. Use this to ignore deprecations for plugins or parts of
171+
* your application that still emit deprecations.
182172
*/
183173
'Error' => [
184174
'errorLevel' => E_ALL,
185-
'exceptionRenderer' => ExceptionRenderer::class,
186-
'skipLog' => [
187-
'Cake\Http\Exception\NotFoundException',
188-
],
175+
'skipLog' => [],
189176
'log' => true,
190177
'trace' => true,
178+
'ignoredDeprecationPaths' => [],
179+
],
180+
181+
/*
182+
* Debugger configuration
183+
*
184+
* Define development error values for Cake\Error\Debugger
185+
*
186+
* - `editor` Set the editor URL format you want to use.
187+
* By default atom, emacs, macvim, phpstorm, sublime, textmate, and vscode are
188+
* available. You can add additional editor link formats using
189+
* `Debugger::addEditor()` during your application bootstrap.
190+
* - `outputMask` A mapping of `key` to `replacement` values that
191+
* `Debugger` should replace in dumped data and logs generated by `Debugger`.
192+
*/
193+
'Debugger' => [
194+
'editor' => 'phpstorm',
191195
],
192196

193197
/*
@@ -236,7 +240,7 @@
236240
* Delivery profiles allow you to predefine various properties about email
237241
* messages from your application and give the settings a name. This saves
238242
* duplication across your application and makes maintenance and development
239-
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
243+
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Mailer`
240244
* for more information.
241245
*/
242246
'Email' => [
@@ -257,36 +261,36 @@
257261
*
258262
* ### Notes
259263
* - Drivers include Mysql Postgres Sqlite Sqlserver
260-
* See vendor\cakephp\cakephp\src\Database\Driver for complete list
261-
* - Do not use periods in database name - it may lead to error.
264+
* See vendor\cakephp\cakephp\src\Database\Driver for the complete list
265+
* - Do not use periods in database name - it may lead to errors.
262266
* See https://github.com/cakephp/cakephp/issues/6471 for details.
263267
* - 'encoding' is recommended to be set to full UTF-8 4-Byte support.
264268
* E.g set it to 'utf8mb4' in MariaDB and MySQL and 'utf8' for any
265269
* other RDBMS.
266270
*/
267271
'Datasources' => [
268-
/**
272+
/*
269273
* These configurations should contain permanent settings used
270274
* by all environments.
271275
*
272276
* The values in app_local.php will override any values set here
273277
* and should be used for local and per-environment configurations.
274278
*
275-
* Environment variable based configurations can be loaded here or
276-
* in app_local.php depending on the applications needs.
279+
* Environment variable-based configurations can be loaded here or
280+
* in app_local.php depending on the application's needs.
277281
*/
278282
'default' => [
279283
'className' => Connection::class,
280284
'driver' => Mysql::class,
281285
'persistent' => false,
282286
'timezone' => 'UTC',
283287

284-
/**
285-
* For MariaDB/MySQL the internal default changed from utf8 to utf8mb4, aka full utf-8 support, in CakePHP 3.6
288+
/*
289+
* For MariaDB/MySQL the internal default changed from utf8 to utf8mb4, aka full utf-8 support
286290
*/
287-
//'encoding' => 'utf8mb4',
291+
'encoding' => 'utf8mb4',
288292

289-
/**
293+
/*
290294
* If your MySQL server is configured with `skip-character-set-client-handshake`
291295
* then you MUST use the `flags` config to set your charset encoding.
292296
* For e.g. `'flags' => [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4']`
@@ -323,7 +327,7 @@
323327
'driver' => Mysql::class,
324328
'persistent' => false,
325329
'timezone' => 'UTC',
326-
//'encoding' => 'utf8mb4',
330+
'encoding' => 'utf8mb4',
327331
'flags' => [],
328332
'cacheMetadata' => true,
329333
'quoteIdentifiers' => false,
@@ -352,13 +356,13 @@
352356
'scopes' => null,
353357
'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
354358
],
355-
// To enable this dedicated query log, you need set your datasource's log flag to true
359+
// To enable this dedicated query log, you need to set your datasource's log flag to true
356360
'queries' => [
357361
'className' => FileLog::class,
358362
'path' => LOGS,
359363
'file' => 'queries',
360364
'url' => env('LOG_QUERIES_URL', null),
361-
'scopes' => ['queriesLog'],
365+
'scopes' => ['cake.database.queries'],
362366
],
363367
],
364368

@@ -375,18 +379,23 @@
375379
* Avoid using `.` in cookie names, as PHP will drop sessions from cookies with `.` in the name.
376380
* - `cookiePath` - The url path for which session cookie is set. Maps to the
377381
* `session.cookie_path` php.ini config. Defaults to base path of app.
378-
* - `timeout` - The time in minutes the session should be valid for.
379-
* Pass 0 to disable checking timeout.
380-
* Please note that php.ini's session.gc_maxlifetime must be equal to or greater
381-
* than the largest Session['timeout'] in all served websites for it to have the
382-
* desired effect.
382+
* - `timeout` - The time in minutes a session can be 'idle'. If no request is received in
383+
* this duration, the session will be expired and rotated. Pass 0 to disable idle timeout checks.
383384
* - `defaults` - The default configuration set to use as a basis for your session.
384385
* There are four built-in options: php, cake, cache, database.
385386
* - `handler` - Can be used to enable a custom session handler. Expects an
386387
* array with at least the `engine` key, being the name of the Session engine
387388
* class to use for managing the session. CakePHP bundles the `CacheSession`
388389
* and `DatabaseSession` engines.
389-
* - `ini` - An associative array of additional ini values to set.
390+
* - `ini` - An associative array of additional 'session.*` ini values to set.
391+
*
392+
* Within the `ini` key, you will likely want to define:
393+
*
394+
* - `session.cookie_lifetime` - The number of seconds that cookies are valid for. This
395+
* should be longer than `Session.timeout`.
396+
* - `session.gc_maxlifetime` - The number of seconds after which a session is considered 'garbage'
397+
* that can be deleted by PHP's session cleanup behavior. This value should be greater than both
398+
* `Sesssion.timeout` and `session.cookie_lifetime`.
390399
*
391400
* The built-in `defaults` options are:
392401
*
@@ -395,7 +404,7 @@
395404
* - 'database' - Uses CakePHP's database sessions.
396405
* - 'cache' - Use the Cache class to save sessions.
397406
*
398-
* To define a custom session handler, save it at src/Network/Session/<name>.php.
407+
* To define a custom session handler, save it at src/Http/Session/<name>.php.
399408
* Make sure the class implements PHP's `SessionHandlerInterface` and set
400409
* Session.handler to <name>
401410
*
@@ -404,4 +413,47 @@
404413
'Session' => [
405414
'defaults' => 'php',
406415
],
416+
417+
/**
418+
* DebugKit configuration.
419+
*
420+
* Contains an array of configurations to apply to the DebugKit plugin, if loaded.
421+
* Documentation: https://book.cakephp.org/debugkit/5/en/index.html#configuration
422+
*
423+
* ## Options
424+
*
425+
* - `panels` - Enable or disable panels. The key is the panel name, and the value is true to enable,
426+
* or false to disable.
427+
* - `includeSchemaReflection` - Set to true to enable logging of schema reflection queries. Disabled by default.
428+
* - `safeTld` - Set an array of whitelisted TLDs for local development.
429+
* - `forceEnable` - Force DebugKit to display. Careful with this, it is usually safer to simply whitelist
430+
* your local TLDs.
431+
* - `ignorePathsPattern` - Regex pattern (including delimiter) to ignore paths.
432+
* DebugKit won’t save data for request URLs that match this regex.
433+
* - `ignoreAuthorization` - Set to true to ignore Cake Authorization plugin for DebugKit requests.
434+
* Disabled by default.
435+
* - `maxDepth` - Defines how many levels of nested data should be shown in general for debug output.
436+
* Default is 5. WARNING: Increasing the max depth level can lead to an out of memory error.
437+
* - `variablesPanelMaxDepth` - Defines how many levels of nested data should be shown in the variables tab.
438+
* Default is 5. WARNING: Increasing the max depth level can lead to an out of memory error.
439+
*/
440+
'DebugKit' => [
441+
'forceEnable' => filter_var(env('DEBUG_KIT_FORCE_ENABLE', false), FILTER_VALIDATE_BOOLEAN),
442+
'safeTld' => env('DEBUG_KIT_SAFE_TLD', null),
443+
'ignoreAuthorization' => env('DEBUG_KIT_IGNORE_AUTHORIZATION', false),
444+
],
445+
446+
/**
447+
* TestSuite configuration.
448+
*
449+
* ## Options
450+
*
451+
* - `errorLevel` - Defaults to `E_ALL`. Can be set to `false` to disable overwrite error level.
452+
* - `fixtureStrategy` - Defaults to TruncateStrategy. Can be set to any class implementing FixtureStrategyInterface.
453+
*/
454+
'TestSuite' => [
455+
'errorLevel' => null,
456+
'fixtureStrategy' => null,
457+
],
407458
];
459+

src/Application.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Authentication\AuthenticationService;
1818
use Authentication\AuthenticationServiceInterface;
1919
use Authentication\AuthenticationServiceProviderInterface;
20+
use Authentication\Identifier\AbstractIdentifier;
2021
use Authentication\Middleware\AuthenticationMiddleware;
2122
use Authorization\AuthorizationService;
2223
use Authorization\AuthorizationServiceInterface;
@@ -120,31 +121,46 @@ public function middleware($middlewareQueue): \Cake\Http\MiddlewareQueue
120121

121122
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
122123
{
123-
$authenticationService = new AuthenticationService([
124-
'unauthenticatedRedirect' => Router::url('/users/login'),
124+
$service = new AuthenticationService();
125+
126+
// Define where users should be redirected to when they are not authenticated
127+
$service->setConfig([
128+
'unauthenticatedRedirect' => [
129+
'prefix' => false,
130+
'plugin' => false,
131+
'controller' => 'Users',
132+
'action' => 'login',
133+
],
125134
'queryParam' => 'redirect',
126135
]);
127136

128-
// Load identifiers, ensure we check email and password fields
129-
$authenticationService->loadIdentifier('Authentication.Password', [
130-
'fields' => [
131-
'username' => 'email',
132-
'password' => 'password',
137+
// Define identifiers
138+
$fields = [
139+
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
140+
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password'
141+
];
142+
$passwordIdentifier = [
143+
'Authentication.Password' => [
144+
'fields' => $fields,
133145
],
134-
]);
146+
];
135147

136-
// Load the authenticators, you want session first
137-
$authenticationService->loadAuthenticator('Authentication.Session');
138-
// Configure form data check to pick email and password
139-
$authenticationService->loadAuthenticator('Authentication.Form', [
140-
'fields' => [
141-
'username' => 'email',
142-
'password' => 'password',
143-
],
144-
'loginUrl' => '/users/login',
148+
// Load the authenticators. Session should be first.
149+
$service->loadAuthenticator('Authentication.Session', [
150+
'identifier' => $passwordIdentifier,
151+
]);
152+
$service->loadAuthenticator('Authentication.Form', [
153+
'identifier' => $passwordIdentifier,
154+
'fields' => $fields,
155+
'loginUrl' => Router::url([
156+
'prefix' => false,
157+
'plugin' => null,
158+
'controller' => 'Users',
159+
'action' => 'login',
160+
]),
145161
]);
146162

147-
return $authenticationService;
163+
return $service;
148164
}
149165

150166
public function getAuthorizationService(ServerRequestInterface $request): AuthorizationServiceInterface

0 commit comments

Comments
 (0)