Symfony 1.4: Software Installed Environment for CLI

I have a project built on Symfony 1.4, and it has several environments - each developer has his own copy installed on his local machine, and therefore has his own environment.

I can dynamically set the environment in index.php, but how to do this for CLI tasks?

I could, of course, use --env = myenvironment for all tasks, but I would prefer it to use the same logic as mine in index.php

+3
source share
3 answers

I see that this question had a lot of opinions, so for reference I am sending the solution I came with.

, CLI, , , Subversion:

http://www.4pmp.com/2010/10/programmatically-set-environment-for-symfony-project/

+1

sfContext::getInstance()->getConfiguration()->getEnvironment()

+2

You could do something similar to this in your task:

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 works by default in the "prod" environment if the environment.cfg file does not exist. This also assumes that you only have the environment in the file (for example, "prod", "dev", "slappythefish", etc.).

0
source

Source: https://habr.com/ru/post/1739117/


All Articles