From e49decb75802fe0552019c6c8fc2f05242a5cb7a Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Fri, 3 Mar 2023 23:58:24 -0600 Subject: [PATCH 01/22] wip --- app/Config/Routes.php | 49 --------- app/Config/Routing.php | 100 ++++++++++++++++++ app/Routes.php | 7 ++ system/Config/Routing.php | 98 +++++++++++++++++ system/Config/Services.php | 2 +- system/Router/RouteCollection.php | 45 ++++++-- .../system/Router/AutoRouterImprovedTest.php | 2 +- .../RouteCollectionReverseRouteTest.php | 2 +- tests/system/Router/RouteCollectionTest.php | 2 +- user_guide_src/source/changelogs/v4.3.3.rst | 15 +++ user_guide_src/source/incoming/routing.rst | 25 ++--- .../source/incoming/routing/045.php | 3 +- .../source/incoming/routing/046.php | 1 + .../source/incoming/routing/049.php | 4 + .../source/incoming/routing/050.php | 4 + .../source/incoming/routing/051.php | 3 + .../source/installation/upgrade_433.rst | 9 ++ .../source/tutorial/static_pages.rst | 5 +- .../source/tutorial/static_pages/003.php | 2 - 19 files changed, 299 insertions(+), 79 deletions(-) delete mode 100644 app/Config/Routes.php create mode 100644 app/Config/Routing.php create mode 100644 app/Routes.php create mode 100644 system/Config/Routing.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php deleted file mode 100644 index c251ec22c4b4..000000000000 --- a/app/Config/Routes.php +++ /dev/null @@ -1,49 +0,0 @@ -setDefaultNamespace('App\Controllers'); -$routes->setDefaultController('Home'); -$routes->setDefaultMethod('index'); -$routes->setTranslateURIDashes(false); -$routes->set404Override(); -// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps -// where controller filters or CSRF protection are bypassed. -// If you don't want to define all routes, please use the Auto Routing (Improved). -// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true. -// $routes->setAutoRoute(false); - -/* - * -------------------------------------------------------------------- - * Route Definitions - * -------------------------------------------------------------------- - */ - -// We get a performance increase by specifying the default -// route since we don't have to scan directories. -$routes->get('/', 'Home::index'); - -/* - * -------------------------------------------------------------------- - * Additional Routing - * -------------------------------------------------------------------- - * - * There will often be times that you need additional routing and you - * need it to be able to override any defaults in this file. Environment - * based routes is one such time. require() additional route files here - * to make that happen. - * - * You will have access to the $routes object within that file without - * needing to reload it. - */ -if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) { - require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'; -} diff --git a/app/Config/Routing.php b/app/Config/Routing.php new file mode 100644 index 000000000000..1fc1b4b81d9b --- /dev/null +++ b/app/Config/Routing.php @@ -0,0 +1,100 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Config; + +use CodeIgniter\Config\Routing as BaseRouting; + +/** + * Routing configuration + */ +class Routing extends BaseRouting +{ + /** + * The default namespace to use for Controllers when no other + * namespace has been specified. + * + * Default: 'App\Controllers' + */ + public string $defaultNamespace = 'App\Controllers'; + + /** + * The default controller to use when no other controller has been + * specified. + * + * Default: 'Home' + */ + public string $defaultController = 'Home'; + + /** + * The default method to call on the controller when no other + * method has been set in the route. + * + * Default: 'index' + */ + public string $defaultMethod = 'index'; + + /** + * Whether to translate dashes in URIs to underscores. + * Primarily useful when using the auto-routing. + * + * Default: false + */ + public bool $translateURIDashes = false; + + /** + * Sets the class/method that should be called if routing doesn't + * find a match. It can be either a closure or the controller/method + * name exactly like a route is defined: Users::index + * + * This setting is passed to the Router class and handled there. + * + * If you want to use a closure, you will have to set it in the + * class constructor or the routes file by calling: + * + * $routes->set404Override(function() { + * // Do something here + * }); + * + * Example: + * public $override404 = 'App\Errors::show404'; + */ + public $override404 = null; + + /** + * If TRUE, the system will attempt to match the URI against + * Controllers by matching each segment against folders/files + * in APPPATH/Controllers, when a match wasn't found against + * defined routes. + * + * If FALSE, will stop searching and do NO automatic routing. + */ + public bool $autoRoute = false; + + /** + * If TRUE, will enable the use of the 'prioritize' option + * when defining routes. + * + * Default: false + */ + public bool $prioritize = false; + + /** + * An array of files that contain route definitions. + * Route files are read in order, with the first match + * found taking precedence. + * + * Default: APPPATH . 'Config/Routes.php' + */ + public array $routeFiles = [ + APPPATH .DIRECTORY_SEPARATOR . 'Routes.php', + ]; +} diff --git a/app/Routes.php b/app/Routes.php new file mode 100644 index 000000000000..6e7170b8a4c1 --- /dev/null +++ b/app/Routes.php @@ -0,0 +1,7 @@ +get('/', 'Home::index'); diff --git a/system/Config/Routing.php b/system/Config/Routing.php new file mode 100644 index 000000000000..bf5249377a08 --- /dev/null +++ b/system/Config/Routing.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Config; + +/** + * Routing configuration + */ +class Routing extends BaseConfig +{ + /** + * The default namespace to use for Controllers when no other + * namespace has been specified. + * + * Default: 'App\Controllers' + */ + public string $defaultNamespace = 'App\Controllers'; + + /** + * The default controller to use when no other controller has been + * specified. + * + * Default: 'Home' + */ + public string $defaultController = 'Home'; + + /** + * The default method to call on the controller when no other + * method has been set in the route. + * + * Default: 'index' + */ + public string $defaultMethod = 'index'; + + /** + * Whether to translate dashes in URIs to underscores. + * Primarily useful when using the auto-routing. + * + * Default: false + */ + public bool $translateURIDashes = false; + + /** + * Sets the class/method that should be called if routing doesn't + * find a match. It can be either a closure or the controller/method + * name exactly like a route is defined: Users::index + * + * This setting is passed to the Router class and handled there. + * + * If you want to use a closure, you will have to set it in the + * class constructor or the routes file by calling: + * + * $routes->set404Override(function() { + * // Do something here + * }); + * + * Example: + * public $override404 = 'App\Errors::show404'; + */ + public $override404 = null; + + /** + * If TRUE, the system will attempt to match the URI against + * Controllers by matching each segment against folders/files + * in APPPATH/Controllers, when a match wasn't found against + * defined routes. + * + * If FALSE, will stop searching and do NO automatic routing. + */ + public bool $autoRoute = false; + + /** + * If TRUE, will enable the use of the 'prioritize' option + * when defining routes. + * + * Default: false + */ + public bool $prioritize = false; + + /** + * An array of files that contain route definitions. + * Route files are read in order, with the first match + * found taking precedence. + * + * Default: APPPATH . 'Config/Routes.php' + */ + public array $routeFiles = [ + APPPATH .DIRECTORY_SEPARATOR . 'Routes.php', + ]; +} diff --git a/system/Config/Services.php b/system/Config/Services.php index 2358e87bb1a5..161a6b112757 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -596,7 +596,7 @@ public static function routes(bool $getShared = true) return static::getSharedInstance('routes'); } - return new RouteCollection(AppServices::locator(), config('Modules')); + return new RouteCollection(AppServices::locator(), config('Modules'), config('Routing')); } /** diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 50b73616ea0e..49410803e776 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -16,6 +16,7 @@ use CodeIgniter\Router\Exceptions\RouterException; use Config\App; use Config\Modules; +use Config\Routing; use Config\Services; use InvalidArgumentException; use Locale; @@ -88,6 +89,12 @@ class RouteCollection implements RouteCollectionInterface */ protected $override404; + /** + * An array of files that would contain route definitions. + * @var array + */ + protected array $routeFiles = []; + /** * Defined placeholders that can be used * within the @@ -242,12 +249,22 @@ class RouteCollection implements RouteCollectionInterface /** * Constructor */ - public function __construct(FileLocator $locator, Modules $moduleConfig) + public function __construct(FileLocator $locator, Modules $moduleConfig, Routing $routing) { $this->fileLocator = $locator; $this->moduleConfig = $moduleConfig; $this->httpHost = Services::request()->getServer('HTTP_HOST'); + + // Setup based on config file. Let routes file override. + $this->defaultNamespace = $routing->defaultNamespace; + $this->defaultController = $routing->defaultController; + $this->defaultMethod = $routing->defaultMethod; + $this->translateURIDashes = $routing->translateURIDashes; + $this->override404 = $routing->override404; + $this->autoRoute = $routing->autoRoute; + $this->routeFiles = $routing->routeFiles; + $this->prioritize = $routing->prioritize; } /** @@ -263,8 +280,25 @@ public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php') return $this; } + // Include the passed in routesFile if it doesn't exist. + // Only keeping that around for BC purposes for now. + $routeFiles = $this->routeFiles; + if (! in_array($routesFile, $routeFiles, true)) { + $routeFiles[] = $routesFile; + } + + // We need this var in local scope + // so route files can access it. $routes = $this; - require $routesFile; + + foreach($routeFiles as $routesFile) { + if (! is_file($routesFile)) { + log_message('warning', 'Routes file not found: ' . $routesFile . '.'); + continue; + } + + require $routesFile; + } $this->discoverRoutes(); @@ -288,14 +322,9 @@ protected function discoverRoutes() if ($this->moduleConfig->shouldDiscover('routes')) { $files = $this->fileLocator->search('Config/Routes.php'); - $excludes = [ - APPPATH . 'Config' . DIRECTORY_SEPARATOR . 'Routes.php', - SYSTEMPATH . 'Config' . DIRECTORY_SEPARATOR . 'Routes.php', - ]; - foreach ($files as $file) { // Don't include our main file again... - if (in_array($file, $excludes, true)) { + if (in_array($file, $this->routeFiles, true)) { continue; } diff --git a/tests/system/Router/AutoRouterImprovedTest.php b/tests/system/Router/AutoRouterImprovedTest.php index ab1fa7db2188..a460cfdfd56c 100644 --- a/tests/system/Router/AutoRouterImprovedTest.php +++ b/tests/system/Router/AutoRouterImprovedTest.php @@ -35,7 +35,7 @@ protected function setUp(): void $moduleConfig = new Modules(); $moduleConfig->enabled = false; - $this->collection = new RouteCollection(Services::locator(), $moduleConfig); + $this->collection = new RouteCollection(Services::locator(), $moduleConfig, new \Config\Routing()); } private function createNewAutoRouter(string $httpVerb = 'get'): AutoRouterImproved diff --git a/tests/system/Router/RouteCollectionReverseRouteTest.php b/tests/system/Router/RouteCollectionReverseRouteTest.php index 2e6de5aacdf7..a5ac40e47cfa 100644 --- a/tests/system/Router/RouteCollectionReverseRouteTest.php +++ b/tests/system/Router/RouteCollectionReverseRouteTest.php @@ -49,7 +49,7 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $moduleConfig->enabled = false; } - return (new RouteCollection($loader, $moduleConfig))->setHTTPVerb('get'); + return (new RouteCollection($loader, $moduleConfig, new \Config\Routing()))->setHTTPVerb('get'); } public function testReverseRoutingFindsSimpleMatch() diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 6458449a02c9..abb2feb2e4f4 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -49,7 +49,7 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $moduleConfig->enabled = false; } - return (new RouteCollection($loader, $moduleConfig))->setHTTPVerb('get'); + return (new RouteCollection($loader, $moduleConfig, new \Config\Routing()))->setHTTPVerb('get'); } public function testBasicAdd() diff --git a/user_guide_src/source/changelogs/v4.3.3.rst b/user_guide_src/source/changelogs/v4.3.3.rst index cd9d3fc31a40..3d0c48249ffc 100644 --- a/user_guide_src/source/changelogs/v4.3.3.rst +++ b/user_guide_src/source/changelogs/v4.3.3.rst @@ -16,6 +16,21 @@ SECURITY - **Text Helper:** The :php:func:`random_string()` type **alpha**, **alnum**, **numeric** and **nozero** are now cryptographically secure. +BREAKING +******** + +Message Changes +*************** + +Changes +******* + +- **Config:** Routing settings have been moved to ``Config\Routing`` config file. +- The default location for new projects Routes.php file has been moved to `app/Routes.php`. This can be modified in the `Config/Routing.php` file. + +Deprecations +************ + Bugs Fixed ********** diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index e11dee96c818..cee4c6ba672a 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -22,7 +22,7 @@ First, let's look at Defined Route Routing. If you want to use Auto Routing, see Setting Routing Rules ********************* -Routing rules are defined in the **app/Config/Routes.php** file. In it you'll see that +Routing rules are defined in the **app/Routes.php** file. In it you'll see that it creates an instance of the RouteCollection class (``$routes``) that permits you to specify your own routing criteria. Routes can be specified using placeholders or Regular Expressions. @@ -408,7 +408,7 @@ The value for the filter can be a string or an array of strings: See :doc:`Controller Filters ` for more information on setting up filters. -.. Warning:: If you set filters to routes in **app/Config/Routes.php** +.. Warning:: If you set filters to routes in **app/Routes.php** (not in **app/Config/Filters.php**), it is recommended to disable Auto Routing (Legacy). When :ref:`auto-routing-legacy` is enabled, it may be possible that a controller can be accessed via a different URL than the configured route, @@ -545,7 +545,7 @@ Routes Configuration Options **************************** The RoutesCollection class provides several options that affect all routes, and can be modified to meet your -application's needs. These options are available at the top of **app/Config/Routes.php**. +application's needs. These options are available in **app/Config/Routing.php**. .. _routing-default-namespace: @@ -569,8 +569,7 @@ Translate URI Dashes ==================== This option enables you to automatically replace dashes (``-``) with underscores in the controller and method -URI segments, thus saving you additional route entries if you need to do that. This is required because the -dash isn't a valid class or method name character and would cause a fatal error if you try to use it: +URI segments when used in Auto Routing, thus saving you additional route entries if you need to do that. This is required because the dash isn't a valid class or method name character and would cause a fatal error if you try to use it: .. literalinclude:: routing/049.php @@ -585,7 +584,7 @@ When no defined route is found that matches the URI, the system will attempt to controllers and methods when Auto Routing is enabled. You can disable this automatic matching, and restrict routes -to only those defined by you, by setting the ``setAutoRoute()`` option to false: +to only those defined by you, by setting the ``$autoRoute`` option to false: .. literalinclude:: routing/050.php @@ -601,6 +600,8 @@ a valid class/method pair, just like you would show in any route, or a Closure: .. literalinclude:: routing/051.php +Using the ``set404Override`` method within the routes file, you can use closures. Defining the override in the Routing file is restricted to class/method pairs. + .. note:: The ``set404Override()`` method does not change the Response status code to ``404``. If you don't set the status code in the controller you set, the default status code ``200`` will be returned. See :php:meth:`CodeIgniter\\HTTP\\Response::setStatusCode()` for @@ -642,9 +643,9 @@ and execute the corresponding controller methods. Enable Auto Routing =================== -To use it, you need to change the setting ``setAutoRoute()`` option to true in **app/Config/Routes.php**:: +To use it, you need to change the setting ``$autoRoute`` option to true in **app/Config/Routing.php**:: - $routes->setAutoRoute(true); + public bool $autoRoute = true; And you need to change the property ``$autoRoutesImproved`` to ``true`` in **app/Config/Feature.php**:: @@ -676,7 +677,7 @@ See :ref:`Auto Routing in Controllers ` for mo Configuration Options ===================== -These options are available at the top of **app/Config/Routes.php**. +These options are available at the top of **app/Routes.php**. Default Controller ------------------ @@ -719,7 +720,7 @@ Auto Routing (Legacy) Auto Routing (Legacy) is a routing system from CodeIgniter 3. It can automatically route HTTP requests based on conventions and execute the corresponding controller methods. -It is recommended that all routes are defined in the **app/Config/Routes.php** file, +It is recommended that all routes are defined in the **app/Routes.php** file, or to use :ref:`auto-routing-improved`, .. warning:: To prevent misconfiguration and miscoding, we recommend that you do not use @@ -733,7 +734,7 @@ Enable Auto Routing (Legacy) Since v4.2.0, the auto-routing is disabled by default. -To use it, you need to change the setting ``setAutoRoute()`` option to true in **app/Config/Routes.php**:: +To use it, you need to change the setting ``setAutoRoute()`` option to true in **app/Routes.php**:: $routes->setAutoRoute(true); @@ -760,7 +761,7 @@ See :ref:`Auto Routing (Legacy) in Controllers ` Configuration Options (Legacy) ============================== -These options are available at the top of **app/Config/Routes.php**. +These options are available at the top of **app/Routes.php**. Default Controller (Legacy) --------------------------- diff --git a/user_guide_src/source/incoming/routing/045.php b/user_guide_src/source/incoming/routing/045.php index 98aef9276f9d..f20d34a40681 100644 --- a/user_guide_src/source/incoming/routing/045.php +++ b/user_guide_src/source/incoming/routing/045.php @@ -1,6 +1,7 @@ setDefaultNamespace(''); +// In app/Config/Routing.php +public string $defaultNamespace = ''; // Controller is \Users $routes->get('users', 'Users::index'); diff --git a/user_guide_src/source/incoming/routing/046.php b/user_guide_src/source/incoming/routing/046.php index fbbbee2300df..8998fe70c039 100644 --- a/user_guide_src/source/incoming/routing/046.php +++ b/user_guide_src/source/incoming/routing/046.php @@ -1,5 +1,6 @@ setDefaultNamespace('App'); // Controller is \App\Users diff --git a/user_guide_src/source/incoming/routing/049.php b/user_guide_src/source/incoming/routing/049.php index 31d49508ab86..57bee07fcb67 100644 --- a/user_guide_src/source/incoming/routing/049.php +++ b/user_guide_src/source/incoming/routing/049.php @@ -1,3 +1,7 @@ setTranslateURIDashes(true); diff --git a/user_guide_src/source/incoming/routing/050.php b/user_guide_src/source/incoming/routing/050.php index c331102cd9f4..8133cf77b7f1 100644 --- a/user_guide_src/source/incoming/routing/050.php +++ b/user_guide_src/source/incoming/routing/050.php @@ -1,3 +1,7 @@ setAutoRoute(false); diff --git a/user_guide_src/source/incoming/routing/051.php b/user_guide_src/source/incoming/routing/051.php index dddd067f0f26..098d85178575 100644 --- a/user_guide_src/source/incoming/routing/051.php +++ b/user_guide_src/source/incoming/routing/051.php @@ -1,5 +1,8 @@ set404Override('App\Errors::show404'); diff --git a/user_guide_src/source/installation/upgrade_433.rst b/user_guide_src/source/installation/upgrade_433.rst index 5e86a9737767..e7f830d7d5a7 100644 --- a/user_guide_src/source/installation/upgrade_433.rst +++ b/user_guide_src/source/installation/upgrade_433.rst @@ -27,6 +27,15 @@ Content Changes The following files received significant changes (including deprecations or visual adjustments) and it is recommended that you merge the updated versions with your application: +Routing +------- + +To clean up the routing system, the following changes were made: + - New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file. + - The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file. + - The ``app/Config/Routes.php`` file was moved to ``app/Routes.php`` to make it easier to find. When upgrading, you can change the ``app/Config/Routing.php` file, ``$routeFiles`` property to point to the old location if you prefer. + - The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``. + Config ------ diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index 926ed09603c7..37c6121129de 100644 --- a/user_guide_src/source/tutorial/static_pages.rst +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -136,10 +136,9 @@ We have made the controller. The next thing is to set routing rules. Routing associates a URI with a controller's method. Let's do that. Open the routing file located at -**app/Config/Routes.php** and look for the "Route Definitions" -section of the configuration file. +**app/Routes.php**. -The only uncommented line there to start with should be: +The only line there to start with should be: .. literalinclude:: static_pages/003.php diff --git a/user_guide_src/source/tutorial/static_pages/003.php b/user_guide_src/source/tutorial/static_pages/003.php index 956c097d390f..bf0466ca2192 100644 --- a/user_guide_src/source/tutorial/static_pages/003.php +++ b/user_guide_src/source/tutorial/static_pages/003.php @@ -2,8 +2,6 @@ // ... -// We get a performance increase by specifying the default -// route since we don't have to scan directories. $routes->get('/', 'Home::index'); // ... From 481c2f983ac233bae492efe6d53c98e65e762e57 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Sat, 25 Mar 2023 00:09:02 -0500 Subject: [PATCH 02/22] refactor: Clean up routes file to be just for routes. Moved route settings to new Routing config file. --- app/Config/Routing.php | 22 ++++++++++----------- system/Config/Routing.php | 22 ++++++++++----------- system/Router/RouteCollection.php | 2 +- tests/system/Router/RouteCollectionTest.php | 5 ++++- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/app/Config/Routing.php b/app/Config/Routing.php index 1fc1b4b81d9b..2cf88bf9b29b 100644 --- a/app/Config/Routing.php +++ b/app/Config/Routing.php @@ -18,6 +18,17 @@ */ class Routing extends BaseRouting { + /** + * An array of files that contain route definitions. + * Route files are read in order, with the first match + * found taking precedence. + * + * Default: APPPATH . 'Config/Routes.php' + */ + public array $routeFiles = [ + APPPATH . 'Routes.php', + ]; + /** * The default namespace to use for Controllers when no other * namespace has been specified. @@ -86,15 +97,4 @@ class Routing extends BaseRouting * Default: false */ public bool $prioritize = false; - - /** - * An array of files that contain route definitions. - * Route files are read in order, with the first match - * found taking precedence. - * - * Default: APPPATH . 'Config/Routes.php' - */ - public array $routeFiles = [ - APPPATH .DIRECTORY_SEPARATOR . 'Routes.php', - ]; } diff --git a/system/Config/Routing.php b/system/Config/Routing.php index bf5249377a08..580e555d202d 100644 --- a/system/Config/Routing.php +++ b/system/Config/Routing.php @@ -16,6 +16,17 @@ */ class Routing extends BaseConfig { + /** + * An array of files that contain route definitions. + * Route files are read in order, with the first match + * found taking precedence. + * + * Default: APPPATH . 'Config/Routes.php' + */ + public array $routeFiles = [ + APPPATH . 'Routes.php', + ]; + /** * The default namespace to use for Controllers when no other * namespace has been specified. @@ -84,15 +95,4 @@ class Routing extends BaseConfig * Default: false */ public bool $prioritize = false; - - /** - * An array of files that contain route definitions. - * Route files are read in order, with the first match - * found taking precedence. - * - * Default: APPPATH . 'Config/Routes.php' - */ - public array $routeFiles = [ - APPPATH .DIRECTORY_SEPARATOR . 'Routes.php', - ]; } diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 49410803e776..b5f06d936713 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -274,7 +274,7 @@ public function __construct(FileLocator $locator, Modules $moduleConfig, Routing * * @return $this */ - public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php') + public function loadRoutes(string $routesFile = APPPATH . 'Routes.php') { if ($this->didDiscover) { return $this; diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index abb2feb2e4f4..3802d067200d 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -49,7 +49,10 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $moduleConfig->enabled = false; } - return (new RouteCollection($loader, $moduleConfig, new \Config\Routing()))->setHTTPVerb('get'); + $routerConfig = new \Config\Routing(); + $routerConfig->defaultNamespace = '\\'; + + return (new RouteCollection($loader, $moduleConfig, $routerConfig))->setHTTPVerb('get'); } public function testBasicAdd() From 31138abda5aaf45a05c8e25eca6ece237548f79f Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Sat, 25 Mar 2023 00:24:38 -0500 Subject: [PATCH 03/22] Fixing style issues --- app/Config/Routing.php | 2 +- app/Routes.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Config/Routing.php b/app/Config/Routing.php index 2cf88bf9b29b..f6163000efdb 100644 --- a/app/Config/Routing.php +++ b/app/Config/Routing.php @@ -78,7 +78,7 @@ class Routing extends BaseRouting * Example: * public $override404 = 'App\Errors::show404'; */ - public $override404 = null; + public $override404; /** * If TRUE, the system will attempt to match the URI against diff --git a/app/Routes.php b/app/Routes.php index 6e7170b8a4c1..4fb22a2e358c 100644 --- a/app/Routes.php +++ b/app/Routes.php @@ -3,5 +3,4 @@ /** * @var \CodeIgniter\Router\RouteCollection $routes */ - $routes->get('/', 'Home::index'); From e37c2c616396f01cc2a8cb7a35438de58d81b653 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Sat, 25 Mar 2023 00:31:05 -0500 Subject: [PATCH 04/22] More style fixes --- system/Config/Routing.php | 2 +- system/Router/RouteCollection.php | 4 ++-- tests/system/Router/RouteCollectionTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Config/Routing.php b/system/Config/Routing.php index 580e555d202d..857a27769215 100644 --- a/system/Config/Routing.php +++ b/system/Config/Routing.php @@ -76,7 +76,7 @@ class Routing extends BaseConfig * Example: * public $override404 = 'App\Errors::show404'; */ - public $override404 = null; + public $override404; /** * If TRUE, the system will attempt to match the URI against diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index b5f06d936713..9962bb23e11c 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -91,7 +91,6 @@ class RouteCollection implements RouteCollectionInterface /** * An array of files that would contain route definitions. - * @var array */ protected array $routeFiles = []; @@ -291,9 +290,10 @@ public function loadRoutes(string $routesFile = APPPATH . 'Routes.php') // so route files can access it. $routes = $this; - foreach($routeFiles as $routesFile) { + foreach ($routeFiles as $routesFile) { if (! is_file($routesFile)) { log_message('warning', 'Routes file not found: ' . $routesFile . '.'); + continue; } diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 3802d067200d..e298ea723b08 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -49,7 +49,7 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $moduleConfig->enabled = false; } - $routerConfig = new \Config\Routing(); + $routerConfig = new \Config\Routing(); $routerConfig->defaultNamespace = '\\'; return (new RouteCollection($loader, $moduleConfig, $routerConfig))->setHTTPVerb('get'); From ec0da198627a277f8873bd13ffe970e43e72b470 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Fri, 31 Mar 2023 22:34:24 -0500 Subject: [PATCH 05/22] Allow specifying the location of Routing files within modules. --- system/Config/Routing.php | 10 ++++++++++ system/Router/RouteCollection.php | 14 +++++++++++++- tests/system/Router/RouteCollectionTest.php | 1 + tests/system/Router/RouterTest.php | 7 ++++++- user_guide_src/source/general/modules.rst | 2 ++ user_guide_src/source/installation/upgrade_433.rst | 1 + 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/system/Config/Routing.php b/system/Config/Routing.php index 857a27769215..158a7db3c66f 100644 --- a/system/Config/Routing.php +++ b/system/Config/Routing.php @@ -27,6 +27,16 @@ class Routing extends BaseConfig APPPATH . 'Routes.php', ]; + /** + * When discovering routes within "modules", or namespaces other + * than "App", this is the path relative to the module's root + * directory. + * + * Default: 'Routes.php' + * Legacy: 'Config/Routes.php' + */ + public string $modulePath = 'Routes.php'; + /** * The default namespace to use for Controllers when no other * namespace has been specified. diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 9962bb23e11c..c8650c217a84 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -94,6 +94,12 @@ class RouteCollection implements RouteCollectionInterface */ protected array $routeFiles = []; + /** + * The path to the file that contains + * the route definitions within "modules". + */ + protected string $modulePath; + /** * Defined placeholders that can be used * within the @@ -263,6 +269,7 @@ public function __construct(FileLocator $locator, Modules $moduleConfig, Routing $this->override404 = $routing->override404; $this->autoRoute = $routing->autoRoute; $this->routeFiles = $routing->routeFiles; + $this->modulePath = $routing->modulePath; $this->prioritize = $routing->prioritize; } @@ -320,7 +327,12 @@ protected function discoverRoutes() $routes = $this; if ($this->moduleConfig->shouldDiscover('routes')) { - $files = $this->fileLocator->search('Config/Routes.php'); + if (empty($this->modulePath)) { + log_message('warning', 'Routes module path is not set in Config/Routing.php.'); + return; + } + + $files = $this->fileLocator->search($this->modulePath); foreach ($files as $file) { // Don't include our main file again... diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index e298ea723b08..bfe5378b60d0 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -51,6 +51,7 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $routerConfig = new \Config\Routing(); $routerConfig->defaultNamespace = '\\'; + $routerConfig->modulePath = 'Config/Routes.php'; return (new RouteCollection($loader, $moduleConfig, $routerConfig))->setHTTPVerb('get'); } diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index 5be01a47bfc6..9cf8c90bb9a7 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -36,7 +36,12 @@ protected function setUp(): void $moduleConfig = new Modules(); $moduleConfig->enabled = false; - $this->collection = new RouteCollection(Services::locator(), $moduleConfig); + + $routerConfig = new \Config\Routing(); + $routerConfig->defaultNamespace = '\\'; + $routerConfig->modulePath = 'Config/Routes.php'; + + $this->collection = new RouteCollection(Services::locator(), $moduleConfig, $routerConfig); $routes = [ '/' => 'Home::index', diff --git a/user_guide_src/source/general/modules.rst b/user_guide_src/source/general/modules.rst index 2298c32a986f..40831cb76121 100644 --- a/user_guide_src/source/general/modules.rst +++ b/user_guide_src/source/general/modules.rst @@ -154,6 +154,8 @@ the **Modules** config file, described above. When working with modules, it can be a problem if the routes in the application contain wildcards. In that case, see :ref:`routing-priority`. +By default, route files are named **Routes.php** and are located in the root directory of the module. You can change this by setting the ``$modulePath`` variable in the **Routing** config file to path to the file, relative to the module's root directory. For example, if you wanted to put your routes in a file named **Routes.php** in the module's ``Config`` directory, you would set the ``$modulePath`` variable to ``Config/Routes.php``. + Filters ======= diff --git a/user_guide_src/source/installation/upgrade_433.rst b/user_guide_src/source/installation/upgrade_433.rst index e7f830d7d5a7..4b32c01433d3 100644 --- a/user_guide_src/source/installation/upgrade_433.rst +++ b/user_guide_src/source/installation/upgrade_433.rst @@ -34,6 +34,7 @@ To clean up the routing system, the following changes were made: - New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file. - The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file. - The ``app/Config/Routes.php`` file was moved to ``app/Routes.php`` to make it easier to find. When upgrading, you can change the ``app/Config/Routing.php` file, ``$routeFiles`` property to point to the old location if you prefer. + - Any module ``Routes.php`` files are expected to be in the namespace's root directory now. To adjust this to match the functionality of existing projects, you can cahnge the ``$modulePath`` property in ``app/Config/Routing.php`` to ``'Config/Routes.php'``. - The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``. Config From 520a0a23789672ee9b9dc4e92c49879c162f2325 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Fri, 31 Mar 2023 23:19:03 -0500 Subject: [PATCH 06/22] Change user guide changes to 4.4 --- user_guide_src/source/changelogs/v4.3.3.rst | 3 --- user_guide_src/source/changelogs/v4.4.0.rst | 2 ++ user_guide_src/source/installation/upgrade_433.rst | 10 ---------- user_guide_src/source/installation/upgrade_440.rst | 10 ++++++++++ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.3.3.rst b/user_guide_src/source/changelogs/v4.3.3.rst index 3d0c48249ffc..1430cf767aea 100644 --- a/user_guide_src/source/changelogs/v4.3.3.rst +++ b/user_guide_src/source/changelogs/v4.3.3.rst @@ -25,9 +25,6 @@ Message Changes Changes ******* -- **Config:** Routing settings have been moved to ``Config\Routing`` config file. -- The default location for new projects Routes.php file has been moved to `app/Routes.php`. This can be modified in the `Config/Routing.php` file. - Deprecations ************ diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index 503922b418e2..74c59205ddb4 100644 --- a/user_guide_src/source/changelogs/v4.4.0.rst +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -104,6 +104,8 @@ Changes So if you installed CodeIgniter under the folder that contains the special characters like ``(``, ``)``, etc., CodeIgniter didn't work. Since v4.4.0, this restriction has been removed. +- **Config:** Routing settings have been moved to ``Config\Routing`` config file. +- The default location for new projects Routes.php file has been moved to `app/Routes.php`. This can be modified in the `Config/Routing.php` file. Deprecations ************ diff --git a/user_guide_src/source/installation/upgrade_433.rst b/user_guide_src/source/installation/upgrade_433.rst index 4b32c01433d3..5e86a9737767 100644 --- a/user_guide_src/source/installation/upgrade_433.rst +++ b/user_guide_src/source/installation/upgrade_433.rst @@ -27,16 +27,6 @@ Content Changes The following files received significant changes (including deprecations or visual adjustments) and it is recommended that you merge the updated versions with your application: -Routing -------- - -To clean up the routing system, the following changes were made: - - New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file. - - The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file. - - The ``app/Config/Routes.php`` file was moved to ``app/Routes.php`` to make it easier to find. When upgrading, you can change the ``app/Config/Routing.php` file, ``$routeFiles`` property to point to the old location if you prefer. - - Any module ``Routes.php`` files are expected to be in the namespace's root directory now. To adjust this to match the functionality of existing projects, you can cahnge the ``$modulePath`` property in ``app/Config/Routing.php`` to ``'Config/Routes.php'``. - - The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``. - Config ------ diff --git a/user_guide_src/source/installation/upgrade_440.rst b/user_guide_src/source/installation/upgrade_440.rst index f5bc7aef91f2..4e2ec61c5f7d 100644 --- a/user_guide_src/source/installation/upgrade_440.rst +++ b/user_guide_src/source/installation/upgrade_440.rst @@ -62,6 +62,16 @@ Content Changes The following files received significant changes (including deprecations or visual adjustments) and it is recommended that you merge the updated versions with your application: +Routing +------- + +To clean up the routing system, the following changes were made: + - New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file. + - The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file. + - The ``app/Config/Routes.php`` file was moved to ``app/Routes.php`` to make it easier to find. When upgrading, you can change the ``app/Config/Routing.php` file, ``$routeFiles`` property to point to the old location if you prefer. + - Any module ``Routes.php`` files are expected to be in the namespace's root directory now. To adjust this to match the functionality of existing projects, you can cahnge the ``$modulePath`` property in ``app/Config/Routing.php`` to ``'Config/Routes.php'``. + - The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``. + Config ------ From 0604b40afa1db535a7ed9c5cb272ffecd18fefaa Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Mon, 3 Apr 2023 23:10:55 -0500 Subject: [PATCH 07/22] Move routes files back to Config folder for now, and drop the modulesPath config setting. --- app/{ => Config}/Routes.php | 0 app/Config/Routing.php | 2 +- system/Config/Routing.php | 10 ---------- system/Router/RouteCollection.php | 14 +------------- .../Commands/Utilities/Routes/FilterFinderTest.php | 3 ++- tests/system/Router/RouteCollectionTest.php | 1 - tests/system/Router/RouterTest.php | 1 - user_guide_src/source/changelogs/v4.4.0.rst | 1 - user_guide_src/source/general/modules.rst | 2 -- user_guide_src/source/installation/upgrade_440.rst | 1 - 10 files changed, 4 insertions(+), 31 deletions(-) rename app/{ => Config}/Routes.php (100%) diff --git a/app/Routes.php b/app/Config/Routes.php similarity index 100% rename from app/Routes.php rename to app/Config/Routes.php diff --git a/app/Config/Routing.php b/app/Config/Routing.php index f6163000efdb..73d9a93f0f4b 100644 --- a/app/Config/Routing.php +++ b/app/Config/Routing.php @@ -26,7 +26,7 @@ class Routing extends BaseRouting * Default: APPPATH . 'Config/Routes.php' */ public array $routeFiles = [ - APPPATH . 'Routes.php', + APPPATH . 'Config/Routes.php', ]; /** diff --git a/system/Config/Routing.php b/system/Config/Routing.php index 158a7db3c66f..857a27769215 100644 --- a/system/Config/Routing.php +++ b/system/Config/Routing.php @@ -27,16 +27,6 @@ class Routing extends BaseConfig APPPATH . 'Routes.php', ]; - /** - * When discovering routes within "modules", or namespaces other - * than "App", this is the path relative to the module's root - * directory. - * - * Default: 'Routes.php' - * Legacy: 'Config/Routes.php' - */ - public string $modulePath = 'Routes.php'; - /** * The default namespace to use for Controllers when no other * namespace has been specified. diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index c8650c217a84..9962bb23e11c 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -94,12 +94,6 @@ class RouteCollection implements RouteCollectionInterface */ protected array $routeFiles = []; - /** - * The path to the file that contains - * the route definitions within "modules". - */ - protected string $modulePath; - /** * Defined placeholders that can be used * within the @@ -269,7 +263,6 @@ public function __construct(FileLocator $locator, Modules $moduleConfig, Routing $this->override404 = $routing->override404; $this->autoRoute = $routing->autoRoute; $this->routeFiles = $routing->routeFiles; - $this->modulePath = $routing->modulePath; $this->prioritize = $routing->prioritize; } @@ -327,12 +320,7 @@ protected function discoverRoutes() $routes = $this; if ($this->moduleConfig->shouldDiscover('routes')) { - if (empty($this->modulePath)) { - log_message('warning', 'Routes module path is not set in Config/Routing.php.'); - return; - } - - $files = $this->fileLocator->search($this->modulePath); + $files = $this->fileLocator->search('Config/Routes.php'); foreach ($files as $file) { // Don't include our main file again... diff --git a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php index ace71d9d7e2d..91d73153dc2d 100644 --- a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php +++ b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Commands\Utilities\Routes; +use Config\Routing; use CodeIgniter\Config\Services; use CodeIgniter\Filters\CSRF; use CodeIgniter\Filters\DebugToolbar; @@ -52,7 +53,7 @@ protected function setUp(): void private function createRouteCollection(array $routes = []): RouteCollection { - $collection = new RouteCollection(Services::locator(), $this->moduleConfig); + $collection = new RouteCollection(Services::locator(), $this->moduleConfig, new Routing()); $routes = ($routes !== []) ? $routes : [ 'users' => 'Users::index', diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index bfe5378b60d0..e298ea723b08 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -51,7 +51,6 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $routerConfig = new \Config\Routing(); $routerConfig->defaultNamespace = '\\'; - $routerConfig->modulePath = 'Config/Routes.php'; return (new RouteCollection($loader, $moduleConfig, $routerConfig))->setHTTPVerb('get'); } diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index 9cf8c90bb9a7..35a5abc939ea 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -39,7 +39,6 @@ protected function setUp(): void $routerConfig = new \Config\Routing(); $routerConfig->defaultNamespace = '\\'; - $routerConfig->modulePath = 'Config/Routes.php'; $this->collection = new RouteCollection(Services::locator(), $moduleConfig, $routerConfig); diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index 74c59205ddb4..7352347b821a 100644 --- a/user_guide_src/source/changelogs/v4.4.0.rst +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -105,7 +105,6 @@ Changes characters like ``(``, ``)``, etc., CodeIgniter didn't work. Since v4.4.0, this restriction has been removed. - **Config:** Routing settings have been moved to ``Config\Routing`` config file. -- The default location for new projects Routes.php file has been moved to `app/Routes.php`. This can be modified in the `Config/Routing.php` file. Deprecations ************ diff --git a/user_guide_src/source/general/modules.rst b/user_guide_src/source/general/modules.rst index 40831cb76121..2298c32a986f 100644 --- a/user_guide_src/source/general/modules.rst +++ b/user_guide_src/source/general/modules.rst @@ -154,8 +154,6 @@ the **Modules** config file, described above. When working with modules, it can be a problem if the routes in the application contain wildcards. In that case, see :ref:`routing-priority`. -By default, route files are named **Routes.php** and are located in the root directory of the module. You can change this by setting the ``$modulePath`` variable in the **Routing** config file to path to the file, relative to the module's root directory. For example, if you wanted to put your routes in a file named **Routes.php** in the module's ``Config`` directory, you would set the ``$modulePath`` variable to ``Config/Routes.php``. - Filters ======= diff --git a/user_guide_src/source/installation/upgrade_440.rst b/user_guide_src/source/installation/upgrade_440.rst index 4e2ec61c5f7d..47dbb1a4a0ef 100644 --- a/user_guide_src/source/installation/upgrade_440.rst +++ b/user_guide_src/source/installation/upgrade_440.rst @@ -69,7 +69,6 @@ To clean up the routing system, the following changes were made: - New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file. - The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file. - The ``app/Config/Routes.php`` file was moved to ``app/Routes.php`` to make it easier to find. When upgrading, you can change the ``app/Config/Routing.php` file, ``$routeFiles`` property to point to the old location if you prefer. - - Any module ``Routes.php`` files are expected to be in the namespace's root directory now. To adjust this to match the functionality of existing projects, you can cahnge the ``$modulePath`` property in ``app/Config/Routing.php`` to ``'Config/Routes.php'``. - The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``. Config From b2ae0cc4e67109ac382494a6d80b6ab2fe04859b Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Mon, 3 Apr 2023 23:20:14 -0500 Subject: [PATCH 08/22] Code quality improvements --- app/Config/Routes.php | 4 +++- tests/system/Commands/Utilities/Routes/FilterFinderTest.php | 2 +- tests/system/Router/AutoRouterImprovedTest.php | 3 ++- tests/system/Router/RouteCollectionReverseRouteTest.php | 3 ++- tests/system/Router/RouteCollectionTest.php | 3 ++- tests/system/Router/RouterTest.php | 5 +++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4fb22a2e358c..fc4914a6923b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -1,6 +1,8 @@ get('/', 'Home::index'); diff --git a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php index 91d73153dc2d..9829e36a490a 100644 --- a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php +++ b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php @@ -11,7 +11,6 @@ namespace CodeIgniter\Commands\Utilities\Routes; -use Config\Routing; use CodeIgniter\Config\Services; use CodeIgniter\Filters\CSRF; use CodeIgniter\Filters\DebugToolbar; @@ -26,6 +25,7 @@ use CodeIgniter\Test\ConfigFromArrayTrait; use Config\Filters as FiltersConfig; use Config\Modules; +use Config\Routing; /** * @internal diff --git a/tests/system/Router/AutoRouterImprovedTest.php b/tests/system/Router/AutoRouterImprovedTest.php index a460cfdfd56c..d6560e1eb9e6 100644 --- a/tests/system/Router/AutoRouterImprovedTest.php +++ b/tests/system/Router/AutoRouterImprovedTest.php @@ -19,6 +19,7 @@ use CodeIgniter\Router\Controllers\Mycontroller; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; +use Config\Routing; /** * @internal @@ -35,7 +36,7 @@ protected function setUp(): void $moduleConfig = new Modules(); $moduleConfig->enabled = false; - $this->collection = new RouteCollection(Services::locator(), $moduleConfig, new \Config\Routing()); + $this->collection = new RouteCollection(Services::locator(), $moduleConfig, new Routing()); } private function createNewAutoRouter(string $httpVerb = 'get'): AutoRouterImproved diff --git a/tests/system/Router/RouteCollectionReverseRouteTest.php b/tests/system/Router/RouteCollectionReverseRouteTest.php index a5ac40e47cfa..12350edbb8ff 100644 --- a/tests/system/Router/RouteCollectionReverseRouteTest.php +++ b/tests/system/Router/RouteCollectionReverseRouteTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Router\Exceptions\RouterException; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; +use Config\Routing; use Generator; /** @@ -49,7 +50,7 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $moduleConfig->enabled = false; } - return (new RouteCollection($loader, $moduleConfig, new \Config\Routing()))->setHTTPVerb('get'); + return (new RouteCollection($loader, $moduleConfig, new Routing()))->setHTTPVerb('get'); } public function testReverseRoutingFindsSimpleMatch() diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index e298ea723b08..be5ecd4f2287 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; +use Config\Routing; use Tests\Support\Controllers\Hello; /** @@ -49,7 +50,7 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $moduleConfig->enabled = false; } - $routerConfig = new \Config\Routing(); + $routerConfig = new Routing(); $routerConfig->defaultNamespace = '\\'; return (new RouteCollection($loader, $moduleConfig, $routerConfig))->setHTTPVerb('get'); diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index 35a5abc939ea..2898f154716e 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -18,6 +18,7 @@ use CodeIgniter\Router\Exceptions\RouterException; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; +use Config\Routing; use Tests\Support\Filters\Customfilter; /** @@ -37,10 +38,10 @@ protected function setUp(): void $moduleConfig = new Modules(); $moduleConfig->enabled = false; - $routerConfig = new \Config\Routing(); + $routerConfig = new Routing(); $routerConfig->defaultNamespace = '\\'; - $this->collection = new RouteCollection(Services::locator(), $moduleConfig, $routerConfig); + $this->collection = new RouteCollection(Services::locator(), $moduleConfig, $routerConfig); $routes = [ '/' => 'Home::index', From 79bc6617a33aca2c260ece35f8e5033265b6a40c Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Wed, 5 Apr 2023 09:07:05 -0500 Subject: [PATCH 09/22] Updating doc code samples and CodeIgniter test --- tests/system/CodeIgniterTest.php | 3 ++- user_guide_src/source/incoming/routing/049.php | 2 +- user_guide_src/source/incoming/routing/050.php | 2 +- user_guide_src/source/incoming/routing/051.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index a7f5b9bd1908..f01986553e83 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -22,6 +22,7 @@ use Config\Cache; use Config\Filters as FiltersConfig; use Config\Modules; +use Config\Routing; use Tests\Support\Filters\Customfilter; /** @@ -165,7 +166,7 @@ public function testRun404OverrideByClosure() $_SERVER['argc'] = 2; // Inject mock router. - $routes = new RouteCollection(Services::locator(), new Modules()); + $routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); $routes->setAutoRoute(false); $routes->set404Override(static function () { echo '404 Override by Closure.'; diff --git a/user_guide_src/source/incoming/routing/049.php b/user_guide_src/source/incoming/routing/049.php index 57bee07fcb67..dd276e95316f 100644 --- a/user_guide_src/source/incoming/routing/049.php +++ b/user_guide_src/source/incoming/routing/049.php @@ -1,7 +1,7 @@ setTranslateURIDashes(true); diff --git a/user_guide_src/source/incoming/routing/050.php b/user_guide_src/source/incoming/routing/050.php index 8133cf77b7f1..dc24bfe41416 100644 --- a/user_guide_src/source/incoming/routing/050.php +++ b/user_guide_src/source/incoming/routing/050.php @@ -1,7 +1,7 @@ setAutoRoute(false); diff --git a/user_guide_src/source/incoming/routing/051.php b/user_guide_src/source/incoming/routing/051.php index 098d85178575..125308e20163 100644 --- a/user_guide_src/source/incoming/routing/051.php +++ b/user_guide_src/source/incoming/routing/051.php @@ -1,7 +1,7 @@ set404Override('App\Errors::show404'); From f673df4901273886c427b475ae09ce2e3c90a3a3 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Tue, 4 Apr 2023 15:45:47 -0500 Subject: [PATCH 10/22] Apply suggestions from code review Co-authored-by: Michal Sniatala --- user_guide_src/source/incoming/routing.rst | 12 ++++++------ user_guide_src/source/installation/upgrade_440.rst | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index cee4c6ba672a..64233c05f598 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -22,7 +22,7 @@ First, let's look at Defined Route Routing. If you want to use Auto Routing, see Setting Routing Rules ********************* -Routing rules are defined in the **app/Routes.php** file. In it you'll see that +Routing rules are defined in the **app/Config/Routes.php** file. In it you'll see that it creates an instance of the RouteCollection class (``$routes``) that permits you to specify your own routing criteria. Routes can be specified using placeholders or Regular Expressions. @@ -408,7 +408,7 @@ The value for the filter can be a string or an array of strings: See :doc:`Controller Filters ` for more information on setting up filters. -.. Warning:: If you set filters to routes in **app/Routes.php** +.. Warning:: If you set filters to routes in **app/Config/Routes.php** (not in **app/Config/Filters.php**), it is recommended to disable Auto Routing (Legacy). When :ref:`auto-routing-legacy` is enabled, it may be possible that a controller can be accessed via a different URL than the configured route, @@ -677,7 +677,7 @@ See :ref:`Auto Routing in Controllers ` for mo Configuration Options ===================== -These options are available at the top of **app/Routes.php**. +These options are available at the top of **app/Config/Routes.php**. Default Controller ------------------ @@ -720,7 +720,7 @@ Auto Routing (Legacy) Auto Routing (Legacy) is a routing system from CodeIgniter 3. It can automatically route HTTP requests based on conventions and execute the corresponding controller methods. -It is recommended that all routes are defined in the **app/Routes.php** file, +It is recommended that all routes are defined in the **app/Config/Routes.php** file, or to use :ref:`auto-routing-improved`, .. warning:: To prevent misconfiguration and miscoding, we recommend that you do not use @@ -734,7 +734,7 @@ Enable Auto Routing (Legacy) Since v4.2.0, the auto-routing is disabled by default. -To use it, you need to change the setting ``setAutoRoute()`` option to true in **app/Routes.php**:: +To use it, you need to change the setting ``$autoRoute`` option to true in **app/Config/Routing.php**:: $routes->setAutoRoute(true); @@ -761,7 +761,7 @@ See :ref:`Auto Routing (Legacy) in Controllers ` Configuration Options (Legacy) ============================== -These options are available at the top of **app/Routes.php**. +These options are available at the top of **app/Config/Routes.php**. Default Controller (Legacy) --------------------------- diff --git a/user_guide_src/source/installation/upgrade_440.rst b/user_guide_src/source/installation/upgrade_440.rst index 47dbb1a4a0ef..b400aaf23e5d 100644 --- a/user_guide_src/source/installation/upgrade_440.rst +++ b/user_guide_src/source/installation/upgrade_440.rst @@ -68,7 +68,6 @@ Routing To clean up the routing system, the following changes were made: - New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file. - The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file. - - The ``app/Config/Routes.php`` file was moved to ``app/Routes.php`` to make it easier to find. When upgrading, you can change the ``app/Config/Routing.php` file, ``$routeFiles`` property to point to the old location if you prefer. - The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``. Config From 56eb7020fa63edbe30f92bbd27a91e7e6fc17981 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Tue, 4 Apr 2023 23:03:59 -0500 Subject: [PATCH 11/22] Apply suggestions from code review Co-authored-by: kenjis --- user_guide_src/source/changelogs/v4.3.3.rst | 12 ------------ user_guide_src/source/incoming/routing.rst | 4 ++-- user_guide_src/source/tutorial/static_pages.rst | 2 +- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.3.3.rst b/user_guide_src/source/changelogs/v4.3.3.rst index 1430cf767aea..cd9d3fc31a40 100644 --- a/user_guide_src/source/changelogs/v4.3.3.rst +++ b/user_guide_src/source/changelogs/v4.3.3.rst @@ -16,18 +16,6 @@ SECURITY - **Text Helper:** The :php:func:`random_string()` type **alpha**, **alnum**, **numeric** and **nozero** are now cryptographically secure. -BREAKING -******** - -Message Changes -*************** - -Changes -******* - -Deprecations -************ - Bugs Fixed ********** diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index 64233c05f598..c1bcb07341d6 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -584,7 +584,7 @@ When no defined route is found that matches the URI, the system will attempt to controllers and methods when Auto Routing is enabled. You can disable this automatic matching, and restrict routes -to only those defined by you, by setting the ``$autoRoute`` option to false: +to only those defined by you, by setting the ``$autoRoute`` property to false: .. literalinclude:: routing/050.php @@ -600,7 +600,7 @@ a valid class/method pair, just like you would show in any route, or a Closure: .. literalinclude:: routing/051.php -Using the ``set404Override`` method within the routes file, you can use closures. Defining the override in the Routing file is restricted to class/method pairs. +Using the ``$override404`` property within the routing config file, you can use closures. Defining the override in the Routing file is restricted to class/method pairs. .. note:: The ``set404Override()`` method does not change the Response status code to ``404``. If you don't set the status code in the controller you set, the default status code ``200`` diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index 37c6121129de..d39224f3b018 100644 --- a/user_guide_src/source/tutorial/static_pages.rst +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -136,7 +136,7 @@ We have made the controller. The next thing is to set routing rules. Routing associates a URI with a controller's method. Let's do that. Open the routing file located at -**app/Routes.php**. +**app/Config/Routes.php**. The only line there to start with should be: From 7a0d1e4e2177f14ff997b09eb560f0aca1a76a59 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Wed, 5 Apr 2023 08:43:42 -0500 Subject: [PATCH 12/22] Apply suggestions from code review --- system/Router/RouteCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 9962bb23e11c..0ae204f140be 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -273,7 +273,7 @@ public function __construct(FileLocator $locator, Modules $moduleConfig, Routing * * @return $this */ - public function loadRoutes(string $routesFile = APPPATH . 'Routes.php') + public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php') { if ($this->didDiscover) { return $this; From 35f9a1dda30daaeab6b7526beeb27c19cea0cfbc Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 09:33:56 +0900 Subject: [PATCH 13/22] test: update failed tests --- tests/system/CommonFunctionsTest.php | 10 ++++++---- tests/system/HTTP/RedirectResponseTest.php | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index cf0555fba3d8..92c853f4cf2d 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -32,6 +32,7 @@ use Config\Cookie; use Config\Logger; use Config\Modules; +use Config\Routing; use Config\Services; use Kint; use RuntimeException; @@ -124,7 +125,8 @@ public function testRedirectReturnsRedirectResponse() $response = $this->createMock(Response::class); $routes = new RouteCollection( Services::locator(), - new Modules() + new Modules(), + new Routing() ); Services::injectMock('response', $response); Services::injectMock('routes', $routes); @@ -389,7 +391,7 @@ public function testOldInput() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules()); + $this->routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); @@ -424,7 +426,7 @@ public function testOldInputSerializeData() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules()); + $this->routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); @@ -459,7 +461,7 @@ public function testOldInputArray() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules()); + $this->routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); diff --git a/tests/system/HTTP/RedirectResponseTest.php b/tests/system/HTTP/RedirectResponseTest.php index 65fc0e62d03c..22c3c719b716 100644 --- a/tests/system/HTTP/RedirectResponseTest.php +++ b/tests/system/HTTP/RedirectResponseTest.php @@ -19,6 +19,7 @@ use CodeIgniter\Validation\Validation; use Config\App; use Config\Modules; +use Config\Routing; use Config\Services; /** @@ -47,7 +48,7 @@ protected function setUp(): void $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules()); + $this->routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest( From d74967f9452882597e5bc2ec5aecac7abd12d67e Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 09:34:29 +0900 Subject: [PATCH 14/22] test: fix incorrect tests --- tests/system/RESTful/ResourceControllerTest.php | 2 +- tests/system/RESTful/ResourcePresenterTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/RESTful/ResourceControllerTest.php b/tests/system/RESTful/ResourceControllerTest.php index fe1d0ac6f781..c96cebc8ebcb 100644 --- a/tests/system/RESTful/ResourceControllerTest.php +++ b/tests/system/RESTful/ResourceControllerTest.php @@ -66,7 +66,7 @@ private function createCodeigniter(): void // Inject mock router. $this->routes = Services::routes(); - $this->routes->resource('work', ['controller' => Worker::class]); + $this->routes->resource('work', ['controller' => '\\' . Worker::class]); Services::injectMock('routes', $this->routes); $config = new App(); diff --git a/tests/system/RESTful/ResourcePresenterTest.php b/tests/system/RESTful/ResourcePresenterTest.php index a430b527a580..8c72d4d6ffb8 100644 --- a/tests/system/RESTful/ResourcePresenterTest.php +++ b/tests/system/RESTful/ResourcePresenterTest.php @@ -60,7 +60,7 @@ private function createCodeigniter(): void // Inject mock router. $this->routes = Services::routes(); - $this->routes->presenter('work', ['controller' => Worker2::class]); + $this->routes->presenter('work', ['controller' => '\\' . Worker2::class]); Services::injectMock('routes', $this->routes); $config = new App(); From 1aba5dbaf798d802735d99adcfcc03185d7f55ee Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 09:34:54 +0900 Subject: [PATCH 15/22] docs: to pass cs-fix --- user_guide_src/source/incoming/routing/045.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/incoming/routing/045.php b/user_guide_src/source/incoming/routing/045.php index f20d34a40681..08ae4e4f2bb7 100644 --- a/user_guide_src/source/incoming/routing/045.php +++ b/user_guide_src/source/incoming/routing/045.php @@ -1,7 +1,7 @@ get('users', 'Users::index'); From 2eb2ee55252b0fe6c8e1301966108f1f0c2b4579 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 09:51:42 +0900 Subject: [PATCH 16/22] test: extract method --- tests/system/CommonFunctionsTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 92c853f4cf2d..a40e4cd8d438 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -118,17 +118,19 @@ public function testEnvBooleans() $this->assertNull(env('p4')); } + private function createRouteCollection(): RouteCollection + { + return new RouteCollection(Services::locator(), new Modules(), new Routing()); + } + public function testRedirectReturnsRedirectResponse() { $_SERVER['REQUEST_METHOD'] = 'GET'; $response = $this->createMock(Response::class); - $routes = new RouteCollection( - Services::locator(), - new Modules(), - new Routing() - ); Services::injectMock('response', $response); + + $routes = $this->createRouteCollection(); Services::injectMock('routes', $routes); $routes->add('home/base', 'Controller::index', ['as' => 'base']); @@ -391,7 +393,7 @@ public function testOldInput() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); + $this->routes = $this->createRouteCollection(); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); @@ -426,7 +428,7 @@ public function testOldInputSerializeData() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); + $this->routes = $this->createRouteCollection(); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); @@ -461,7 +463,7 @@ public function testOldInputArray() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules(), new Routing()); + $this->routes = $this->createRouteCollection(); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); From a47b8f1bb54940cc0dd90d0aea2479d969c3f396 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 10:06:01 +0900 Subject: [PATCH 17/22] docs: improve sample code class files --- user_guide_src/source/incoming/routing/045.php | 7 ++++++- user_guide_src/source/incoming/routing/049.php | 7 ++++++- user_guide_src/source/incoming/routing/050.php | 7 ++++++- user_guide_src/source/incoming/routing/051.php | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/user_guide_src/source/incoming/routing/045.php b/user_guide_src/source/incoming/routing/045.php index 08ae4e4f2bb7..e9534931dbc8 100644 --- a/user_guide_src/source/incoming/routing/045.php +++ b/user_guide_src/source/incoming/routing/045.php @@ -1,7 +1,12 @@ get('users', 'Users::index'); diff --git a/user_guide_src/source/incoming/routing/049.php b/user_guide_src/source/incoming/routing/049.php index dd276e95316f..9f53bee87476 100644 --- a/user_guide_src/source/incoming/routing/049.php +++ b/user_guide_src/source/incoming/routing/049.php @@ -1,7 +1,12 @@ setTranslateURIDashes(true); diff --git a/user_guide_src/source/incoming/routing/050.php b/user_guide_src/source/incoming/routing/050.php index dc24bfe41416..6f5446f5a654 100644 --- a/user_guide_src/source/incoming/routing/050.php +++ b/user_guide_src/source/incoming/routing/050.php @@ -1,7 +1,12 @@ setAutoRoute(false); diff --git a/user_guide_src/source/incoming/routing/051.php b/user_guide_src/source/incoming/routing/051.php index 125308e20163..bced5d53147a 100644 --- a/user_guide_src/source/incoming/routing/051.php +++ b/user_guide_src/source/incoming/routing/051.php @@ -1,7 +1,12 @@ set404Override('App\Errors::show404'); From 329d90beee0a0c3489b7437737be945d7cb8761d Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 10:10:07 +0900 Subject: [PATCH 18/22] docs: add note for new config file --- user_guide_src/source/incoming/routing.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index c1bcb07341d6..066009beda65 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -547,6 +547,10 @@ Routes Configuration Options The RoutesCollection class provides several options that affect all routes, and can be modified to meet your application's needs. These options are available in **app/Config/Routing.php**. +.. note:: The config file **app/Config/Routing.php** has been added since v4.4.0. + In previous versions, the setter methods were used in **app/Config/Routes.php** + to change settings. + .. _routing-default-namespace: Default Namespace From 5243ba32141f8bacfd4a7e3c0014a07083623969 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 10:19:48 +0900 Subject: [PATCH 19/22] docs: add changelog --- user_guide_src/source/changelogs/v4.4.0.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index 7352347b821a..b8c586d47c3d 100644 --- a/user_guide_src/source/changelogs/v4.4.0.rst +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -35,6 +35,8 @@ Interface Changes Method Signature Changes ======================== +- The third parameter ``Routing $routing`` has been added to ``RouteCollection::__construct()``. + Enhancements ************ @@ -97,6 +99,7 @@ Changes ******* - **Config:** The deprecated Cookie items in **app/Config/App.php** has been removed. +- **Config:** Routing settings have been moved to **app/Config/Routing.php** config file. - **DownloadResponse:** When generating response headers, does not replace the ``Content-Disposition`` header if it was previously specified. - **Autoloader:** Before v4.4.0, CodeIgniter autoloader did not allow special characters that are illegal in filenames on certain operating systems. @@ -104,7 +107,6 @@ Changes So if you installed CodeIgniter under the folder that contains the special characters like ``(``, ``)``, etc., CodeIgniter didn't work. Since v4.4.0, this restriction has been removed. -- **Config:** Routing settings have been moved to ``Config\Routing`` config file. Deprecations ************ From e5e6766cae1b33e3c5c65d780cdda2a1934c776f Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 10:37:36 +0900 Subject: [PATCH 20/22] docs: update ugrade_440 --- user_guide_src/source/changelogs/v4.4.0.rst | 1 + .../source/installation/upgrade_440.rst | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index b8c586d47c3d..40f45d72e010 100644 --- a/user_guide_src/source/changelogs/v4.4.0.rst +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -100,6 +100,7 @@ Changes - **Config:** The deprecated Cookie items in **app/Config/App.php** has been removed. - **Config:** Routing settings have been moved to **app/Config/Routing.php** config file. + See :ref:`Upgrading Guide `. - **DownloadResponse:** When generating response headers, does not replace the ``Content-Disposition`` header if it was previously specified. - **Autoloader:** Before v4.4.0, CodeIgniter autoloader did not allow special characters that are illegal in filenames on certain operating systems. diff --git a/user_guide_src/source/installation/upgrade_440.rst b/user_guide_src/source/installation/upgrade_440.rst index b400aaf23e5d..102308545b51 100644 --- a/user_guide_src/source/installation/upgrade_440.rst +++ b/user_guide_src/source/installation/upgrade_440.rst @@ -34,6 +34,24 @@ Mandatory File Changes Config Files ============ +.. _upgrade-440-config-routing: + +app/Config/Routing.php +---------------------- + +To clean up the routing system, the following changes were made: + +- New **app/Config/Routing.php** file that holds the settings that used to be in the Routes file. +- The **app/Config/Routes.php** file was simplified so that it only contains the routes without settings and verbiage to clutter the file. +- The environment-specific routes files are no longer loaded automatically. + +So you need to do: + +1. Copy **app/Config/Routing.php** from the new framework to your **app/Config** + directory, and configure it. +2. Remove all settings in **app/Config/Routes.php** that are no longer needed. +3. If you use the environment-specific routes files, add them to the ``$routeFiles`` property in **app/Config/Routing.php**. + app/Config/Cookie.php --------------------- @@ -62,14 +80,6 @@ Content Changes The following files received significant changes (including deprecations or visual adjustments) and it is recommended that you merge the updated versions with your application: -Routing -------- - -To clean up the routing system, the following changes were made: - - New ``app/Config/Routing.php`` file that holds the settings that used to be in the Routes file. - - The ``app/Config/Routes.php`` file was simplified so that it only contains the routes without settings and verbiage to clutter the file. - - The environment-specific routes files are no longer loaded automatically. To load those, you must add them to the ``$routeFiles`` property in ``app/Config/Routing.php``. - Config ------ From 48e3864a07c34f9e5f5f96d5245169b6dd9ec1b8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Apr 2023 10:57:34 +0900 Subject: [PATCH 21/22] docs: add instruction to upgrade --- user_guide_src/source/installation/upgrade_440.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_guide_src/source/installation/upgrade_440.rst b/user_guide_src/source/installation/upgrade_440.rst index 102308545b51..6200fa79ae22 100644 --- a/user_guide_src/source/installation/upgrade_440.rst +++ b/user_guide_src/source/installation/upgrade_440.rst @@ -65,6 +65,10 @@ The Cookie config items in **app/Config/App.php** are no longer used. Breaking Enhancements ********************* +- The method signature of ``RouteCollection::__construct()`` has been changed. + The third parameter ``Routing $routing`` has been added. Extending classes + should likewise add the parameter so as not to break LSP. + Project Files ************* From 64130a27b5bd6440f2dcfc30b44410f669651f51 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 10 Apr 2023 08:58:37 +0900 Subject: [PATCH 22/22] fix: log message In error messages, we do not place a dot in the sentence when it comes `:` + word. --- system/Router/RouteCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 0ae204f140be..97f85400cdee 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -292,7 +292,7 @@ public function loadRoutes(string $routesFile = APPPATH . 'Config/Routes.php') foreach ($routeFiles as $routesFile) { if (! is_file($routesFile)) { - log_message('warning', 'Routes file not found: ' . $routesFile . '.'); + log_message('warning', sprintf('Routes file not found: "%s"', $routesFile)); continue; }