[英]Symfony2 - Accessing user-defined functions from a Command
由於控制台命令只允許聲明config()
和execute()
函數,如何聲明用戶定義的函數並調用它們?
您可以在Command類中定義和調用任何函數:
<?php
namespace ...\Command;
use ...
class TestCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
// ...
$this->mySuperFunction();
}
protected function mySuperFunction()
{
// your code goes here...
}
}
如果要輸出內容,請將輸出對象傳遞給函數
$this->mySuperFunction($output);
並使用它:
protected function mySuperFunction(OutputInterface $output)
{
$output->write('hello world!');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.