Skip to content
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

[Runtime] Update ReactPHP example #19727

Open
wants to merge 3 commits into
base: 7.1
Choose a base branch
from

Conversation

chadyred
Copy link
Contributor

@chadyred chadyred commented Apr 1, 2024

Hello,

Based on update : https://github.com/reactphp/reactphp/blob/1.x/README.md

I make a more explicit example for reader to be able to test without being frustrated at the end of the doc.

GIT example :

reactPHP

Thanks :)

@carsonbot carsonbot added this to the 7.1 milestone Apr 1, 2024
@chadyred chadyred force-pushed the doc/update-custom-runtime branch 7 times, most recently from d16b434 to 54ea2ae Compare April 1, 2024 14:17
@chadyred
Copy link
Contributor Author

chadyred commented Apr 1, 2024

CI make me trouble about "[Missing class] Class, interface or trait", where are classes should be declared ?

components/runtime.rst Outdated Show resolved Hide resolved
@OskarStark
Copy link
Contributor

CI make me trouble about "[Missing class] Class, interface or trait", where are classes should be declared ?

Can be ignored 👍

@OskarStark OskarStark modified the milestones: 7.1, 6.4 Apr 3, 2024
require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';

return static function (): RequestHandlerInterface {
return new class implements RequestHandlerInterface {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the common use case for a react-php application would be to define your request handler as an anonymous class in the front controller, as this does really allow testing your logic (or at least it makes it harder). The previous code suggesting to instantiate a class makes more sense to me (however, changing the return type of the closure to RequestHandlerInterface might make sense).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @stof , sure, in fact this PR is to avoid frustration about testing this example with a minimal source code. Why not showing what "SomeCustomPsr15Application" could looks like ? (on another piece of code) It is for having a full functional example, for you is it too much ? In my mind, when I read it, I came to the fact it misses "things", maybe it is enough to stop at the "SomeCustomPsr15Application", but it requires more research if we want to enjoy the moment we end the reading to enjoy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I keep it simple, the full example could be too much as it requires attention to maintain details about it in the future (it depends too much of an external lib)


return function (array $context): SomeCustomPsr15Application {
return new SomeCustomPsr15Application();
$_SERVER['APP_RUNTIME'] = ReactPhpRuntime::class;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be set here?

Copy link
Contributor Author

@chadyred chadyred Apr 4, 2024

Choose a reason for hiding this comment

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

It is for the application : by default it uses the SymfonyRuntime on the autoload_runtime, this is the way to choose our Runtime

$runtime = $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? 'Symfony\\Component\\Runtime\\SymfonyRuntime';

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if that is a good way to demo it in the example though. This would override whatever you would specify in the ENV of the webserver for example. Users might get the wrong impression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will push a shorter version with all feedbacks, thanks @alcohol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I push a new version without all this detail as explain just above to stof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants