Skip to content

Extracting the call handler for Spark commands from kernel. #6110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 18, 2022

Conversation

iRedds
Copy link
Collaborator

@iRedds iRedds commented Jun 11, 2022

Description
This is the concept of extracting the call to Spark commands from processing via routing. Commands are called directly, as when using the command() function. This will reduce the load on the console application in the form of Request, Response, Filters and Routes services and more.

In the beginning, the idea of creating an Application class was considered, from which the CodeIniter and Console classes would be inherited. This was necessary to initialize the application. But due to the fact that, at the request of one person, the core of the application turned into a service, there were difficulties with the implementation.

Therefore, the initialization of the application through the CodeIgniter class is saved.

The Console class now uses the Services::commands() service directly instead of using the CommandRunner class.
The CodeIgniter class has been cleared of processing Spark commands, and the Console class no longer processes Response.

Although this is not within the purview of the PR, I added the StreamFilterTrait trait, which correctly adds and removes filters for capturing stream output, since the current implementation in the tests is not correct enough in my opinion.
Depends on StreamFilterTrait #6112

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added 4.3 refactor Pull requests that refactor code labels Jun 11, 2022
@kenjis
Copy link
Member

kenjis commented Jun 11, 2022

I have not looked into this PR yet, but this is a big change.
It would take some time to review.

So could you please split StreamFilterTrait into a separate PR?
It is small and will be merged sooner than this.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right direction. We have some big conversations going around CLI and the app so it is helpful to have an actual implementation to look at. Let's make this our general discussion place at well, just for the sake of having a common thread.

@iRedds
Copy link
Collaborator Author

iRedds commented Jun 11, 2022

@kenjis StreamFilterTrait #6112

@kenjis kenjis added the docs needed Pull requests needing documentation write-ups and/or revisions. label Jun 15, 2022
@kenjis
Copy link
Member

kenjis commented Jun 15, 2022

It seems there is no problem.

@MGatner
Copy link
Member

MGatner commented Jun 15, 2022

I'm still in favor of this. The rest of the team is oddly quiet 😅 Let's get the User Guide and changelog updates done and then I will give them one last chance.


return $this->app->useSafeOutput($useSafeOutput)->run();
return $runner->run($command, $params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseCommand::run() called by Commands::run() returns void although not strictly because not typehinted. However, most of our implementations of commands I think don't return anything either. So the $exit in L85 in spark above will be null so always exit on EXIT_SUCCESS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that exit (0), unless of course the developer forcibly returns the desired value of the exit code.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is removed, does this mean that the CommandRunner will be removed? Or deprecated, at least?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CommandRunner class will be removed as there is no point in it. I'm already preparing changes.

@kenjis
Copy link
Member

kenjis commented Jun 17, 2022

===================

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 <https://www.php.net/manual/en/function.exit.php>`_.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of specifying the range, I think it would be better to use our constants for that?

defined('EXIT_SUCCESS') || define('EXIT_SUCCESS', 0); // no errors
defined('EXIT_ERROR') || define('EXIT_ERROR', 1); // generic error
defined('EXIT_CONFIG') || define('EXIT_CONFIG', 3); // configuration error
defined('EXIT_UNKNOWN_FILE') || define('EXIT_UNKNOWN_FILE', 4); // file not found
defined('EXIT_UNKNOWN_CLASS') || define('EXIT_UNKNOWN_CLASS', 5); // unknown class
defined('EXIT_UNKNOWN_METHOD') || define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
defined('EXIT_USER_INPUT') || define('EXIT_USER_INPUT', 7); // invalid user input
defined('EXIT_DATABASE') || define('EXIT_DATABASE', 8); // database error
defined('EXIT__AUTO_MIN') || define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
defined('EXIT__AUTO_MAX') || define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion! I forgot the constants.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes. I hope this is similar to what you were talking about.

@iRedds
Copy link
Collaborator Author

iRedds commented Jun 17, 2022

@kenjis I have doubts about the quality of the upgrade manual.

@kenjis
Copy link
Member

kenjis commented Jun 17, 2022

Please add.

--- 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

I think the upgrading is okay. Thanks.

@kenjis kenjis removed the docs needed Pull requests needing documentation write-ups and/or revisions. label Jun 17, 2022
Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kenjis kenjis merged commit 6e5b412 into codeigniter4:4.3 Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants