有什么方法可以在Symfony控制台应用程序中获取运行路径?例如(假设中的php解释器PATH
):
cd /tmp
php /home/user/myapplication/app/console.php mycommand
应返回/tmp
的console.php
是推出/tmp
。
getcwd()
会做你需要的。您可以从任何目录执行app / console,PHP会知道它是哪个目录。
我使用以下示例对此进行了验证。
<?php
namespace Acme\DemoBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class DemoCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('demo:cwd')
->setDescription('Get Current Working Directory')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(getcwd());
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句