Skip to content

[Framework] allow to create kernel-aware console applications without default commands #21019

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

FrancescoBorzi
Copy link
Contributor

@FrancescoBorzi FrancescoBorzi commented Dec 22, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT
Doc PR symfony/symfony-docs#7296

Suppose that you need to create a kernel-aware application:

// ...
$kernel = new AppKernel($env, $debug);
$application = new MyApplication($kernel);

$application->addCommands([
    // CUstom commands
    new MyCustomCommand(),
]);

$application->run($input);

The code above will create a console application with MyCustomCommand plus all the other default symfony commands.

With this PR you are able to specify whether or not you want to add the default commands:

$application = new MyApplication($kernel, false);
or
$application = new MyApplication($kernel, true); (default)

@FrancescoBorzi
Copy link
Contributor Author

@ro0NL here

@FrancescoBorzi FrancescoBorzi changed the title [Framework] allow to create kernel-aware console applications without… [Framework] allow to create kernel-aware console applications without default commands Dec 22, 2016
@ro0NL
Copy link
Contributor

ro0NL commented Dec 22, 2016

You could have changed the base branch on your previous PR as well ;-)

You should add a test if this is accepted 👍

@linaori
Copy link
Contributor

linaori commented Dec 22, 2016

This should make it easier to create single command applications I believe?

@FrancescoBorzi
Copy link
Contributor Author

@iltar yes, in particular kernel-aware ones

@FrancescoBorzi
Copy link
Contributor Author

Thanks all for reviewing this.

Now about the doc part, is there already a page which explains how to create kernel-aware console applications?

Afaik the only place where Symfony\Bundle\FrameworkBundle\Console\Application is mentioned is for testing commands.

@ro0NL
Copy link
Contributor

ro0NL commented Dec 25, 2016

Maybe a special note at https://symfony.com/doc/current/components/console/single_command_tool.html?

Howto create a single command app with the framework something like that?

@FrancescoBorzi
Copy link
Contributor Author

FrancescoBorzi commented Dec 25, 2016

@ro0NL I don't think so, because it hasn't to be necessarily one single command. It can be even with multiple commands.

Maybe it's better to create a new dedicated page about "How to create a kernel-aware console application" ?

@ro0NL
Copy link
Contributor

ro0NL commented Dec 25, 2016

It's about creating awareness of this small feature. I think the single command tool page has the most visits by now, and is best indexed.

Besides, this definitely relates to creating a truly single command tool with the framework ;-) If we explain it right there, people will probably understand this is applies to multiple commands as well.

@FrancescoBorzi
Copy link
Contributor Author

PR for the doc done:

symfony/symfony-docs#7296

@FrancescoBorzi
Copy link
Contributor Author

any news?

*/
public function __construct(KernelInterface $kernel)
public function __construct(KernelInterface $kernel, $loadDefaultCommands = true)
Copy link
Member

Choose a reason for hiding this comment

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

I would name it registerDefaultCommands to be consistent.

@nicolas-grekas
Copy link
Member

Moving to 4.1. Rebase on master needed, where PHP 7.1 features can be used btw.

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 8, 2017
@nicolas-grekas nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
@OskarStark
Copy link
Contributor

@FrancescoBorzi can you please rebase this PR?

@FrancescoBorzi
Copy link
Contributor Author

I opened this PR on 22 Dec 2016 so almost 3 years ago.

I no longer use Symfony for a while and to be honest I don't even remember what I did here.

Sorry.

@fabpot fabpot closed this Aug 1, 2019
@chalasr chalasr self-requested a review August 1, 2019 14:47
@nicolas-grekas nicolas-grekas removed this from the next milestone Oct 27, 2019
@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Oct 27, 2019
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.

10 participants