As a console command only allows for the config() and execute() functions to be declared, how can I declare user-defined functions and call them?
1 Answer
You can define and call any function in your Command class:
<?php
namespace ...\Command;
use ...
class TestCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
// ...
$this->mySuperFunction();
}
protected function mySuperFunction()
{
// your code goes here...
}
}
If you want to output something, then pass your output object to your function
$this->mySuperFunction($output);
and use it:
protected function mySuperFunction(OutputInterface $output)
{
$output->write('hello world!');
}
execute()is called.