Is there any way to get the running path in a Symfony Console application? For example (assuming php interpreter in PATH
):
cd /tmp
php /home/user/myapplication/app/console.php mycommand
Should return /tmp
as console.php
was launched from /tmp
.
The Symfony framework provides lots of commands through the bin/console script (e.g. the well-known bin/console cache:clear command). These commands are created with the Console component. You can also use it to create your own commands.
Process Management Software. Symphony allows you and your team to create well-structured work routines and automate recurring processes to increase productivity and team communication. Start using Symphony. Start using Symphony.
If you have file system access to the project Look inside the file for a line like: const VERSION = '5.0. 4'; that's the Symfony version number.
getcwd()
will do what you need. You can execute app/console from any directory, and PHP will know which one it is.
I used the following example to verify this.
<?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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With