Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

gnugat
Copy link

QA
Doc fix?yes
New docs?no
Applies to2.4+
Fixed ticketsN/A

Command as a service can be useful to give access to services and
configuration parameters in theconfigure method.

A simple use case: you want to allow the user to set an option's default
value in theapp/config/parameters.yml file. Or the default value
needs to be computed by a service (database retrieval for instance).

With aContainerAwareCommand, this wouldn't be possible because the
configure method is called from the constructor, so the container
isn't set yet.

nixillaand others added3 commitsFebruary 12, 2014 16:28
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 staticOtherwise 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/ACommand as a service can be useful to give access to services andconfiguration parameters in the `configure` method.A simple use case: you want to allow the user to set an option's defaultvalue 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 the`configure` method is called from the constructor, so the containerisn'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
Copy link
Member

Choose a reason for hiding this comment

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

Typo: wan

@wouterj
Copy link
Member

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

@gnugat
Copy link
Author

Hi! I based my branch on 2.4, because command as service have been introduced in this version. How can I fix this?

@wouterj
Copy link
Member

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).

@gnugat
Copy link
Author

Ok I'll do that with the fixes. Cheers!

@gnugatgnugat closed thisMar 1, 2014
@gnugatgnugat mentioned this pull requestMar 1, 2014
``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
Copy link
Member

Choose a reason for hiding this comment

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

pass it [...] to

@gnugat
Copy link
Author

@xabbuh: this PR has been closed, the new one's here:#3621

weaverryan added a commit that referenced this pull requestMar 24, 2014
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/ACommand as a service can be useful to give access to services andconfiguration parameters in the `configure` method.A simple use case: you want to allow the user to set an option's defaultvalue 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 the`configure` method is called from the constructor, so the containerisn't set yet.Original PR:#3620Commits-------c8fe610 Moved back and listened to@weaverryane8b3320 Took into account@cordoval's feedback11bfe50 Added warning about performances6a7a25f Fixed@wouterj's feedbacke137951 Created a new articlecdd534a Added@lsmith77 and@dbu use casesa7b916e Fixed typos spotted by@cordovala055140 Took@wouterj's advices into account947ad92 [Console] Adding use cases to command as service
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@gnugat@wouterj@xabbuh@nixilla@weaverryan

[8]ページ先頭

©2009-2025 Movatter.jp