From ff996feff4df2028f802ae2f961e1e3285dccefc Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 10 Sep 2025 09:41:42 +0000 Subject: [PATCH] Sync configuration files --- app/config/app.php | 419 +++++++++++++++---------- app/config/bootstrap.php | 117 +++---- app/config/paths.php | 2 +- app/src/Controller/ApiV2Controller.php | 11 +- app/src/Controller/AppController.php | 5 +- 5 files changed, 324 insertions(+), 230 deletions(-) diff --git a/app/config/app.php b/app/config/app.php index 974c4a67b..fa782aff8 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -25,8 +25,15 @@ * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ +use Cake\Cache\Engine\FileEngine; +use Cake\Database\Connection; +use Cake\Database\Driver\Mysql; +use Cake\Log\Engine\FileLog; +use Cake\Mailer\Transport\MailTransport; +use function Cake\Core\env; + return [ - /** + /* * Debug Level: * * Production Mode: @@ -37,14 +44,14 @@ */ 'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN), - /** + /* * Configure basic information about the application. * * - namespace - The namespace to find app classes under. * - defaultLocale - The default locale for translation, formatting currencies and numbers, date and time. * - encoding - The encoding used for HTML + database connections. * - base - The base directory the app resides in. If false this - * will be auto detected. + * will be auto-detected. * - dir - Name of app directory. * - webroot - The webroot directory. * - wwwRoot - The file path to webroot. @@ -58,10 +65,10 @@ * CakePHP generates required value based on `HTTP_HOST` environment variable. * However, you can define it manually to optimize performance or if you * are concerned about people manipulating the `Host` header. - * - imageBaseUrl - Web path to the public images directory under webroot. - * - cssBaseUrl - Web path to the public css directory under webroot. - * - jsBaseUrl - Web path to the public js directory under webroot. - * - paths - Configure paths for non class based resources. Supports the + * - imageBaseUrl - Web path to the public images/ directory under webroot. + * - cssBaseUrl - Web path to the public css/ directory under webroot. + * - jsBaseUrl - Web path to the public js/ directory under webroot. + * - paths - Configure paths for non class-based resources. Supports the * `plugins`, `templates`, `locales` subkeys, which allow the definition of * paths for plugins, view templates and locale files respectively. */ @@ -89,11 +96,11 @@ LOCAL . DS . 'plugins' . DS ], 'templates' => [ROOT . DS . 'templates' . DS], - 'locales' => [ROOT . DS . 'resources' . DS . 'locales' . DS], + 'locales' => [RESOURCES . 'locales' . DS], ], ], - /** + /* * Security and encryption configuration * * - salt - A random string used in security hashing methods. @@ -101,11 +108,11 @@ * You should treat it as extremely sensitive data. */ 'Security' => [ - // Note that we (COmanage) override this in bootstrap.php - //'salt' => env('SECURITY_SALT', 'd6ded009aad8fe73e7ebf4f9c170e39e3b0ed0ab9253ed3eb4db03ad6fc07ab4'), + // Note that we (COmanage) override this in bootstrap.php + //'salt' => env('SECURITY_SALT', 'd6ded009aad8fe73e7ebf4f9c170e39e3b0ed0ab9253ed3eb4db03ad6fc07ab4'), ], - /** + /* * Apply timestamps with the last modified time to static assets (js, css, images). * Will append a querystring parameter containing the time the file was modified. * This is useful for busting browser caches. @@ -118,41 +125,41 @@ // 'cacheTime' => '+1 year' ], - /** + /* * Configure the cache adapters. */ 'Cache' => [ 'default' => [ - 'className' => 'Cake\Cache\Engine\FileEngine', + 'className' => FileEngine::class, 'path' => CACHE, 'url' => env('CACHE_DEFAULT_URL', null), ], - /** + /* * Configure the cache used for general framework caching. * Translation cache files are stored with this configuration. * Duration will be set to '+2 minutes' in bootstrap.php when debug = true * If you set 'className' => 'Null' core cache will be disabled. */ '_cake_translations_' => [ - 'className' => 'Cake\Cache\Engine\FileEngine', + 'className' => FileEngine::class, 'prefix' => 'myapp_cake_translations_', - 'path' => CACHE . 'persistent/', + 'path' => CACHE . 'persistent' . DS, 'serialize' => true, 'duration' => '+1 years', - 'url' => env('CACHE_TRNASLATIONS_URL', null), + 'url' => env('CACHE_CAKECORE_URL', null), ], - /** + /* * Configure the cache for model and datasource caches. This cache * configuration is used to store schema descriptions, and table listings * in connections. * Duration will be set to '+2 minutes' in bootstrap.php when debug = true */ '_cake_model_' => [ - 'className' => 'Cake\Cache\Engine\FileEngine', + 'className' => FileEngine::class, 'prefix' => 'myapp_cake_model_', - 'path' => CACHE . 'models/', + 'path' => CACHE . 'models' . DS, 'serialize' => true, 'duration' => '+1 years', 'url' => env('CACHE_CAKEMODEL_URL', null), @@ -164,27 +171,27 @@ * Duration will be set to '+2 seconds' in bootstrap.php when debug = true */ '_cake_routes_' => [ - 'className' => 'Cake\Cache\Engine\FileEngine', + 'className' => FileEngine::class, 'prefix' => 'myapp_cake_routes_', 'path' => CACHE, 'serialize' => true, 'duration' => '+1 years', 'url' => env('CACHE_CAKEROUTES_URL', null), ], - /** - * Configure the cache for html elements. - * Duration will be set to '+2 seconds' in bootstrap.php when debug = true - */ + /** + * Configure the cache for html elements. + * Duration will be set to '+2 seconds' in bootstrap.php when debug = true + */ '_html_elements' => [ - 'className' => 'Cake\Cache\Engine\FileEngine', - 'prefix' => 'myapp_cake_elements_', - 'duration' => '+1 week', - 'probability' => 100, - 'url' => env('CACHE_HTMLELEMENT_URL', null), + 'className' => FileEngine::class, + 'prefix' => 'myapp_cake_elements_', + 'duration' => '+1 week', + 'probability' => 100, + 'url' => env('CACHE_HTMLELEMENT_URL', null), ] ], - /** + /* * Configure the Error and Exception handlers used by your application. * * By default errors are displayed using Debugger, when debug is true and logged @@ -198,29 +205,54 @@ * Options: * * - `errorLevel` - int - The level of errors you are interested in capturing. - * - `trace` - boolean - Whether or not backtraces should be included in + * - `trace` - boolean - Whether backtraces should be included in * logged errors/exceptions. - * - `log` - boolean - Whether or not you want exceptions logged. - * - `exceptionRenderer` - string - The class responsible for rendering - * uncaught exceptions. If you choose a custom class you should place - * the file for that class in src/Error. This class needs to implement a - * render method. + * - `log` - boolean - Whether you want exceptions logged. + * - `exceptionRenderer` - string - The class responsible for rendering uncaught exceptions. + * The chosen class will be used for both CLI and web environments. If you want different + * classes used in CLI and web environments you'll need to write that conditional logic as well. + * The conventional location for custom renderers is in `src/Error`. Your exception renderer needs to + * implement the `render()` method and return either a string or Http\Response. + * `errorRenderer` - string - The class responsible for rendering PHP errors. The selected + * class will be used for both web and CLI contexts. If you want different classes for each environment + * you'll need to write that conditional logic as well. Error renderers need to + * to implement the `Cake\Error\ErrorRendererInterface`. * - `skipLog` - array - List of exceptions to skip for logging. Exceptions that * extend one of the listed exceptions will also be skipped for logging. * E.g.: * `'skipLog' => ['Cake\Http\Exception\NotFoundException', 'Cake\Http\Exception\UnauthorizedException']` - * - `extraFatalErrorMemory` - int - The number of megabytes to increase - * the memory limit by when a fatal error is encountered. This allows + * - `extraFatalErrorMemory` - int - The number of megabytes to increase the memory limit by + * when a fatal error is encountered. This allows * breathing room to complete logging or error handling. + * - `ignoredDeprecationPaths` - array - A list of glob-compatible file paths that deprecations + * should be ignored in. Use this to ignore deprecations for plugins or parts of + * your application that still emit deprecations. */ 'Error' => [ 'errorLevel' => E_ALL, 'skipLog' => [], 'log' => true, 'trace' => true, + 'ignoredDeprecationPaths' => [], ], - /** + /* + * Debugger configuration + * + * Define development error values for Cake\Error\Debugger + * + * - `editor` Set the editor URL format you want to use. + * By default atom, emacs, macvim, phpstorm, sublime, textmate, and vscode are + * available. You can add additional editor link formats using + * `Debugger::addEditor()` during your application bootstrap. + * - `outputMask` A mapping of `key` to `replacement` values that + * `Debugger` should replace in dumped data and logs generated by `Debugger`. + */ + 'Debugger' => [ + 'editor' => 'phpstorm', + ], + + /* * Email configuration. * * By defining transports separately from delivery profiles you can easily @@ -238,87 +270,94 @@ * You can add custom transports (or override existing transports) by adding the * appropriate file to src/Mailer/Transport. Transports should be named * 'YourTransport.php', where 'Your' is the name of the transport. - * - * Note Registry uses dynamic configuration for EmailTransport. */ 'EmailTransport' => [ 'default' => [ - 'className' => 'Cake\Mailer\Transport\MailTransport', + 'className' => MailTransport::class, /* - * The following keys are used in SMTP transports: + * The keys host, port, timeout, username, password, client and tls + * are used in SMTP transports */ 'host' => 'localhost', 'port' => 25, 'timeout' => 30, - 'username' => null, - 'password' => null, + /* + * It is recommended to set these options through your environment or app_local.php + */ + //'username' => null, + //'password' => null, 'client' => null, - 'tls' => null, + 'tls' => false, 'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null), ], ], - /** + /* * Email delivery profiles * * Delivery profiles allow you to predefine various properties about email * messages from your application and give the settings a name. This saves * duplication across your application and makes maintenance and development - * easier. Each profile accepts a number of keys. See `Cake\Mailer\Email` + * easier. Each profile accepts a number of keys. See `Cake\Mailer\Mailer` * for more information. - * - * Note Registry uses dynamic configuration for Email. */ 'Email' => [ 'default' => [ 'transport' => 'default', 'from' => 'you@localhost', + /* + * Will by default be set to config value of App.encoding, if that exists otherwise to UTF-8. + */ //'charset' => 'utf-8', //'headerCharset' => 'utf-8', ], ], - /** + /* * Connection information used by the ORM to connect * to your application's datastores. * * ### Notes * - Drivers include Mysql Postgres Sqlite Sqlserver - * See vendor\cakephp\cakephp\src\Database\Driver for complete list - * - Do not use periods in database name - it may lead to error. + * See vendor\cakephp\cakephp\src\Database\Driver for the complete list + * - Do not use periods in database name - it may lead to errors. * See https://github.com/cakephp/cakephp/issues/6471 for details. * - 'encoding' is recommended to be set to full UTF-8 4-Byte support. * E.g set it to 'utf8mb4' in MariaDB and MySQL and 'utf8' for any * other RDBMS. - * - * Note for COmanage we read in local/Config/database.php instead */ 'Datasources' => [ + /* + * These configurations should contain permanent settings used + * by all environments. + * + * The values in app_local.php will override any values set here + * and should be used for local and per-environment configurations. + * + * Environment variable-based configurations can be loaded here or + * in app_local.php depending on the application's needs. + */ 'default' => [ - 'className' => 'Cake\Database\Connection', - 'driver' => 'Cake\Database\Driver\Mysql', + 'className' => Connection::class, + 'driver' => Mysql::class, 'persistent' => false, - 'host' => 'localhost', + 'timezone' => 'UTC', + /* - * CakePHP will use the default DB port based on the driver selected - * MySQL on MAMP uses port 8889, MAMP users will want to uncomment - * the following line and set the port accordingly + * For MariaDB/MySQL the internal default changed from utf8 to utf8mb4, aka full utf-8 support */ - //'port' => 'non_standard_port_number', - 'username' => 'my_app', - 'password' => 'secret', - 'database' => 'my_app', + 'encoding' => 'utf8mb4', + /* - * You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6). + * If your MySQL server is configured with `skip-character-set-client-handshake` + * then you MUST use the `flags` config to set your charset encoding. + * For e.g. `'flags' => [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4']` */ - //'encoding' => 'utf8mb4', - 'timezone' => 'UTC', 'flags' => [], 'cacheMetadata' => true, - // Set to true to get query log for debugging - 'log' => null, + 'log' => false, - /** + /* * Set identifier quoting to true if you are using reserved words or * special characters in your table or column names. Enabling this * setting will result in queries built using the Query Builder having @@ -328,7 +367,7 @@ */ 'quoteIdentifiers' => false, - /** + /* * During development, if using MySQL < 5.6, uncommenting the * following line could boost the speed at which schema metadata is * fetched from the database. It can also be set directly with the @@ -336,111 +375,104 @@ * which is the recommended value in production environments */ //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], - - 'url' => env('DATABASE_URL', null), ], - /** + /* * The test connection is used during the test suite. */ 'test' => [ - 'className' => 'Cake\Database\Connection', - 'driver' => 'Cake\Database\Driver\Mysql', + 'className' => Connection::class, + 'driver' => Mysql::class, 'persistent' => false, - 'host' => 'localhost', - //'port' => 'non_standard_port_number', - 'username' => 'my_app', - 'password' => 'secret', - 'database' => 'test_myapp', - //'encoding' => 'utf8mb4', 'timezone' => 'UTC', + 'encoding' => 'utf8mb4', + 'flags' => [], 'cacheMetadata' => true, 'quoteIdentifiers' => false, - 'log' => null, + 'log' => false, //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], - 'url' => env('DATABASE_TEST_URL', null), ], ], - /** + /* * Configures logging options */ 'Log' => null !== env('COMANAGE_REGISTRY_CONTAINER', null) - // Configuration for container deployments - ? [ - 'debug' => [ - 'className' => 'Cake\Log\Engine\ConsoleLog', - 'stream' => 'php://stdout', - 'outputAs' => 0, - 'scopes' => null, - 'levels' => ['notice', 'info', 'debug'], - ], - 'error' => [ - 'className' => 'Cake\Log\Engine\ConsoleLog', - 'stream' => 'php://stderr', - 'outputAs' => 0, - 'scopes' => null, - 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], - ], - 'queries' => [ - 'className' => 'Cake\Log\Engine\ConsoleLog', - 'stream' => 'php://stdout', - 'outputAs' => 0, - 'scopes' => ['queriesLog'] - ], - 'trace' => [ - 'className' => 'Cake\Log\Engine\ConsoleLog', - 'stream' => 'php://stdout', - 'outputAs' => 0, - 'scopes' => ['trace'], - ] - ] - // Configuration for tranditional deployments - : [ - 'debug' => [ - 'className' => 'Cake\Log\Engine\FileLog', - 'path' => LOGS, - 'file' => 'debug', - 'url' => env('LOG_DEBUG_URL', null), - 'scopes' => null, - 'levels' => ['notice', 'info', 'debug'], - ], - 'error' => [ - 'className' => 'Cake\Log\Engine\FileLog', - 'path' => LOGS, - 'file' => 'error', - 'url' => env('LOG_ERROR_URL', null), - 'scopes' => null, - 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], - ], - // To enable this dedicated query log, you need set your datasource's log flag to true - 'queries' => [ - 'className' => 'Cake\Log\Engine\FileLog', - 'path' => LOGS, - 'file' => 'queries', - 'url' => env('LOG_QUERIES_URL', null), - 'scopes' => ['queriesLog'], - ], - // We define a trace level for what is really debugging, except debug level - // will write to stdout instead of the log when debug=true - 'trace' => [ - 'className' => 'Cake\Log\Engine\FileLog', - 'path' => LOGS, - 'file' => 'trace', - 'url' => env('LOG_TRACE_URL', null), - 'scopes' => ['trace'], + // Configuration for container deployments + ? [ + 'debug' => [ + 'className' => FileLog::class, + 'stream' => 'php://stdout', + 'outputAs' => 0, + 'scopes' => null, + 'levels' => ['notice', 'info', 'debug'], + ], + 'error' => [ + 'className' => FileLog::class, + 'stream' => 'php://stderr', + 'outputAs' => 0, + 'scopes' => null, + 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], + ], + 'queries' => [ + 'className' => FileLog::class, + 'stream' => 'php://stdout', + 'outputAs' => 0, + 'scopes' => ['queriesLog'] + ], + 'trace' => [ + 'className' => FileLog::class, + 'stream' => 'php://stdout', + 'outputAs' => 0, + 'scopes' => ['trace'], + ] + ] + // Configuration for tranditional deployments + : [ + 'debug' => [ + 'className' => FileLog::class, + 'path' => LOGS, + 'file' => 'debug', + 'url' => env('LOG_DEBUG_URL', null), + 'scopes' => null, + 'levels' => ['notice', 'info', 'debug'], + ], + 'error' => [ + 'className' => FileLog::class, + 'path' => LOGS, + 'file' => 'error', + 'url' => env('LOG_ERROR_URL', null), + 'scopes' => null, + 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], + ], + // To enable this dedicated query log, you need to set your datasource's log flag to true + 'queries' => [ + 'className' => FileLog::class, + 'path' => LOGS, + 'file' => 'queries', + 'url' => env('LOG_QUERIES_URL', null), + 'scopes' => ['cake.database.queries'], + ], + // We define a trace level for what is really debugging, except debug level + // will write to stdout instead of the log when debug=true + 'trace' => [ + 'className' => FileLog::class, + 'path' => LOGS, + 'file' => 'trace', + 'url' => env('LOG_TRACE_URL', null), + 'scopes' => ['trace'], + ], + // We define a rules level to record application rule execution + 'rule' => [ + 'className' => FileLog::class, + 'path' => LOGS, + 'file' => 'rule', + 'url' => env('LOG_TRACE_URL', null), + 'scopes' => ['rule'], + ] ], - // We define a rules level to record application rule execution - 'rule' => [ - 'className' => 'Cake\Log\Engine\FileLog', - 'path' => LOGS, - 'file' => 'rule', - 'url' => env('LOG_TRACE_URL', null), - 'scopes' => ['rule'], - ] - ], - /** + /* * Session configuration. * * Contains an array of settings to use for session configuration. The @@ -449,22 +481,27 @@ * * ## Options * - * - `cookie` - The name of the cookie to use. Defaults to 'CAKEPHP'. Avoid using `.` in cookie names, - * as PHP will drop sessions from cookies with `.` in the name. + * - `cookie` - The name of the cookie to use. Defaults to value set for `session.name` php.ini config. + * Avoid using `.` in cookie names, as PHP will drop sessions from cookies with `.` in the name. * - `cookiePath` - The url path for which session cookie is set. Maps to the * `session.cookie_path` php.ini config. Defaults to base path of app. - * - `timeout` - The time in minutes the session should be valid for. - * Pass 0 to disable checking timeout. - * Please note that php.ini's session.gc_maxlifetime must be equal to or greater - * than the largest Session['timeout'] in all served websites for it to have the - * desired effect. + * - `timeout` - The time in minutes a session can be 'idle'. If no request is received in + * this duration, the session will be expired and rotated. Pass 0 to disable idle timeout checks. * - `defaults` - The default configuration set to use as a basis for your session. * There are four built-in options: php, cake, cache, database. * - `handler` - Can be used to enable a custom session handler. Expects an * array with at least the `engine` key, being the name of the Session engine * class to use for managing the session. CakePHP bundles the `CacheSession` * and `DatabaseSession` engines. - * - `ini` - An associative array of additional ini values to set. + * - `ini` - An associative array of additional 'session.*` ini values to set. + * + * Within the `ini` key, you will likely want to define: + * + * - `session.cookie_lifetime` - The number of seconds that cookies are valid for. This + * should be longer than `Session.timeout`. + * - `session.gc_maxlifetime` - The number of seconds after which a session is considered 'garbage' + * that can be deleted by PHP's session cleanup behavior. This value should be greater than both + * `Sesssion.timeout` and `session.cookie_lifetime`. * * The built-in `defaults` options are: * @@ -473,7 +510,7 @@ * - 'database' - Uses CakePHP's database sessions. * - 'cache' - Use the Cache class to save sessions. * - * To define a custom session handler, save it at src/Network/Session/.php. + * To define a custom session handler, save it at src/Http/Session/.php. * Make sure the class implements PHP's `SessionHandlerInterface` and set * Session.handler to * @@ -485,4 +522,46 @@ // Note this name must match the name used in webroot/auth/*/* 'cookie' => 'REGISTRYPECAKEPHP' ], + + /** + * DebugKit configuration. + * + * Contains an array of configurations to apply to the DebugKit plugin, if loaded. + * Documentation: https://book.cakephp.org/debugkit/5/en/index.html#configuration + * + * ## Options + * + * - `panels` - Enable or disable panels. The key is the panel name, and the value is true to enable, + * or false to disable. + * - `includeSchemaReflection` - Set to true to enable logging of schema reflection queries. Disabled by default. + * - `safeTld` - Set an array of whitelisted TLDs for local development. + * - `forceEnable` - Force DebugKit to display. Careful with this, it is usually safer to simply whitelist + * your local TLDs. + * - `ignorePathsPattern` - Regex pattern (including delimiter) to ignore paths. + * DebugKit won’t save data for request URLs that match this regex. + * - `ignoreAuthorization` - Set to true to ignore Cake Authorization plugin for DebugKit requests. + * Disabled by default. + * - `maxDepth` - Defines how many levels of nested data should be shown in general for debug output. + * Default is 5. WARNING: Increasing the max depth level can lead to an out of memory error. + * - `variablesPanelMaxDepth` - Defines how many levels of nested data should be shown in the variables tab. + * Default is 5. WARNING: Increasing the max depth level can lead to an out of memory error. + */ + 'DebugKit' => [ + 'forceEnable' => filter_var(env('DEBUG_KIT_FORCE_ENABLE', false), FILTER_VALIDATE_BOOLEAN), + 'safeTld' => env('DEBUG_KIT_SAFE_TLD', null), + 'ignoreAuthorization' => env('DEBUG_KIT_IGNORE_AUTHORIZATION', false), + ], + + /** + * TestSuite configuration. + * + * ## Options + * + * - `errorLevel` - Defaults to `E_ALL`. Can be set to `false` to disable overwrite error level. + * - `fixtureStrategy` - Defaults to TruncateStrategy. Can be set to any class implementing FixtureStrategyInterface. + */ + 'TestSuite' => [ + 'errorLevel' => null, + 'fixtureStrategy' => null, + ], ]; diff --git a/app/config/bootstrap.php b/app/config/bootstrap.php index fbaef3b56..bba87c600 100644 --- a/app/config/bootstrap.php +++ b/app/config/bootstrap.php @@ -15,27 +15,26 @@ * @license https://opensource.org/licenses/mit-license.php MIT License */ +/* + * This file is loaded by your src/Application.php bootstrap method. + * Feel free to extend/extract parts of the bootstrap process into your own files + * to suit your needs/preferences. + */ + /* * Configure paths required to find CakePHP + general filepath constants */ -require __DIR__ . DIRECTORY_SEPARATOR . '/paths.php'; +require __DIR__ . DIRECTORY_SEPARATOR . 'paths.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. + * Bootstrap CakePHP + * Currently all this does is initialize the router (without loading your routes) */ require CORE_PATH . 'config' . DS . 'bootstrap.php'; use Cake\Cache\Cache; use Cake\Core\Configure; use Cake\Core\Configure\Engine\PhpConfig; -use Cake\Database\TypeFactory; -use Cake\Database\Type\StringType; use Cake\Datasource\ConnectionManager; use Cake\Error\ErrorTrap; use Cake\Error\ExceptionTrap; @@ -44,8 +43,8 @@ use Cake\Mailer\Mailer; use Cake\Mailer\TransportFactory; use Cake\Routing\Router; -use Cake\Utility\Inflector; use Cake\Utility\Security; +use function Cake\Core\env; /* * Load global functions for collections, translations, debugging etc. @@ -53,12 +52,33 @@ require CAKE . 'functions.php'; /* - * Read configuration file and inject configuration into various - * CakePHP classes. + * See https://github.com/josegonzalez/php-dotenv for API details. + * + * 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. + * + * The purpose of the .env file is to emulate the presence of the environment + * variables like they would be present in production. + * + * If you use .env files, be careful to not commit them to source control to avoid + * security risks. See https://github.com/josegonzalez/php-dotenv#general-security-information + * for more information for recommended practices. +*/ +// if (!env('APP_NAME') && file_exists(CONFIG . '.env')) { +// $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']); +// $dotenv->parse() +// ->putenv() +// ->toEnv() +// ->toServer(); +// } + +/* + * Initializes default Config store and loads the main configuration file (app.php) * - * 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. + * CakePHP contains 2 configuration files after project creation: + * - `config/app.php` for the default application configuration. + * - `config/app_local.php` for environment specific configuration. */ try { Configure::config('default', new PhpConfig()); @@ -72,20 +92,19 @@ /* * 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. + * Notice: For security reasons app_local.php **should 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. + * When debug = true the metadata cache should only last for a short time. */ if (Configure::read('debug')) { Cache::disable(); //Configure::write('Cache._cake_model_.duration', '+2 minutes'); - //Configure::write('Cache._cake_core_.duration', '+2 minutes'); + //Configure::write('Cache._cake_translations_.duration', '+2 minutes'); // disable router cache during development //Configure::write('Cache._cake_routes_.duration', '+2 seconds'); Configure::write('DebugKit.forceEnable', true); @@ -93,7 +112,7 @@ /* * 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. + * Check https://php.net/manual/en/timezones.php for list of valid timezone strings. */ date_default_timezone_set(Configure::read('App.defaultTimezone')); @@ -163,11 +182,16 @@ } unset($fullBaseUrl); +/* + * Apply the loaded configuration settings to their respective systems. + * This will also remove the loaded config data from memory. + */ Cache::setConfig(Configure::consume('Cache')); ConnectionManager::setConfig(Configure::consume('Datasources')); TransportFactory::setConfig(Configure::consume('EmailTransport')); Mailer::setConfig(Configure::consume('Email')); Log::setConfig(Configure::consume('Log')); +//Security::setSalt(Configure::consume('Security.salt')); // Set the salt from the environment if available, else from the filesystem, // and if the salt cannot be determined we're probably in SetupCommand, @@ -187,6 +211,8 @@ /* * Setup detectors for mobile and tablet. + * If you don't use these checks you can safely remove this code + * and the mobiledetect package from composer.json. */ ServerRequest::addDetector('mobile', function ($request) { $detector = new \Detection\MobileDetect(); @@ -200,47 +226,32 @@ }); /* - * You can set whether the ORM uses immutable or mutable Time types. - * The default changed in 4.0 to immutable types. You can uncomment - * below to switch back to mutable types. - * * 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/4/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data + * locale specific date formats when processing request data. For details see + * @link https://book.cakephp.org/5/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data */ -// \Cake\Database\TypeFactory::build('time') -// ->useMutable(); -// \Cake\Database\TypeFactory::build('date') -// ->useMutable(); -// \Cake\Database\TypeFactory::build('datetime') -// ->useMutable(); -// \Cake\Database\TypeFactory::build('timestamp') -// ->useMutable(); -// \Cake\Database\TypeFactory::build('datetimefractional') -// ->useMutable(); -// \Cake\Database\TypeFactory::build('timestampfractional') -// ->useMutable(); -// \Cake\Database\TypeFactory::build('datetimetimezone') -// ->useMutable(); -// \Cake\Database\TypeFactory::build('timestamptimezone') -// ->useMutable(); -// There is no time-specific type in Cake -TypeFactory::map('time', StringType::class); +// \Cake\Database\TypeFactory::build('time')->useLocaleParser(); +// \Cake\Database\TypeFactory::build('date')->useLocaleParser(); +// \Cake\Database\TypeFactory::build('datetime')->useLocaleParser(); +// \Cake\Database\TypeFactory::build('timestamp')->useLocaleParser(); +// \Cake\Database\TypeFactory::build('datetimefractional')->useLocaleParser(); +// \Cake\Database\TypeFactory::build('timestampfractional')->useLocaleParser(); +// \Cake\Database\TypeFactory::build('datetimetimezone')->useLocaleParser(); +// \Cake\Database\TypeFactory::build('timestamptimezone')->useLocaleParser(); /* * 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']); - -Inflector::rules('irregular', ['co_terms_and_condition' => 'co_terms_and_conditions']); -Inflector::rules('irregular', ['cou' => 'cous']); -Inflector::rules('irregular', ['meta' => 'meta']); +// \Cake\Utility\Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']); +// \Cake\Utility\Inflector::rules('irregular', ['red' => 'redlings']); +// \Cake\Utility\Inflector::rules('uninflected', ['dontinflectme']); + +\Cake\Utility\Inflector::rules('irregular', ['co_terms_and_condition' => 'co_terms_and_conditions']); +\Cake\Utility\Inflector::rules('irregular', ['cou' => 'cous']); +\Cake\Utility\Inflector::rules('irregular', ['meta' => 'meta']); /* * Define some constants diff --git a/app/config/paths.php b/app/config/paths.php index d00dcaa55..696144318 100644 --- a/app/config/paths.php +++ b/app/config/paths.php @@ -20,7 +20,7 @@ } /* - * These defines should only be edited if you have cake installed in + * These definitions should only be edited if you have cake installed in * a directory layout other than the way it is distributed. * When using custom settings be sure to use the DS and do not add a trailing DS. */ diff --git a/app/src/Controller/ApiV2Controller.php b/app/src/Controller/ApiV2Controller.php index 38206d077..b44e1c640 100644 --- a/app/src/Controller/ApiV2Controller.php +++ b/app/src/Controller/ApiV2Controller.php @@ -60,10 +60,13 @@ public function initialize(): void { // behavior for UI calls (which is Models, eg "Cous"). We need to do this // before RegistryAuthComponent runs. $modelsName = Inflector::camelize($reqModel); - $this->name = $modelsName; - // Similarly, for compatibility with UI related calls we load the model - $this->$modelsName = TableRegistry::getTableLocator()->get($modelsName); - $this->tableName = $this->$modelsName->getTable(); + $this->setName($modelsName); + // Make this the default table for fetchTable() + $this->defaultTable = $modelsName; + // If you need a reusable handle for this request, keep it in a declared property + $this->table = $this->fetchTable(); + // If you still need the table name as a property, assign it to a declared one + $this->tableName = $this->table->getTable(); // We want API auth, not Web Auth $this->RegistryAuth->setConfig('apiUser', true); diff --git a/app/src/Controller/AppController.php b/app/src/Controller/AppController.php index b5e923597..919ac0d22 100644 --- a/app/src/Controller/AppController.php +++ b/app/src/Controller/AppController.php @@ -48,6 +48,7 @@ * @property \Cake\Controller\Component\FlashComponent $Flash * @property \Cake\Controller\Component\FormProtectionComponent $FormProtection */ +#[\AllowDynamicProperties] class AppController extends Controller { use \App\Lib\Traits\LabeledLogTrait; @@ -712,11 +713,11 @@ protected function setCO() { } if($coid) { - $this->Cos = $this->fetchTable('Cos'); + $Cos = $this->fetchTable('Cos'); // This throws Cake\Datasource\Exception\RecordNotFoundException which // we just let pass up the stack. - $this->cur_co = $this->Cos->findById($coid)->firstOrFail(); + $this->cur_co = $Cos->findById($coid)->firstOrFail(); // While the COmanage CO cannot be suspended (AR-CO-2), this is enforced // at cos/edit, not here.