Skip to content

Commit e8ee92b

Browse files
authored
refactor: further rename --handler to --sort-by-handler for routes (#10125)
1 parent 279eae2 commit e8ee92b

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

system/Commands/Utilities/Routes.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,21 @@ class Routes extends BaseCommand
7373
* @var array<string, string>
7474
*/
7575
protected $options = [
76-
'--handler' => 'Sort by Handler.',
77-
'--host' => 'Specify hostname in request URI.',
76+
'--sort-by-handler' => 'Sort by handler.',
77+
'--host' => 'Specify hostname in request URI.',
7878
];
7979

8080
/**
8181
* Displays the help for the spark cli script itself.
8282
*/
8383
public function run(array $params)
8484
{
85-
$sortByHandler = array_key_exists('handler', $params);
85+
$sortByHandler = array_key_exists('sort-by-handler', $params);
8686

8787
if (! $sortByHandler && array_key_exists('h', $params)) {
88+
// @todo to remove support in v4.8.0
8889
// Support -h as a shortcut but print a warning that it is not the intended use of -h.
89-
CLI::write('Warning: -h will be used as shortcut for --help in v4.8.0. Please use --handler to sort by handler.', 'yellow');
90+
CLI::write('Warning: -h will be used as shortcut for --help in v4.8.0. Please use --sort-by-handler to sort by handler.', 'yellow');
9091
CLI::newLine();
9192

9293
$sortByHandler = true;

tests/system/Commands/Utilities/RoutesTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testRoutesCommandSortByHandler(): void
9494
{
9595
Services::resetSingle('routes');
9696

97-
command('routes --handler');
97+
command('routes --sort-by-handler');
9898

9999
$expected = <<<'EOL'
100100
+---------+---------+---------------+----------------------------------------+----------------+---------------+
@@ -127,7 +127,7 @@ public function testRoutesCommandSortByHandlerUsingShortcutForBc(): void
127127
command('routes -h');
128128

129129
$expected = <<<'EOL'
130-
Warning: -h will be used as shortcut for --help in v4.8.0. Please use --handler to sort by handler.
130+
Warning: -h will be used as shortcut for --help in v4.8.0. Please use --sort-by-handler to sort by handler.
131131
132132
+---------+---------+---------------+----------------------------------------+----------------+---------------+
133133
| Method | Route | Name | Handler ↓ | Before Filters | After Filters |
@@ -146,7 +146,10 @@ public function testRoutesCommandSortByHandlerUsingShortcutForBc(): void
146146
| CLI | testing | testing-index | \App\Controllers\TestController::index | | |
147147
+---------+---------+---------------+----------------------------------------+----------------+---------------+
148148
EOL;
149-
$this->assertStringContainsString($expected, $this->getBuffer());
149+
$this->assertStringContainsString(
150+
$expected,
151+
(string) preg_replace('/\e\[[^m]+m/u', '', $this->getBuffer()),
152+
);
150153
}
151154

152155
public function testRoutesCommandHostHostname(): void

user_guide_src/source/changelogs/v4.7.3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Message Changes
2424
Changes
2525
*******
2626

27-
- **Commands:** The ``-h`` option for the ``routes`` command is renamed to ``--handler`` to avoid conflict with the common use of ``-h`` as a shortcut for ``--help``.
27+
- **Commands:** The ``-h`` option for the ``routes`` command is renamed to ``--sort-by-handler`` to avoid conflict with the common use of ``-h`` as a shortcut for ``--help``.
2828
The old ``-h`` option will continue to work until v4.8.0, at which point it will be removed and repurposed as a shortcut for ``--help``.
29-
A warning message is displayed when using the old ``-h`` option to encourage users to switch to the new ``--handler`` option.
29+
A warning message is displayed when using the old ``-h`` option to encourage users to switch to the new ``--sort-by-handler`` option.
3030

3131
************
3232
Deprecations

user_guide_src/source/incoming/routing.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,11 +1001,11 @@ Sort by Handler
10011001

10021002
.. versionadded:: 4.3.0
10031003

1004-
You can sort the routes by *Handler*:
1004+
You can sort the routes by *handler*:
10051005

10061006
.. code-block:: console
10071007
1008-
php spark routes -h
1008+
php spark routes --sort-by-handler
10091009
10101010
.. _routing-spark-routes-specify-host:
10111011

@@ -1060,4 +1060,3 @@ Additionally, if we use ``addRedirect()`` we can also expect the ``redirect`` ke
10601060
To access the values of these parameters, we can call ``Router::getMatchedRouteOptions()``. Here is an example of the returned array:
10611061

10621062
.. literalinclude:: routing/074.php
1063-

0 commit comments

Comments
 (0)