php - Getting services from the command class -


how can service command class? have been trying use containerawarecommand parent of command class, , using $this->getcontainer()->get('my_service'), when run command in cli, following error:

call undefined method symfony\component\console\application::getkernel()

inside getcontainer() method of containerawarecommand class.

the file through run command is:

<?php      require_once __dir__.'/../vendor/autoload.php';     require_once __dir__.'/appkernel.php';      use appbundle\console\command\changeemailcommand;     use symfony\component\console\application;     use symfony\component\console\input\argvinput;     use symfony\component\debug\debug;      $input = new argvinput();     $env = $input->getparameteroption(array('--env', '-e'), getenv('symfony_env') ?: 'dev');     $debug = getenv('symfony_debug') !== '0' && !$input->hasparameteroption(array('--no-debug', '')) && $env !== 'prod';      if ($debug) {         debug::enable();     }      $kernel = new appkernel($env, $debug);     $application = new application($kernel);     $application->add(new changeemailcommand());     $application->run(); 

you have use application of frameworkbundle instead of console component. class extends 1 in console component, adds awareness of kernel , container. application version doesn't have awareness (as it's designed standalone use, outside of symfony context), resulting in "method getkernel() not exists".

so change this:

use symfony\component\console\application; 

to:

use symfony\bundle\frameworkbundle\console\application; 

btw, won't need create file yourself. can use app/console in standard edition: https://github.com/symfony/symfony-standard/blob/2.7/app/console when installed symfony using installer/composer create-project.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -