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

Use PHP to define the services and routes of the app #721

Open
wants to merge 1 commit into
base: master
from

Conversation

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 10, 2020

Q A
License MIT
Doc issue/PR -

This PR is here to demonstrate the new capabilities of Symfony 5.1.
Basically, we can now develop a full Symfony app in a single file, like "microframeworks"
No services.yaml, no routes.yaml here.

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

@danabrey

This comment has been minimized.

Copy link

danabrey commented Jan 10, 2020

There is a lot of documentation and tutorial content that will become confusing when this change is made. SymfonyCasts doesn't generally refer to PHP service/route configuration even being a possibility, every example is based on the .yaml files. I realise these can be updated but hopefully that transition can be made quickly enough to not put off too many newcomers :)

@nicolas-grekas nicolas-grekas force-pushed the nicolas-grekas:php-dsl branch from 3097a59 to 1d2916c Jan 10, 2020
Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

@nicolas-grekas nicolas-grekas force-pushed the nicolas-grekas:php-dsl branch from 1d2916c to 3369748 Jan 10, 2020
Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.


// add more service definitions when explicit configuration is needed
// please note that last definitions always *replace* previous ones
//$services->set(...);

This comment has been minimized.

Copy link
@yceruto

yceruto Jan 10, 2020

Member

I like this approach a lot, but I'd prefer a separate config/services.php file.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Jan 10, 2020

Author Member

That'd be way more confusing. Here, we have full context, see the type hint on the method. This makes autocompletion just work. In a separate file, you loose this context.

This comment has been minimized.

Copy link
@yceruto

yceruto Jan 10, 2020

Member

what about a PHPdoc /** @var ContainerConfigurator $container */ ?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Jan 10, 2020

Author Member

Make it a PR to compare :)

This comment has been minimized.

Copy link
@yceruto

yceruto Jan 10, 2020

Member

It would be a pleasure, after you mark it ready :)

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Jan 10, 2020

Author Member

I can't, the CI has a bug :)
But consider it ready, use my fork.

@nicolas-grekas nicolas-grekas force-pushed the nicolas-grekas:php-dsl branch from 3369748 to 74f319b Jan 10, 2020
Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

@nicolas-grekas

This comment has been minimized.

Copy link
Member Author

nicolas-grekas commented Jan 10, 2020

The validation error from the bot is a bug /cc @fabpot :)

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

@@ -15,14 +16,41 @@ protected function configureContainer(ContainerConfigurator $container): void
{
$container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
$container->import('../config/{services}.yaml');

This comment has been minimized.

Copy link
@ogizanagi

ogizanagi Jan 10, 2020

Member

I'm not convinced removing the base services and routes files is a great step forward. I think the less we have to tweak the Kernel in userland, the best it is. Especially I don't find this much friendly for newcomers.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Jan 11, 2020

Author Member

Newcomers will be able to discover the framework using autocompletion. I call that more friendly to them :) Also using PHP can be seen as more friendly.
The DI configuration for an app is very thin nowadays, there is no need to build a full architecture to organize it - at least at the beginning of a project.
(note that I'm specifically talking about the app's config. vendors do need dedicated files, yaml is the best for them)

@weaverryan

This comment has been minimized.

Copy link
Member

weaverryan commented Jan 10, 2020

There is a lot of documentation and tutorial content that will become confusing when this change is made. SymfonyCasts doesn't generally refer to PHP service/route configuration even being a possibility, every example is based on the .yaml files. I realise these can be updated but hopefully that transition can be made quickly enough to not put off too many newcomers :)

Yea, this is the BIG cost - not to be taken lightly. I think it's at least good to explore though.

In practice, if we were to make a big recipe change like this, it makes more sense on a major version (even if the major version doesn't contain the feature that's required to power the recipe). Then you can say "Oh, in Symfony 6, it's done this new way". For SymfonyCasts, if we made this change for 5.1, then any Symfony 5 screencasts we make between now and May (next 5ish months) will have a big outdated piece. I don't think it's worth it - especially because routes.yaml and services.yaml are not huge YAML pain-points anymore (as you don't do a lot of coding in them, typically thank to autowiring & annotations).

@javiereguiluz

This comment has been minimized.

Copy link
Member

javiereguiluz commented Jan 10, 2020

Thanks for proposing this feature!

I like it a lot ... but I have a minor comment: I agree with Yonel and Maxime ... I like this approach, but I'd prefer to keep the config/services.php and config/routes.php files.

I think it makes things easier to understand, especially for newcomers, and also solves the problem that would make the Kernel class grow too much (up to thousands of lines) when you have lots of routes or services.

@nicolas-grekas

This comment has been minimized.

Copy link
Member Author

nicolas-grekas commented Jan 11, 2020

The Kernel holds nothing but configuration. The Kernel is configuration. Look at it.
I get this is surprising, like anything new and unexpected.
Yet the Kernel is the perfect place to do configuration - that's its only purpose actually.

Like I mentioned to @yceruto, the Kernel is actually much better than a random file in a folder, because it has context: the use statements, the type hint of the method, the MicroKernelTrait.

All these are the heart of a better configuration system that works with autocompletion.

@Pierstoval

This comment has been minimized.

Copy link
Contributor

Pierstoval commented Jan 11, 2020

I also disagree. If one ends up having a big Kernel, it means that on each HTTP request, this "big kernel" is loaded for no reason (loaded, not executed).

Contrary to services.{yaml,php} which is loaded only at compile-time.

Also, Kernel is documented and explained as the "app encapsulator". App config is mostly in config/.

An alternative to provide such direct example and demonstration would be a special skeleton or generator to create a single-file app with only the Kernel.

@nicolas-grekas nicolas-grekas force-pushed the nicolas-grekas:php-dsl branch from 74f319b to 704bb49 Jan 11, 2020
Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

@nicolas-grekas nicolas-grekas marked this pull request as ready for review Jan 11, 2020
Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request does not pass validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.