diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c251ec22c4b4..fc4914a6923b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -1,49 +1,8 @@ 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 - * -------------------------------------------------------------------- +/** + * @var RouteCollection $routes */ - -// 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..73d9a93f0f4b --- /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 +{ + /** + * 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 . 'Config/Routes.php', + ]; + + /** + * 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; + + /** + * 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; +} diff --git a/system/Config/Routing.php b/system/Config/Routing.php new file mode 100644 index 000000000000..857a27769215 --- /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 +{ + /** + * 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. + * + * 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; + + /** + * 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; +} 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..97f85400cdee 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,11 @@ class RouteCollection implements RouteCollectionInterface */ protected $override404; + /** + * An array of files that would contain route definitions. + */ + protected array $routeFiles = []; + /** * Defined placeholders that can be used * within the @@ -242,12 +248,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 +279,26 @@ 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', sprintf('Routes file not found: "%s"', $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/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/tests/system/Commands/Utilities/Routes/FilterFinderTest.php b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php index ace71d9d7e2d..9829e36a490a 100644 --- a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php +++ b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php @@ -25,6 +25,7 @@ use CodeIgniter\Test\ConfigFromArrayTrait; use Config\Filters as FiltersConfig; use Config\Modules; +use Config\Routing; /** * @internal @@ -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/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index cf0555fba3d8..a40e4cd8d438 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; @@ -117,16 +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() - ); Services::injectMock('response', $response); + + $routes = $this->createRouteCollection(); Services::injectMock('routes', $routes); $routes->add('home/base', 'Controller::index', ['as' => 'base']); @@ -389,7 +393,7 @@ public function testOldInput() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules()); + $this->routes = $this->createRouteCollection(); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); @@ -424,7 +428,7 @@ public function testOldInputSerializeData() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules()); + $this->routes = $this->createRouteCollection(); Services::injectMock('routes', $this->routes); $this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent()); @@ -459,7 +463,7 @@ public function testOldInputArray() $this->config = new App(); $this->config->baseURL = 'http://example.com/'; - $this->routes = new RouteCollection(Services::locator(), new Modules()); + $this->routes = $this->createRouteCollection(); 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( 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(); diff --git a/tests/system/Router/AutoRouterImprovedTest.php b/tests/system/Router/AutoRouterImprovedTest.php index ab1fa7db2188..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); + $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 2e6de5aacdf7..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))->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 6458449a02c9..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,10 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo $moduleConfig->enabled = false; } - return (new RouteCollection($loader, $moduleConfig))->setHTTPVerb('get'); + $routerConfig = new Routing(); + $routerConfig->defaultNamespace = '\\'; + + return (new RouteCollection($loader, $moduleConfig, $routerConfig))->setHTTPVerb('get'); } public function testBasicAdd() diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index 5be01a47bfc6..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; /** @@ -36,7 +37,11 @@ protected function setUp(): void $moduleConfig = new Modules(); $moduleConfig->enabled = false; - $this->collection = new RouteCollection(Services::locator(), $moduleConfig); + + $routerConfig = new Routing(); + $routerConfig->defaultNamespace = '\\'; + + $this->collection = new RouteCollection(Services::locator(), $moduleConfig, $routerConfig); $routes = [ '/' => 'Home::index', diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index 503922b418e2..40f45d72e010 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,8 @@ 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/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index e11dee96c818..066009beda65 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -545,7 +545,11 @@ 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**. + +.. 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: @@ -569,8 +573,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 +588,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`` property to false: .. literalinclude:: routing/050.php @@ -601,6 +604,8 @@ a valid class/method pair, just like you would show in any route, or a Closure: .. literalinclude:: routing/051.php +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`` will be returned. See :php:meth:`CodeIgniter\\HTTP\\Response::setStatusCode()` for @@ -642,9 +647,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**:: @@ -733,7 +738,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 ``$autoRoute`` option to true in **app/Config/Routing.php**:: $routes->setAutoRoute(true); diff --git a/user_guide_src/source/incoming/routing/045.php b/user_guide_src/source/incoming/routing/045.php index 98aef9276f9d..e9534931dbc8 100644 --- a/user_guide_src/source/incoming/routing/045.php +++ b/user_guide_src/source/incoming/routing/045.php @@ -1,6 +1,12 @@ setDefaultNamespace(''); +// In app/Config/Routing.php +class Routing extends BaseRouting +{ + // ... + 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..9f53bee87476 100644 --- a/user_guide_src/source/incoming/routing/049.php +++ b/user_guide_src/source/incoming/routing/049.php @@ -1,3 +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 c331102cd9f4..6f5446f5a654 100644 --- a/user_guide_src/source/incoming/routing/050.php +++ b/user_guide_src/source/incoming/routing/050.php @@ -1,3 +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 dddd067f0f26..bced5d53147a 100644 --- a/user_guide_src/source/incoming/routing/051.php +++ b/user_guide_src/source/incoming/routing/051.php @@ -1,5 +1,13 @@ set404Override('App\Errors::show404'); diff --git a/user_guide_src/source/installation/upgrade_440.rst b/user_guide_src/source/installation/upgrade_440.rst index f5bc7aef91f2..6200fa79ae22 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 --------------------- @@ -47,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 ************* diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst index 926ed09603c7..d39224f3b018 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/Config/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'); // ...