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

Skip to content

[Console] Fix registering lazy command services with autoconfigure enabled #23556

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 1 commit into from
Jul 20, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Jul 17, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

For

_defaults:
    autoconfigure: true

App\:
    resource: '../../src/*'

App\Command\FooCommand:
    tags:
        - { name: console.command, command: foo }

Before you get the following error:

Missing "command" attribute on tag "console.command" for service "App\Command\FooCommand"

Now the command is lazy.


Btw, @Tobion's #22734 (comment)

Wouldn't it be more straightforward if aliases are just the additional tags using the command attribute as well?
Then there is no need for an alias property at all and this strange condition doesn't apply either.

Partially addressed here by removing the need for repeating the command attribute on each console.command tag

# before
tags:
    - { name: console.command, command: foo }
    - { name: console.command, command: foo, alias: foobar }

# after
tags:
    - { name: console.command, command: foo }
    - { name: console.command, alias: foobar }

Tobias proposal:

tags:
    - { name: console.command, command: app:my-command }
    - { name: console.command, command: app:my-alias }

I wanted to propose exactly the same at first, but finally found more clear to add a specific attribute for aliases, especially because relying on the order on which tags are defined sounds less good to me. Please tell me about your preference.

(And sorry for the noise around this feature, I want to polish it for 3.4)

@Tobion
Copy link
Contributor

Tobion commented Jul 17, 2017

Now if you have something like the following, the second command: bar is ignored, right? So it still depends on the order of the command tags, but magically ignores stuff. This is worse IMO.

tags:
    - { name: console.command, command: foo }
    - { name: console.command, command: bar, alias: foobar }

@chalasr chalasr force-pushed the console-command-tag branch from b428154 to 3d1dcf7 Compare July 18, 2017 09:23
@chalasr
Copy link
Member Author

chalasr commented Jul 18, 2017

Right, it's worse. The command must have only one command name and may have aliases, we need a rule that doesn't feel magic for determining it.

Updated this, now your example would throw:

Service "foobar" has multiple "console.command" tags with a different value for the "command" attribute, but the command must have only one name. Use the "alias" attribute instead.

The first command attribute found is the real command name. Better?

->setPublic(false)
->addTag('console.command', array('command' => 'my:command'))
->addTag('console.command', array('command' => 'other:name'))
;
Copy link
Contributor

@ro0NL ro0NL Jul 18, 2017

Choose a reason for hiding this comment

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

Still think this is the best option actually :)

specially because relying on the order on which tags are defined sounds less good to me

I guess it aims for to be explicit what getName returns, but do we care? It's the first one :) and practically there's no difference either. Low level perhaps, but thats not an issue for end users.

Alternatively; command: name, aliases: [name, nameN] and dont allow console.command more than once.

Alter-alternatively; perhaps command is a bad name due term duplication with console.command, what about only name: x?

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively; command: name, aliases: [name, nameN]

Tag attributes cannot be arrays :) that's what I'm trying to mimic

perhaps command is a bad name due term duplication with console.command, what about only name?

Not available :) - { name: console.command, command: foobar }

The command attribute is fine to me. What I don't like much is to call setName() on the command (mandatory) for the first command attribute found, and consider other as aliases. But if others think it's better, I'm ok for changing it

Copy link
Contributor

Choose a reason for hiding this comment

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

Tag attributes cannot be arrays

Didnt know that :| And for name well.. eh, right. Lets pretend that did not happen :)

Copy link
Contributor

Choose a reason for hiding this comment

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

What I don't like much is to call setName() on the command (mandatory) for the first command attribute found, and consider other as aliases.

Cant/shouldnt you do that from CommandLoader::get actually?

@ogizanagi
Copy link
Contributor

ogizanagi commented Jul 18, 2017

I tend to agree now that getting rid of the alias attribute and simply repeating the tag with a different command name would be better. In the case of commands registered in a command loader, the way to provide aliases for commands already is to register the same command with a different name.
With command loaders, aliases defined in the command itself already are almost just part of the command description. So it won't disturb me not reusing this term in the DI configuration. (Btw when documenting the lazy-commands feature, we should really highlight Command::$aliases is not used when using command loaders, appart by descriptors or once the command is instantiated loaded for the first time by the Application)

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jul 19, 2017
@chalasr chalasr force-pushed the console-command-tag branch from 3d1dcf7 to 167f191 Compare July 19, 2017 09:06
@chalasr
Copy link
Member Author

chalasr commented Jul 19, 2017

Updated for @Tobion suggestion.

@chalasr chalasr force-pushed the console-command-tag branch from 167f191 to 8a71aa3 Compare July 19, 2017 09:10
@fabpot
Copy link
Member

fabpot commented Jul 20, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 8a71aa3 into symfony:3.4 Jul 20, 2017
fabpot added a commit that referenced this pull request Jul 20, 2017
…oconfigure enabled (chalasr)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Fix registering lazy command services with autoconfigure enabled

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

For
```yaml
_defaults:
    autoconfigure: true

App\:
    resource: '../../src/*'

App\Command\FooCommand:
    tags:
        - { name: console.command, command: foo }
```

Before you get the following error:
> Missing "command" attribute on tag "console.command" for service "App\Command\FooCommand"

Now the command is lazy.

----
Btw, @Tobion's #22734 (comment)
> Wouldn't it be more straightforward if aliases are just the additional tags using the command attribute as well?
Then there is no need for an alias property at all and this strange condition doesn't apply either.

Partially addressed here by removing the need for repeating the `command` attribute on each `console.command` tag
```yaml
# before
tags:
    - { name: console.command, command: foo }
    - { name: console.command, command: foo, alias: foobar }

# after
tags:
    - { name: console.command, command: foo }
    - { name: console.command, alias: foobar }
```

Tobias proposal:

```yaml
tags:
    - { name: console.command, command: app:my-command }
    - { name: console.command, command: app:my-alias }
```

I wanted to propose exactly the same at first, but finally found more clear to add a specific attribute for aliases, especially because relying on the order on which tags are defined sounds less good to me. Please tell me about your preference.

(And sorry for the noise around this feature, I want to polish it for 3.4)

Commits
-------

8a71aa3 Fix registering lazy command services with autoconfigure enabled
@chalasr chalasr deleted the console-command-tag branch July 20, 2017 21:01
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.

7 participants