Skip to content
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

Command cannot depend on other command #48

Open
foglcz opened this issue Feb 8, 2016 · 2 comments
Open

Command cannot depend on other command #48

foglcz opened this issue Feb 8, 2016 · 2 comments

Comments

@foglcz
Copy link
Contributor

foglcz commented Feb 8, 2016

So I have interesting use-case. I have a command, which I want to execute from other command -- because one is maintenance and one is a one-time migration, which is quite extensive (essentially, we're upgrading systems.)

Soooo, I've did this:

console:
    commands:
        - App\Commands\Maintenance\Focus\Paths(%focusPaths%, @focusDibi.connection)
        - App\Commands\MigrationScripts\Y2016Q1\CleanupFocus(%focusPaths%, @focusDibi.connection)

Constructor looks like this:

namespace App\Commands\MigrationScripts\Y2016Q1;

use App\Commands\Maintenance\Focus\Paths;
use Dibi\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CleanupFocus extends Command
{
    /** @var Paths */
    private $pathsCommand;

    public function __construct(array $paths, Connection $focusDibi, Paths $pathsCommand)
    {
        parent::__construct('migrate:y2016q1:focus');
        $this->setDescription('Migrations for FOCUS database, 2016/Q1, the infrastructure overhaul');
        $this->pathsCommand = $pathsCommand;
        // ...
    }

    public function execute(InputInterface $input, OutputInterface $output)
    {
        // ...

        // set options & run the maintenance
        $input->setOption('all', true);
        $input->setOption('force', true);
        $this->pathsCommand->execute($input, $output);

        // ...
    }
}

BUT the DI builder throws a following exception:

[2016-02-08 19-50-14] Nette\DI\ServiceCreationException:
Service 'console.command.0':
Service of type App\Commands\Maintenance\Focus\Paths needed by App\Commands\MigrationScripts\Y2016Q1\CleanupFocus::__construct() not found. 
Did you register it in configuration file? 

Stack trace:
#0 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\Compiler.php(213): Nette\DI\ContainerBuilder->generateClasses(NULL, NULL)
#1 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\Compiler.php(139): Nette\DI\Compiler->generateCode(NULL, NULL)
#2 C:\Users\pptacek\www\projectname,ha!\vendor\nette\bootstrap\src\Bootstrap\Configurator.php(264): Nette\DI\Compiler->compile()
#3 [internal function]: Nette\Configurator->generateContainer(Object(Nette\DI\Compiler))
#4 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\ContainerLoader.php(111): call_user_func_array(Array, Array)
#5 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\ContainerLoader.php(76): Nette\DI\ContainerLoader->generate('Container_168f2...', Array)
#6 C:\Users\pptacek\www\projectname,ha!\vendor\nette\di\src\DI\ContainerLoader.php(41): Nette\DI\ContainerLoader->loadFile('Container_168f2...', Array)
#7 C:\Users\pptacek\www\projectname,ha!\vendor\nette\bootstrap\src\Bootstrap\Configurator.php(218): Nette\DI\ContainerLoader->load(Array, Array)
#8 C:\Users\pptacek\www\projectname,ha!\app\bootstrap.php(23): Nette\Configurator->createContainer()
#9 C:\Users\pptacek\www\projectname,ha!\www\index.php(6): require('C:\\Users\\pptace...')
#10 {main}
(stored in C:\Users\pptacek\www\projectname,ha!\app\..\log\exception--2016-02-08--19-50--1b383ca34c.html)�

If you'd point me to the proper point where I can fix this one, I'd apprecieate it. Cannot continue on it today, but will jump on it first thing tomorrow morning (basically - I need it working :)) )

Creating an issue, since in services section of Nette DI, you can reference other services from constructors -- so this is solvable, somehow.

I know, hotfix might be using @inject - didn't test.

@fprochazka
Copy link
Member

You could in fact name the command and pass it using the name reference.

console:
    commands:
        paths: App\Commands\Maintenance\Focus\Paths(%focusPaths%, @focusDibi.connection)
        - App\Commands\MigrationScripts\Y2016Q1\CleanupFocus(%focusPaths%, @focusDibi.connection, @console.command.paths)

But allowing autowiring might not be a bad idea, as I really see no reason to disallow it.

@fprochazka
Copy link
Member

fprochazka commented May 13, 2017

I will remove the disabling of autowiring, but this might cause some problems => it should go to next major.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants