From 775fa7d4e329209042269ae8c1bebb543c9d1c42 Mon Sep 17 00:00:00 2001 From: Andrey Pyzhikov <5071@mail.ru> Date: Sat, 11 Jun 2022 04:52:38 +0800 Subject: [PATCH 1/5] Extracting the call handler for Spark commands from application. --- spark | 9 ++-- system/CLI/Console.php | 31 +++++------ system/CodeIgniter.php | 91 ++++++++++---------------------- system/Config/Routes.php | 3 +- tests/system/CLI/ConsoleTest.php | 61 ++++++++++++++------- 5 files changed, 86 insertions(+), 109 deletions(-) diff --git a/spark b/spark index 225422aace74..6d4d762b38fc 100755 --- a/spark +++ b/spark @@ -69,10 +69,9 @@ require_once SYSTEMPATH . 'Config/DotEnv.php'; // Grab our CodeIgniter $app = Config\Services::codeigniter(); $app->initialize(); -$app->setContext('spark'); // Grab our Console -$console = new CodeIgniter\CLI\Console($app); +$console = new CodeIgniter\CLI\Console(); // Show basic information before we do anything else. if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) { @@ -83,8 +82,6 @@ if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) { $console->showHeader($suppress); // fire off the command in the main framework. -$response = $console->run(); +$exit = $console->run(); -if ($response->getStatusCode() >= 300) { - exit($response->getStatusCode()); -} +exit(is_int($exit) ? $exit : EXIT_SUCCESS); diff --git a/system/CLI/Console.php b/system/CLI/Console.php index 0bf8a0f7ce0a..a114127cab8f 100644 --- a/system/CLI/Console.php +++ b/system/CLI/Console.php @@ -12,6 +12,7 @@ namespace CodeIgniter\CLI; use CodeIgniter\CodeIgniter; +use Config\Services; use Exception; /** @@ -19,18 +20,6 @@ */ class Console { - /** - * Main CodeIgniter instance. - * - * @var CodeIgniter - */ - protected $app; - - public function __construct(CodeIgniter $app) - { - $this->app = $app; - } - /** * Runs the current command discovered on the CLI. * @@ -38,14 +27,13 @@ public function __construct(CodeIgniter $app) * * @return mixed */ - public function run(bool $useSafeOutput = false) + public function run() { - $path = CLI::getURI() ?: 'list'; - - // Set the path for the application to route to. - $this->app->setPath("ci{$path}"); + $runner = Services::commands(); + $params = array_merge(CLI::getSegments(), CLI::getOptions()); + $command = array_shift($params) ?? 'list'; - return $this->app->useSafeOutput($useSafeOutput)->run(); + return $runner->run($command, $params); } /** @@ -57,7 +45,12 @@ public function showHeader(bool $suppress = false) return; } - CLI::write(sprintf('CodeIgniter v%s Command Line Tool - Server Time: %s UTC%s', CodeIgniter::CI_VERSION, date('Y-m-d H:i:s'), date('P')), 'green'); + CLI::write(sprintf( + 'CodeIgniter v%s Command Line Tool - Server Time: %s UTC%s', + CodeIgniter::CI_VERSION, + date('Y-m-d H:i:s'), + date('P') + ), 'green'); CLI::newLine(); } } diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 82b08e318879..f16415516203 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -147,9 +147,8 @@ class CodeIgniter * Context * web: Invoked by HTTP request * php-cli: Invoked by CLI via `php public/index.php` - * spark: Invoked by CLI via the `spark` command * - * @phpstan-var 'php-cli'|'spark'|'web' + * @phpstan-var 'php-cli'|'web' */ protected ?string $context = null; @@ -307,7 +306,10 @@ protected function initializeKint() public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false) { if ($this->context === null) { - throw new LogicException('Context must be set before run() is called. If you are upgrading from 4.1.x, you need to merge `public/index.php` and `spark` file from `vendor/codeigniter4/framework`.'); + throw new LogicException( + 'Context must be set before run() is called. If you are upgrading from 4.1.x, ' + . 'you need to merge `public/index.php` and `spark` file from `vendor/codeigniter4/framework`.' + ); } $this->startBenchmark(); @@ -342,11 +344,6 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon return; } - // spark command has nothing to do with HTTP redirect and 404 - if ($this->isSparked()) { - return $this->handleRequest($routes, $cacheConfig, $returnResponse); - } - try { return $this->handleRequest($routes, $cacheConfig, $returnResponse); } catch (RedirectException $e) { @@ -380,14 +377,6 @@ public function useSafeOutput(bool $safe = true) return $this; } - /** - * Invoked via spark command? - */ - private function isSparked(): bool - { - return $this->context === 'spark'; - } - /** * Invoked via php-cli command? */ @@ -435,21 +424,18 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache } } - // Never run filters when running through Spark cli - if (! $this->isSparked()) { - // Run "before" filters - $this->benchmark->start('before_filters'); - $possibleResponse = $filters->run($uri, 'before'); - $this->benchmark->stop('before_filters'); + // Run "before" filters + $this->benchmark->start('before_filters'); + $possibleResponse = $filters->run($uri, 'before'); + $this->benchmark->stop('before_filters'); - // If a ResponseInterface instance is returned then send it back to the client and stop - if ($possibleResponse instanceof ResponseInterface) { - return $returnResponse ? $possibleResponse : $possibleResponse->pretend($this->useSafeOutput)->send(); - } + // If a ResponseInterface instance is returned then send it back to the client and stop + if ($possibleResponse instanceof ResponseInterface) { + return $returnResponse ? $possibleResponse : $possibleResponse->pretend($this->useSafeOutput)->send(); + } - if ($possibleResponse instanceof Request) { - $this->request = $possibleResponse; - } + if ($possibleResponse instanceof Request) { + $this->request = $possibleResponse; } $returned = $this->startController(); @@ -476,22 +462,12 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache // so it can be used with the output. $this->gatherOutput($cacheConfig, $returned); - // Never run filters when running through Spark cli - if (! $this->isSparked()) { - $filters->setResponse($this->response); + $filters->setResponse($this->response); - // Run "after" filters - $this->benchmark->start('after_filters'); - $response = $filters->run($uri, 'after'); - $this->benchmark->stop('after_filters'); - } else { - $response = $this->response; - - // Set response code for CLI command failures - if (is_numeric($returned) || $returned === false) { - $response->setStatusCode(400); - } - } + // Run "after" filters + $this->benchmark->start('after_filters'); + $response = $filters->run($uri, 'after'); + $this->benchmark->stop('after_filters'); if ($response instanceof ResponseInterface) { $this->response = $response; @@ -595,7 +571,7 @@ protected function getRequestObject() return; } - if ($this->isSparked() || $this->isPhpCli()) { + if ($this->isPhpCli()) { $this->request = Services::clirequest($this->config); } else { $this->request = Services::request($this->config); @@ -871,9 +847,7 @@ protected function createController() * CI4 supports three types of requests: * 1. Web: URI segments become parameters, sent to Controllers via Routes, * output controlled by Headers to browser - * 2. Spark: accessed by CLI via the spark command, arguments are Command arguments, - * sent to Commands by CommandRunner, output controlled by CLI class - * 3. PHP CLI: accessed by CLI via php public/index.php, arguments become URI segments, + * 2. PHP CLI: accessed by CLI via php public/index.php, arguments become URI segments, * sent to Controllers via Routes, output varies * * @param mixed $class @@ -882,21 +856,12 @@ protected function createController() */ protected function runController($class) { - if ($this->isSparked()) { - // This is a Spark request - /** @var CLIRequest $request */ - $request = $this->request; - $params = $request->getArgs(); - - $output = $class->_remap($this->method, $params); - } else { - // This is a Web request or PHP CLI request - $params = $this->router->params(); + // This is a Web request or PHP CLI request + $params = $this->router->params(); - $output = method_exists($class, '_remap') - ? $class->_remap($this->method, ...$params) - : $class->{$this->method}(...$params); - } + $output = method_exists($class, '_remap') + ? $class->_remap($this->method, ...$params) + : $class->{$this->method}(...$params); $this->benchmark->stop('controller'); @@ -1095,7 +1060,7 @@ protected function callExit($code) /** * Sets the app context. * - * @phpstan-param 'php-cli'|'spark'|'web' $context + * @phpstan-param 'php-cli'|'web' $context * * @return $this */ diff --git a/system/Config/Routes.php b/system/Config/Routes.php index 0f16b675a8ad..114974005dce 100644 --- a/system/Config/Routes.php +++ b/system/Config/Routes.php @@ -8,7 +8,6 @@ * For the full copyright and license information, please view * the LICENSE file that was distributed with this source code. */ - /* * System URI Routing * @@ -20,4 +19,4 @@ */ // CLI Catchall - uses a _remap to call Commands -$routes->cli('ci(:any)', '\CodeIgniter\CLI\CommandRunner::index/$1'); +// $routes->cli('ci(:any)', '\CodeIgniter\CLI\CommandRunner::index/$1'); diff --git a/tests/system/CLI/ConsoleTest.php b/tests/system/CLI/ConsoleTest.php index 685f56bac733..aff85170403b 100644 --- a/tests/system/CLI/ConsoleTest.php +++ b/tests/system/CLI/ConsoleTest.php @@ -13,7 +13,6 @@ use CodeIgniter\CodeIgniter; use CodeIgniter\Config\DotEnv; -use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockCLIConfig; use CodeIgniter\Test\Mock\MockCodeIgniter; @@ -38,26 +37,19 @@ protected function setUp(): void $_SERVER['app.baseURL'] = 'http://example.com/'; } - $_SERVER['argv'] = [ - 'spark', - 'list', - ]; - $_SERVER['argc'] = 2; - CLI::init(); - $this->app = new MockCodeIgniter(new MockCLIConfig()); - $this->app->setContext('spark'); + $this->app->initialize(); } public function testNew() { - $console = new Console($this->app); + $console = new Console(); $this->assertInstanceOf(Console::class, $console); } public function testHeader() { - $console = new Console($this->app); + $console = new Console(); $console->showHeader(); $this->assertGreaterThan( 0, @@ -70,24 +62,55 @@ public function testHeader() public function testNoHeader() { - $console = new Console($this->app); + $console = new Console(); $console->showHeader(true); $this->assertSame('', $this->getStreamFilterBuffer()); } public function testRun() { - $request = new CLIRequest(config('App')); - $this->app->setRequest($request); - - $console = new Console($this->app); - $console->run(true); + $this->initCLI(); - // close open buffer - ob_end_clean(); + $console = new Console(); + $console->run(); // make sure the result looks like a command list $this->assertStringContainsString('Lists the available commands.', $this->getStreamFilterBuffer()); $this->assertStringContainsString('Displays basic usage information.', $this->getStreamFilterBuffer()); } + + public function testBadCommand() + { + $this->initCLI('bogus'); + + $console = new Console(); + $console->run(); + + // make sure the result looks like a command list + $this->assertStringContainsString('Command "bogus" not found', $this->getStreamFilterBuffer()); + } + + public function testHelpCommandDetails() + { + $this->initCLI('help', 'session:migration'); + + $console = new Console(); + $console->run(); + + // make sure the result looks like more detailed help + $this->assertStringContainsString('Description:', $this->getStreamFilterBuffer()); + $this->assertStringContainsString('Usage:', $this->getStreamFilterBuffer()); + $this->assertStringContainsString('Options:', $this->getStreamFilterBuffer()); + } + + /** + * @param array $command + */ + protected function initCLI(...$command): void + { + $_SERVER['argv'] = ['spark', ...$command]; + $_SERVER['argc'] = count($_SERVER['argv']); + + CLI::init(); + } } From be9b0546d5ce9e5ed6cdadd52104db36ebe28f4c Mon Sep 17 00:00:00 2001 From: Andrey Pyzhikov <5071@mail.ru> Date: Fri, 17 Jun 2022 00:39:04 +0800 Subject: [PATCH 2/5] spark-rework: docs&conf. --- app/Config/Routes.php | 6 -- system/CLI/CommandRunner.php | 75 -------------- system/Config/Routes.php | 22 ----- tests/system/CLI/CommandRunnerTest.php | 98 ------------------- tests/system/CLI/ConsoleTest.php | 6 -- user_guide_src/source/changelogs/v4.3.0.rst | 12 ++- user_guide_src/source/cli/cli_controllers.rst | 3 + user_guide_src/source/incoming/routing.rst | 5 +- 8 files changed, 16 insertions(+), 211 deletions(-) delete mode 100644 system/CLI/CommandRunner.php delete mode 100644 system/Config/Routes.php delete mode 100644 tests/system/CLI/CommandRunnerTest.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ff2ac645cb9a..71b7a86de469 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -5,12 +5,6 @@ // Create a new instance of our RouteCollection class. $routes = Services::routes(); -// Load the system's routing file first, so that the app and ENVIRONMENT -// can override as needed. -if (is_file(SYSTEMPATH . 'Config/Routes.php')) { - require SYSTEMPATH . 'Config/Routes.php'; -} - /* * -------------------------------------------------------------------- * Router Setup diff --git a/system/CLI/CommandRunner.php b/system/CLI/CommandRunner.php deleted file mode 100644 index ef4ed057b606..000000000000 --- a/system/CLI/CommandRunner.php +++ /dev/null @@ -1,75 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace CodeIgniter\CLI; - -use CodeIgniter\Controller; -use Config\Services; -use ReflectionException; - -/** - * Command runner - */ -class CommandRunner extends Controller -{ - /** - * Instance of class managing the collection of commands - * - * @var Commands - */ - protected $commands; - - /** - * Constructor - */ - public function __construct() - { - $this->commands = Services::commands(); - } - - /** - * We map all un-routed CLI methods through this function - * so we have the chance to look for a Command first. - * - * @param string $method - * @param array $params - * - * @throws ReflectionException - * - * @return mixed - */ - public function _remap($method, $params) - { - return $this->index($params); - } - - /** - * Default command. - * - * @throws ReflectionException - * - * @return mixed - */ - public function index(array $params) - { - $command = array_shift($params) ?? 'list'; - - return $this->commands->run($command, $params); - } - - /** - * Allows access to the current commands that have been found. - */ - public function getCommands(): array - { - return $this->commands->getCommands(); - } -} diff --git a/system/Config/Routes.php b/system/Config/Routes.php deleted file mode 100644 index 114974005dce..000000000000 --- a/system/Config/Routes.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ -/* - * System URI Routing - * - * This file contains any routing to system tools, such as command-line - * tools for migrations, etc. - * - * It is called by Config\Routes, and has the $routes RouteCollection - * already loaded up and ready for us to use. - */ - -// CLI Catchall - uses a _remap to call Commands -// $routes->cli('ci(:any)', '\CodeIgniter\CLI\CommandRunner::index/$1'); diff --git a/tests/system/CLI/CommandRunnerTest.php b/tests/system/CLI/CommandRunnerTest.php deleted file mode 100644 index 825d0b85579e..000000000000 --- a/tests/system/CLI/CommandRunnerTest.php +++ /dev/null @@ -1,98 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace CodeIgniter\CLI; - -use CodeIgniter\Log\Logger; -use CodeIgniter\Test\CIUnitTestCase; -use CodeIgniter\Test\StreamFilterTrait; -use Config\Services; - -/** - * @internal - */ -final class CommandRunnerTest extends CIUnitTestCase -{ - use StreamFilterTrait; - - private static Logger $logger; - private static CommandRunner $runner; - - public static function setUpBeforeClass(): void - { - self::$logger = service('logger'); - self::$runner = new CommandRunner(); - - self::$runner->initController(service('request'), service('response'), self::$logger); - } - - public function testGoodCommand() - { - self::$runner->index(['list']); - - // make sure the result looks like a command list - $this->assertStringContainsString('Lists the available commands.', $this->getStreamFilterBuffer()); - $this->assertStringContainsString('Displays basic usage information.', $this->getStreamFilterBuffer()); - } - - public function testDefaultCommand() - { - self::$runner->index([]); - - // make sure the result looks like basic help - $this->assertStringContainsString('Lists the available commands.', $this->getStreamFilterBuffer()); - $this->assertStringContainsString('Displays basic usage information.', $this->getStreamFilterBuffer()); - } - - public function testHelpCommand() - { - self::$runner->index(['help']); - - // make sure the result looks like basic help - $this->assertStringContainsString('Displays basic usage information.', $this->getStreamFilterBuffer()); - $this->assertStringContainsString('help command_name', $this->getStreamFilterBuffer()); - } - - public function testHelpCommandDetails() - { - self::$runner->index(['help', 'session:migration']); - - // make sure the result looks like more detailed help - $this->assertStringContainsString('Description:', $this->getStreamFilterBuffer()); - $this->assertStringContainsString('Usage:', $this->getStreamFilterBuffer()); - $this->assertStringContainsString('Options:', $this->getStreamFilterBuffer()); - } - - public function testCommandProperties() - { - $commands = self::$runner->getCommands(); - $command = new $commands['help']['class'](self::$logger, Services::commands()); - - $this->assertSame('Displays basic usage information.', $command->description); - $this->assertNull($command->notdescription); - } - - public function testEmptyCommand() - { - self::$runner->index([null, 'list']); - - // make sure the result looks like a command list - $this->assertStringContainsString('Lists the available commands.', $this->getStreamFilterBuffer()); - } - - public function testBadCommand() - { - self::$runner->index(['bogus']); - - // make sure the result looks like a command list - $this->assertStringContainsString('Command "bogus" not found', $this->getStreamFilterBuffer()); - } -} diff --git a/tests/system/CLI/ConsoleTest.php b/tests/system/CLI/ConsoleTest.php index aff85170403b..513f59d1ef7f 100644 --- a/tests/system/CLI/ConsoleTest.php +++ b/tests/system/CLI/ConsoleTest.php @@ -41,12 +41,6 @@ protected function setUp(): void $this->app->initialize(); } - public function testNew() - { - $console = new Console(); - $this->assertInstanceOf(Console::class, $console); - } - public function testHeader() { $console = new Console(); diff --git a/user_guide_src/source/changelogs/v4.3.0.rst b/user_guide_src/source/changelogs/v4.3.0.rst index a9c5bc64f000..79a71bb07b46 100644 --- a/user_guide_src/source/changelogs/v4.3.0.rst +++ b/user_guide_src/source/changelogs/v4.3.0.rst @@ -12,7 +12,9 @@ Release Date: Unreleased BREAKING ******** -none. +Behavior Changes +================ +- The ``spark`` file has been changed due to a change in the processing of Spark commands. Enhancements ************ @@ -20,11 +22,17 @@ Enhancements - Added the ``StreamFilterTrait`` to make it easier to work with capturing data from STDOUT and STDERR streams. See :ref:`testing-overview-stream-filters`. - Added before and after events to ``BaseModel::insertBatch()`` and ``BaseModel::updateBatch()`` methods. See :ref:`model-events-callbacks`. - Added ``$routes->useSupportedLocalesOnly(true)`` so that the Router returns 404 Not Found if the locale in the URL is not supported in ``Config\App::$supportedLocales``. See :ref:`Localization ` +- The call handler for Spark commands from the ``CodeIgniter\CodeIgniter`` class has been extracted. This will reduce the cost of console calls. Changes ******* -none. +- Changed the processing of Spark commands: + - The ``CodeIgniter\CodeIgniter`` no longer handles Spark commands. + - The ``CodeIgniter::isSparked()`` method has been removed. + - The ``CodeIgniter\CLI\CommandRunner`` class has been removed due to a change in Spark commands processing. + - The system route configuration file ``system/Config/Routes.php`` has been removed. + - The route configuration file ``app/Config/Routes.php`` has been changed. Removed include of system routes configuration file. Deprecations ************ diff --git a/user_guide_src/source/cli/cli_controllers.rst b/user_guide_src/source/cli/cli_controllers.rst index c4230091de7c..d40c0b4ca490 100644 --- a/user_guide_src/source/cli/cli_controllers.rst +++ b/user_guide_src/source/cli/cli_controllers.rst @@ -85,3 +85,6 @@ If you want to make sure running via CLI, check the return value of :php:func:`i However, CodeIgniter provides additional tools to make creating CLI-accessible scripts even more pleasant, include CLI-only routing, and a library that helps you with CLI-only tools. + +.. note:: It is recommended to use Spark Commands for CLI scripts instead of calling controllers via CLI. + See the :doc:`spark_commands` page for detailed information. \ No newline at end of file diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index dc27a5aeb8e3..a0d941fe676a 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -327,6 +327,9 @@ available from the command line: .. warning:: If you enable auto-routing and place the command file in **app/Controllers**, anyone could access the command with the help of auto-routing via HTTP. +.. note:: It is recommended to use Spark Commands instead of CLI routes. + See the :doc:`spark_commands` page for detailed information. + Global Options ============== @@ -716,7 +719,6 @@ The output is like the following: +--------+------------------+------------------------------------------+----------------+-----------------------+ | GET | / | \App\Controllers\Home::index | invalidchars | secureheaders toolbar | | GET | feed | (Closure) | invalidchars | secureheaders toolbar | - | CLI | ci(.*) | \CodeIgniter\CLI\CommandRunner::index/$1 | | | | auto | / | \App\Controllers\Home::index | invalidchars | secureheaders toolbar | | auto | home | \App\Controllers\Home::index | invalidchars | secureheaders toolbar | | auto | home/index[/...] | \App\Controllers\Home::index | invalidchars | secureheaders toolbar | @@ -734,7 +736,6 @@ When you use Auto Routing (Improved), the output is like the following: +-----------+-------------------------+------------------------------------------+----------------+---------------+ | Method | Route | Handler | Before Filters | After Filters | +-----------+-------------------------+------------------------------------------+----------------+---------------+ - | CLI | ci(.*) | \CodeIgniter\CLI\CommandRunner::index/$1 | | | | GET(auto) | product/list/../..[/..] | \App\Controllers\Product::getList | | toolbar | +-----------+-------------------------+------------------------------------------+----------------+---------------+ From ef4e60f6254b33509ad418abc5a8e4cf5c1b7027 Mon Sep 17 00:00:00 2001 From: Andrey Pyzhikov <5071@mail.ru> Date: Fri, 17 Jun 2022 01:16:31 +0800 Subject: [PATCH 3/5] spark-rework: exit code --- user_guide_src/source/cli/cli_commands.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/user_guide_src/source/cli/cli_commands.rst b/user_guide_src/source/cli/cli_commands.rst index 8766673b15d8..542cef9b6b4e 100644 --- a/user_guide_src/source/cli/cli_commands.rst +++ b/user_guide_src/source/cli/cli_commands.rst @@ -82,6 +82,12 @@ Our demo command might have a ``run()`` method something like: See the :doc:`CLI Library ` page for detailed information. +Command termination +=================== + +By default, the command terminates with a success code of ``0``. To change the exit code, for example on error, +the ``run()`` method must return an integer in the range 0 - 254. `PHP exit `_. + *********** BaseCommand *********** From 0dc8b110b16018a28a4f177f8dce352192679b49 Mon Sep 17 00:00:00 2001 From: Andrey Pyzhikov <5071@mail.ru> Date: Fri, 17 Jun 2022 19:07:50 +0800 Subject: [PATCH 4/5] spark-rework: upgrade_430.rst & other docs --- user_guide_src/source/cli/cli_commands.rst | 12 +++- user_guide_src/source/incoming/routing.rst | 2 +- .../source/installation/upgrade_430.rst | 62 +++++++++++++++++++ 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 user_guide_src/source/installation/upgrade_430.rst diff --git a/user_guide_src/source/cli/cli_commands.rst b/user_guide_src/source/cli/cli_commands.rst index 542cef9b6b4e..b51fe5ca2afb 100644 --- a/user_guide_src/source/cli/cli_commands.rst +++ b/user_guide_src/source/cli/cli_commands.rst @@ -83,10 +83,16 @@ Our demo command might have a ``run()`` method something like: See the :doc:`CLI Library ` page for detailed information. Command termination -=================== +------------------- -By default, the command terminates with a success code of ``0``. To change the exit code, for example on error, -the ``run()`` method must return an integer in the range 0 - 254. `PHP exit `_. +By default, the command exits with a success code of ``0``. If an error is encountered while executing a command, +you can terminate the command by using the ``return`` language construct with an exit code in the ``run()`` method. + +For example, ``return EXIT_ERROR;`` + +This approach can help with debugging at the system level, if the command, for example, is run via crontab. + +You can use the ``EXIT_*`` exit code constants defined in the ``app/Config/Constants.php`` file. *********** BaseCommand diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index a0d941fe676a..26c247cf7978 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -328,7 +328,7 @@ available from the command line: anyone could access the command with the help of auto-routing via HTTP. .. note:: It is recommended to use Spark Commands instead of CLI routes. - See the :doc:`spark_commands` page for detailed information. + See the :doc:`../cli/spark_commands` page for detailed information. Global Options ============== diff --git a/user_guide_src/source/installation/upgrade_430.rst b/user_guide_src/source/installation/upgrade_430.rst new file mode 100644 index 000000000000..2f35abf47156 --- /dev/null +++ b/user_guide_src/source/installation/upgrade_430.rst @@ -0,0 +1,62 @@ +############################# +Upgrading from 4.2.1 to 4.3.0 +############################# + +Please refer to the upgrade instructions corresponding to your installation method. + +- :ref:`Composer Installation App Starter Upgrading ` +- :ref:`Composer Installation Adding CodeIgniter4 to an Existing Project Upgrading ` +- :ref:`Manual Installation Upgrading ` + +.. contents:: + :local: + :depth: 2 + +Mandatory File Changes +********************** + +spark +===== + +The following files received significant changes and +**you must merge the updated versions** with your application: + +* ``spark`` + +.. important:: If you do not update this file, Spark commands will not work at all after running ``composer update``. + + The upgrade procedure, for example, is as follows:: + + > composer update + > cp vendor/codeigniter4/framework/spark . + +Breaking Enhancements +********************* + +- Since the launch of Spark Commands was extracted from ``CodeIgniter\CodeIgniter``, there may be problems running these commands if the ``Services::codeigniter()`` service has been overridden. + +Project Files +************* + +Numerous files in the **project space** (root, app, public, writable) received updates. Due to +these files being outside of the **system** scope they will not be changed without your intervention. +There are some third-party CodeIgniter modules available to assist with merging changes to +the project space: `Explore on Packagist `_. + +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: + +* ``app/Config/Routes.php`` + * Due to the fact that the approach to running Spark Commands has changed, there is no longer a need to load the internal routes of the framework. + +All Changes +=========== + +This is a list of all files in the **project space** that received changes; +many will be simple comments or formatting that have no effect on the runtime: + +* app/Config/Routes.php +* spark From 15021055e3d59aca564a656c71c7d9d0c344084b Mon Sep 17 00:00:00 2001 From: Andrey Pyzhikov <5071@mail.ru> Date: Sat, 18 Jun 2022 16:56:50 +0800 Subject: [PATCH 5/5] spark-rework: docs --- user_guide_src/source/cli/cli_commands.rst | 2 +- user_guide_src/source/installation/upgrading.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/cli/cli_commands.rst b/user_guide_src/source/cli/cli_commands.rst index b51fe5ca2afb..22ba6ab2fb09 100644 --- a/user_guide_src/source/cli/cli_commands.rst +++ b/user_guide_src/source/cli/cli_commands.rst @@ -82,7 +82,7 @@ Our demo command might have a ``run()`` method something like: See the :doc:`CLI Library ` page for detailed information. -Command termination +Command Termination ------------------- By default, the command exits with a success code of ``0``. If an error is encountered while executing a command, diff --git a/user_guide_src/source/installation/upgrading.rst b/user_guide_src/source/installation/upgrading.rst index 3570419e19c2..baa5b424c395 100644 --- a/user_guide_src/source/installation/upgrading.rst +++ b/user_guide_src/source/installation/upgrading.rst @@ -12,6 +12,7 @@ upgrading from. .. toctree:: :titlesonly: + upgrade_430 upgrade_421 upgrade_420 upgrade_418