Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 12, 2023
2 parents 38f7a59 + f6ce13b commit 8ad55e3
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 104 deletions.
10 changes: 10 additions & 0 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ class CLI
* Is the readline library on the system?
*
* @var bool
*
* @deprecated 4.4.2 Should be protected.
* @TODO Fix to camelCase in the next major version.
*/
public static $readline_support = false;

/**
* The message displayed at prompts.
*
* @var string
*
* @deprecated 4.4.2 Should be protected.
* @TODO Fix to camelCase in the next major version.
*/
public static $wait_msg = 'Press any key to continue...';

Expand All @@ -63,6 +69,8 @@ class CLI
* Foreground color list
*
* @var array<string, string>
*
* @TODO Fix to camelCase in the next major version.
*/
protected static $foreground_colors = [
'black' => '0;30',
Expand All @@ -88,6 +96,8 @@ class CLI
* Background color list
*
* @var array<string, string>
*
* @TODO Fix to camelCase in the next major version.
*/
protected static $background_colors = [
'black' => '40',
Expand Down
54 changes: 18 additions & 36 deletions tests/system/Commands/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,46 +198,28 @@ public function testRoutesCommandRouteLegacy(): void
$routes->loadRoutes();

$routes->setAutoRoute(true);
$namespace = 'Tests\Support\Controllers';
$routes->setDefaultNamespace($namespace);

command('routes');

$expected = <<<'EOL'
+---------+-------------------------------+---------------+-----------------------------------------------------+----------------+---------------+
| Method | Route | Name | Handler | Before Filters | After Filters |
+---------+-------------------------------+---------------+-----------------------------------------------------+----------------+---------------+
| GET | / | » | \App\Controllers\Home::index | | toolbar |
| GET | closure | » | (Closure) | | toolbar |
| GET | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| HEAD | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| POST | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| PUT | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| DELETE | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| OPTIONS | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| TRACE | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| CONNECT | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| CLI | testing | testing-index | \App\Controllers\TestController::index | | |
| auto | hello | | \Tests\Support\Controllers\Hello::index | | toolbar |
| auto | hello/index[/...] | | \Tests\Support\Controllers\Hello::index | | toolbar |
| auto | newautorouting/getIndex[/...] | | \Tests\Support\Controllers\Newautorouting::getIndex | | toolbar |
| auto | newautorouting/postSave[/...] | | \Tests\Support\Controllers\Newautorouting::postSave | | toolbar |
| auto | popcorn | | \Tests\Support\Controllers\Popcorn::index | | toolbar |
| auto | popcorn/index[/...] | | \Tests\Support\Controllers\Popcorn::index | | toolbar |
| auto | popcorn/pop[/...] | | \Tests\Support\Controllers\Popcorn::pop | | toolbar |
| auto | popcorn/popper[/...] | | \Tests\Support\Controllers\Popcorn::popper | | toolbar |
| auto | popcorn/weasel[/...] | | \Tests\Support\Controllers\Popcorn::weasel | | toolbar |
| auto | popcorn/oops[/...] | | \Tests\Support\Controllers\Popcorn::oops | | toolbar |
| auto | popcorn/goaway[/...] | | \Tests\Support\Controllers\Popcorn::goaway | | toolbar |
| auto | popcorn/index3[/...] | | \Tests\Support\Controllers\Popcorn::index3 | | toolbar |
| auto | popcorn/canyon[/...] | | \Tests\Support\Controllers\Popcorn::canyon | | toolbar |
| auto | popcorn/cat[/...] | | \Tests\Support\Controllers\Popcorn::cat | | toolbar |
| auto | popcorn/json[/...] | | \Tests\Support\Controllers\Popcorn::json | | toolbar |
| auto | popcorn/xml[/...] | | \Tests\Support\Controllers\Popcorn::xml | | toolbar |
| auto | popcorn/toindex[/...] | | \Tests\Support\Controllers\Popcorn::toindex | | toolbar |
| auto | popcorn/echoJson[/...] | | \Tests\Support\Controllers\Popcorn::echoJson | | toolbar |
| auto | remap[/...] | | \Tests\Support\Controllers\Remap::_remap | | toolbar |
+---------+-------------------------------+---------------+-----------------------------------------------------+----------------+---------------+
+---------+------------------+---------------+----------------------------------------+----------------+---------------+
| Method | Route | Name | Handler | Before Filters | After Filters |
+---------+------------------+---------------+----------------------------------------+----------------+---------------+
| GET | / | » | \App\Controllers\Home::index | | toolbar |
| GET | closure | » | (Closure) | | toolbar |
| GET | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| HEAD | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| POST | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| PUT | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| DELETE | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| OPTIONS | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| TRACE | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| CONNECT | testing | testing-index | \App\Controllers\TestController::index | | toolbar |
| CLI | testing | testing-index | \App\Controllers\TestController::index | | |
| auto | / | | \App\Controllers\Home::index | | toolbar |
| auto | home | | \App\Controllers\Home::index | | toolbar |
| auto | home/index[/...] | | \App\Controllers\Home::index | | toolbar |
+---------+------------------+---------------+----------------------------------------+----------------+---------------+
EOL;
$this->assertStringContainsString($expected, $this->getBuffer());
}
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Deprecations
- **Filters:** The Auto-Discovery for Filters and ``Filters::discoverFilters()``
is deprecated. Use :ref:`registrars` instead. See :ref:`modules-filters` for
details.
- **CLI:** The public property ``CLI::$readline_support`` and ``CLI::$wait_msg``
are deprecated. These methods will be protected.

Bugs Fixed
**********
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/installation/upgrade_440.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ When Passing Classname with Namespace to Factories
The behavior of passing a classname with a namespace to Factories has been changed.
See :ref:`ChangeLog <v440-factories>` for details.

If you have code like ``model('\Myth\Auth\Models\UserModel::class')`` or
If you have code like ``model(\Myth\Auth\Models\UserModel::class)`` or
``model('Myth\Auth\Models\UserModel')`` (the code may be in the third-party packages),
and you expect to load your ``App\Models\UserModel``, you need to define the
classname to be loaded before the first loading of that class::
Expand Down
34 changes: 17 additions & 17 deletions user_guide_src/source/tutorial/create_news_items.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ You can read more about the CSRF protection in :doc:`Security <../libraries/secu
because :ref:`auto-routing-legacy` permits any HTTP method to access a controller.
Accessing the controller with a method you don't expect could bypass the filter.

Adding Routing Rules
********************

Before you can start adding news items into your CodeIgniter application
you have to add an extra rule to **app/Config/Routes.php** file. Make sure your
file contains the following:

.. literalinclude:: create_news_items/004.php

The route directive for ``'news/new'`` is placed before the directive for ``'news/(:segment)'`` to ensure that the form to create a news item is displayed.

The ``$routes->post()`` line defines the router for a POST request. It matches
only a POST request to the URI path **/news**, and it maps to the ``create()`` method of
the ``News`` class.

You can read more about different routing types in :ref:`defined-route-routing`.

Create a Form
*************

Expand Down Expand Up @@ -151,23 +168,6 @@ never need to do that, since it is an auto-incrementing field in the database.
This helps protect against Mass Assignment Vulnerabilities. If your model is
handling your timestamps, you would also leave those out.

Adding Routing Rules
********************

Before you can start adding news items into your CodeIgniter application
you have to add an extra rule to **app/Config/Routes.php** file. Make sure your
file contains the following:

.. literalinclude:: create_news_items/004.php

The route directive for ``'news/new'`` is placed before the directive for ``'news/(:segment)'`` to ensure that the form to create a news item is displayed.

The ``$routes->post()`` line defines the router for a POST request. It matches
only a POST request to the URI path **/news**, and it maps to the ``create()`` method of
the ``News`` class.

You can read more about different routing types in :ref:`defined-route-routing`.

Create a News Item
******************

Expand Down
22 changes: 11 additions & 11 deletions user_guide_src/source/tutorial/news_section.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ that are going to display the news items to the user. This could be done
in our ``Pages`` controller created earlier, but for the sake of clarity,
a new ``News`` controller is defined.

Adding Routing Rules
====================

Modify your **app/Config/Routes.php** file, so it looks as follows:

.. literalinclude:: news_section/008.php

This makes sure the requests reach the ``News`` controller instead of
going directly to the ``Pages`` controller. The second ``$routes->get()`` line
routes URI's with a slug to the ``show()`` method in the ``News`` controller.

Create News Controller
======================

Expand Down Expand Up @@ -200,17 +211,6 @@ The only thing left to do is create the corresponding view at

.. literalinclude:: news_section/007.php

Adding Routing Rules
********************

Modify your **app/Config/Routes.php** file, so it looks as follows:

.. literalinclude:: news_section/008.php

This makes sure the requests reach the ``News`` controller instead of
going directly to the ``Pages`` controller. The second ``$routes->get()`` line
routes URI's with a slug to the ``show()`` method in the ``News`` controller.

Point your browser to your "news" page, i.e., **localhost:8080/news**,
you should see a list of the news items, each of which has a link
to display just the one article.
Expand Down
80 changes: 41 additions & 39 deletions user_guide_src/source/tutorial/static_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,51 @@ Static Pages
:doc:`installed the framework <../installation/index>` in your
development environment.

The first thing you're going to do is set up a **controller** to handle
static pages. A controller is simply a class that helps delegate work.
It is the glue of your web application.
The first thing you're going to do is set up routing rules to handle static pages.

Setting Routing Rules
*********************

Routing associates a URI with a controller's method. A controller is simply a
class that helps delegate work. We will create a controller later.

Let's set up routing rules. Open the routes file located at **app/Config/Routes.php**.

The only route directive there to start with should be:

.. literalinclude:: static_pages/003.php

This directive says that any incoming request without any content
specified should be handled by the ``index()`` method inside the ``Home`` controller.

Add the following lines, **after** the route directive for ``'/'``.

.. literalinclude:: static_pages/004.php
:lines: 2-

CodeIgniter reads its routing rules from top to bottom and routes the
request to the first matching rule. Each rule is a regular expression
(left-side) mapped to a controller and method name
(right-side). When a request comes in, CodeIgniter looks for the first
match, and calls the appropriate controller and method, possibly with
arguments.

More information about routing can be found in the :doc:`../incoming/routing`.

Here, the second rule in the ``$routes`` object matches a GET request
to the URI path **/pages**, and it maps to the ``index()`` method of the ``Pages`` class.

The third rule in the ``$routes`` object matches a GET request to a URI segment
using the placeholder ``(:segment)``, and passes the parameter to the
``view()`` method of the ``Pages`` class.

Let's Make our First Controller
*******************************

The next thing you're going to do is set up a **controller** to handle
static pages. A controller is simply a class that helps delegate work.
It is the glue of your web application.

Create Pages Controller
=======================

Expand Down Expand Up @@ -141,42 +179,6 @@ view.
throw errors on case-sensitive platforms. You can read more about it in
:doc:`../outgoing/views`.

Setting Routing Rules
*********************

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 routes file located at **app/Config/Routes.php**.

The only route directive there to start with should be:

.. literalinclude:: static_pages/003.php

This directive says that any incoming request without any content
specified should be handled by the ``index()`` method inside the ``Home`` controller.

Add the following lines, **after** the route directive for ``'/'``.

.. literalinclude:: static_pages/004.php
:lines: 2-

CodeIgniter reads its routing rules from top to bottom and routes the
request to the first matching rule. Each rule is a regular expression
(left-side) mapped to a controller and method name
(right-side). When a request comes in, CodeIgniter looks for the first
match, and calls the appropriate controller and method, possibly with
arguments.

More information about routing can be found in the :doc:`../incoming/routing`.

Here, the second rule in the ``$routes`` object matches a GET request
to the URI path **/pages**, and it maps to the ``index()`` method of the ``Pages`` class.

The third rule in the ``$routes`` object matches a GET request to a URI segment
using the placeholder ``(:segment)``, and passes the parameter to the
``view()`` method of the ``Pages`` class.

Running the App
***************

Expand Down

0 comments on commit 8ad55e3

Please sign in to comment.