-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Console] command as service #3620
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
Conversation
Otherwise you'll get: ``` ContextErrorException: Runtime Notice: call_user_func() expects parameter 1 to be a valid callback, non-static method Vendor\Package\Validator::validate() should not be called statically in Symfony/Component/Validator/Constraints/CallbackValidator.php ```
…be static (nixilla) This PR was merged into the 2.4 branch. Discussion ---------- Callback: [Validator, validate] expects validate to be static Otherwise you'll get: ``` ContextErrorException: Runtime Notice: call_user_func() expects parameter 1 to be a valid callback, non-static method Vendor\Package\Validator::validate() should not be called statically in Symfony/Component/Validator/Constraints/CallbackValidator.php ``` Commits ------- 027bc97 Callback: [Validator, validate] expects validate to be static
| Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.4+ | Fixed tickets | N/A Command as a service can be useful to give access to services and configuration parameters in the `configure` method. A simple use case: you want to allow the user to set an option's default value in the `app/config/parameters.yml` file. Or the default value needs to be computed by a service (database retrieval for instance). With a `ContainerAwareCommand`, this wouldn't be possible because the `configure` method is called from the constructor, so the container isn't set yet.
bundles and automatically register your commands. For the ones implementing | ||
the ``ContainerAwareCommand`` interface, Symfony will even inject the container. | ||
|
||
If you wan to, you can instead register them as services in the container using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: wan
Thank you for the addition! However, it seems like you based your PR on another branch than the branch itself... This should also be merged into the 2.3 branch |
Hi! I based my branch on 2.4, because command as service have been introduced in this version. How can I fix this? |
Ah, my bad :) Well, you can leave this PR open. Since your branch is based on 2.4, it's easy to merge into the 2.4 branch. If you really want to do it the correct way, you have to close this one and open it again against the 2.4 branch (you can't change the base branch of a PR on github). |
Ok I'll do that with the fixes. Cheers! |
``configure`` method | ||
|
||
For example, Imagine you want to provide a default value for the ``name`` | ||
option. You could hard code a string and pass it as the 4th argument of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass it [...] to
This PR was merged into the 2.4 branch. Discussion ---------- [Console] Command as service | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.4+ | Fixed tickets | N/A Command as a service can be useful to give access to services and configuration parameters in the `configure` method. A simple use case: you want to allow the user to set an option's default value in the `app/config/parameters.yml` file. Or the default value needs to be computed by a service (database retrieval for instance). With a `ContainerAwareCommand`, this wouldn't be possible because the `configure` method is called from the constructor, so the container isn't set yet. Original PR: #3620 Commits ------- c8fe610 Moved back and listened to @weaverryan e8b3320 Took into account @cordoval's feedback 11bfe50 Added warning about performances 6a7a25f Fixed @wouterj's feedback e137951 Created a new article cdd534a Added @lsmith77 and @dbu use cases a7b916e Fixed typos spotted by @cordoval a055140 Took @wouterj's advices into account 947ad92 [Console] Adding use cases to command as service
Command as a service can be useful to give access to services and
configuration parameters in the
configure
method.A simple use case: you want to allow the user to set an option's default
value in the
app/config/parameters.yml
file. Or the default valueneeds to be computed by a service (database retrieval for instance).
With a
ContainerAwareCommand
, this wouldn't be possible because theconfigure
method is called from the constructor, so the containerisn't set yet.