Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Expose tags as consts for PHP config autocompletion #24377

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

Closed
wants to merge 1 commit into from
Closed

Expose tags as consts for PHP config autocompletion #24377

wants to merge 1 commit into from

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented Sep 29, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets https://github.com/symfony/symfony/projects/6#card-4488902
License MIT
Doc PR N/A

Now that we have PHP based-config, it'll make sense to have tags exposed as constants for autocompletion & discoverability.

Consts are are defined in the bundles for discoverability and because that's where passes are configured.

@nicolas-grekas
Copy link
Member

Cool, I had that on my list :)
I propose to do it differently: instead of creating tags in random namespaces, I propose to put them all as class-less consts under the Symfony\Component\DependencyInjection\Loader\Configurator\tag namespace.
That way, in PHP DSL config files, ppl would just have to type tag\ to be provided with the full list of possible tags, all bundles included.

@ogizanagi ogizanagi changed the title Expose Tags classes for PHP config autocompletion Expose tags as consts for PHP config autocompletion Sep 29, 2017
@ogizanagi
Copy link
Contributor Author

ogizanagi commented Sep 29, 2017

Done. Using composer file autoload, but perhaps we could just require_once the Resources/di/tags.php file from the container extensions __construct method instead, so it's only available during compilation time.
EDIT: done in third commit.

Do you like segregation by components, like introduced in the second commit ?

capture d ecran 2017-09-29 a 17 57 58

vs

capture d ecran 2017-09-29 a 18 04 18

@fabpot
Copy link
Member

fabpot commented Sep 30, 2017

I'm 👎. I understand the goal, but that introduces another "name" for each tag. The current are well documented everywhere. Not sure if this is worth it.

@afurculita
Copy link
Contributor

@fabpot how about following the Events model: each bundle/component that introduces a new tag needs to add a new constant into a Tags class at the root of the bundle/component.

@ogizanagi
Copy link
Contributor Author

ogizanagi commented Sep 30, 2017

@afurculita: FI, that was the first version of this PR: ogizanagi@7a27b6b

Copy link
Member

@nicolas-grekas nicolas-grekas 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 a great DX improvement, as it allows autocompletion and far easier discovery.
I don't know if that'd be enough to convince fabpot, but I'd suggest the following changes:

  • stick to providing the consts for the purpose of the DSL only. Ie not use them anywhere internally.
  • use a CS convention to name consts that follows the tag name as closely as possible, eg dot=namespace, all the rest stays the same, case included.

In my local stash, I also started adding docblocks on the consts, as I believe that's a great place to have some words about what behavior each tag provides. Being able to have that info directly in a click in my IDE would be another great DX improvement that this would provide.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 30, 2017

To empty my stash, here is what I had:

<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator\tag;

/**
 * Define aliases based on the value of container parameters.
 *
 * The required "format" attribute defines the service to alias and can use any container parameter.
 *
 * You need to manually add the AutoAliasServicePass compiler pass to the container for this feature to work.
 */
const auto_alias = 'auto_alias';

namespace Symfony\Component\DependencyInjection\Loader\Configurator\tag\container;

/**
 * Enable services implementing the ServiceSubscriberInterface to have their service locator created automatically.
 *
 * The optional "key" and "id" attributes allow setting entries to the created service locator.
 * You can repeat this tag several times to set "key"/"id" pairs on the locator.
 */
const service_subscriber = 'container.service_subscriber';

@ogizanagi
Copy link
Contributor Author

In my local stash, I also started adding docblocks on the consts, as I believe that's a great place to have some words about what behavior each tag provides. Being able to have that info directly in a click in my IDE would be another great DX improvement that this would provide.

Of course, I'll update the PR to include those if we can convince @fabpot :)

@nicolas-grekas
Copy link
Member

The doc blocks could also be the place where we tell about which interface adds the tag by mean of autoconfiguration (when applicable.)

@nicolas-grekas
Copy link
Member

Moving to 4.1.

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 8, 2017
@nicolas-grekas
Copy link
Member

I'm closing because this is staling and controversial for now. Let's re-open later if we want.

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.

5 participants