contributte / console

:boom: Best minimal console (symfony/console) to Nette Framework (@nette)
https://contributte.org/packages/contributte/console.html
MIT License
91 stars 32 forks source link

Ability to set a custom console Application class #42

Closed becygroup closed 4 years ago

becygroup commented 4 years ago

I don't want to override whole extension only for changing the Application class.

Please, consider merge this. Thank you.

mabar commented 4 years ago

Did you try this? Any service from extensions (defined in loadConfiguration()) can be overriden in your config file.

services:
  console.application:
    factory: Your\Custom\Application

Btw, I am curious, why do you need to do that?

becygroup commented 4 years ago

You are right, it works. I was confused by this in ConsoleExtension:

public function loadConfiguration(): void
{
    // Skip if isn't CLI
    if ($this->cliMode !== true) {
        return;
    }

and was looking for change Application class only for cliMode, so I deny my self change like you did. But your way is totally right :-)

I need to change help of application (not only command help) and Symfony/Console/Application hasn't property/setter for that. So I need override method getHelp().

I'm closing this and thank you for your fast feedback :-)

mabar commented 4 years ago

I was confused by this in ConsoleExtension:

public function loadConfiguration(): void { // Skip if isn't CLI if ($this->cliMode !== true) { return; }

You should make console application service change in cli-only config

if (PHP_SAPI === 'cli') {
  $configurator->addConfig(__DIR__ . '/config/console.neon');
}