Reputation: 2384
I have a project built on Symfony 1.4 and it has multiple environments - each developer has their own copy installed on their local machine and therefore has their own environment.
I am able to dynamically set the environment in index.php, but how can I do this for CLI tasks?
I could of course use --env=myenvironment on all tasks, but I would prefer it to be able to use the same logic as I have in index.php
Upvotes: 3
Views: 2833
Reputation: 27102
You could do something similar to this in your task perhaps:
class MyTask extends sfBaseTask
{
protected function configure()
{
// Env config file
$file = sfConfig::get("sf_config_dir") . DIRECTORY_SEPARATOR . "environment.cfg";
$env = (file_exists($file) ? file_get_contents($file) : "prod");
$this->addOptions(array(
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', $env),
}
}
The above should work; it defaults to the 'prod' environment if the environment.cfg file doesn't exist. This also assumes that you have just the environment in the file (eg 'prod', 'dev', 'slappythefish' etc).
Upvotes: 0