Symfony Consoleアプリケーションで実行中のパスを取得する方法はありますか? 例(phpインタープリターを想定PATH
):
cd /tmp
php /home/user/myapplication/app/console.php mycommand
から起動された/tmp
とおりに戻る必要があります。console.php
/tmp
Symfony Consoleアプリケーションで実行中のパスを取得する方法はありますか? 例(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());
}
}