0

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?

2
  • Please speficy more what do you want? As executing from the console only execute() is called. Commented May 13, 2013 at 14:43
  • 5
    You can declare any methods you like and call them from execute Commented May 13, 2013 at 14:45

1 Answer 1

2

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!');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.