Ejemplo n.º 1
0
 /**
  * Single entry point for most of use cases in which the passed application will be bootstrapped,
  * configured and run in appropriate mode.
  *
  * Most of applications should use this method as it controls the whole application flow from start to the end
  * of the process in a most standard way.
  *
  * It returns whatever result of running the application.
  * 
  * @param  AbstractApplication $application Application to be ran.
  * @param  string              $env         [optional] Environment in which the application should be ran. Default: `dev`.
  * @param  boolean             $debug       [optional] Should application be ran in debug mode? Default: `true`.
  * @param  int                 $mode        [optional] Mode in which the application should be ran.
  *                                          This is one of the `Framework::MODE_*` constants. Default: `Framework::MODE_WEB`.
  * @return mixed
  *
  * @codeCoverageIgnore
  */
 public static function run(AbstractApplication $application, $env = 'dev', $debug = true, $mode = self::MODE_WEB)
 {
     $framework = new static();
     // console and command modes should attempt to read env and debug from argv
     if ($mode === self::MODE_CONSOLE || $mode === self::MODE_COMMAND) {
         list($env, $debug) = static::getEnvDebugFromArgv($_SERVER['argv'], $env, $debug);
     }
     $framework->warmup($application, $env, $debug);
     switch ($mode) {
         case self::MODE_CONSOLE:
             $result = $framework->runConsole($application);
             break;
         case self::MODE_COMMAND:
             $input = new ArgvInput();
             $result = $framework->runCommand($application, $input);
             break;
         case self::MODE_TEST:
             $result = $framework->runTest($application);
             break;
         case self::MODE_WEB:
         default:
             $request = Request::createFromGlobals();
             $result = $framework->runWebRequest($application, $request);
     }
     return $result;
 }