Php Symfony2-从命令访问用户定义的函数

Php Symfony2-从命令访问用户定义的函数,php,symfony,console,command,Php,Symfony,Console,Command,由于console命令只允许声明config()和execute()函数,如何声明用户定义的函数并调用它们?您可以定义并调用命令类中的任何函数: <?php namespace ...\Command; use ... class TestCommand extends Command { protected function execute(InputInterface $input, OutputInterface $output) { // ...

由于console命令只允许声明
config()
execute()
函数,如何声明用户定义的函数并调用它们?

您可以定义并调用命令类中的任何函数:

<?php

namespace ...\Command;

use ...

class TestCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output)
    {
       // ...

       $this->mySuperFunction();
    }

    protected function mySuperFunction()
    {
      // your code goes here...
    }
}
并使用它:

protected function mySuperFunction(OutputInterface $output)
{
    $output->write('hello world!');
}

请再说一遍你想要什么?当从控制台执行时,只调用
execute()
。您可以声明任何喜欢的方法并从execute调用它们
protected function mySuperFunction(OutputInterface $output)
{
    $output->write('hello world!');
}