/**
  * Handle request in stack
  * 
  * @param   object  $request  Request
  * @return  mixed
  */
 public function handle(Request $request)
 {
     $response = $this->next($request);
     $arguments = $this->app['arguments'];
     $output = $this->app['output'];
     // Check for interactivity flag and set on output accordingly
     if ($arguments->getOpt('non-interactive')) {
         $output->makeNonInteractive();
     }
     // Check for color flag and set on output accordingly
     if ($arguments->getOpt('no-colors')) {
         $output->makeUnColored();
     }
     // If task is help, set the output to our output class with extra methods for rendering help doc
     if ($arguments->get('task') == 'help') {
         $output = $output->getHelpOutput();
     }
     // If the format opt is present, try to use the appropriate output subclass
     if ($arguments->getOpt('format')) {
         $output = $output->getOutputFormatter($arguments->getOpt('format'));
     }
     // Register any user specific events
     if ($hooks = Config::get('hooks')) {
         foreach ($hooks as $trigger => $scripts) {
             foreach ($scripts as $script) {
                 Event::register($trigger, function () use($script, $output) {
                     if ($output->getMode() != 'minimal') {
                         $output->addLine("Running '{$script}'");
                     }
                     shell_exec(escapeshellcmd($script));
                 });
             }
         }
     }
     // Reset the output stored on the application
     $this->app->forget('output');
     $this->app->set('output', $output);
     return $response;
 }
 /**
  * Initialise the application
  *
  * @param  array $options an optional associative array of configuration settings.
  * @return void
  */
 public function initialise($options = [])
 {
     $arguments = App::get('arguments');
     $output = App::get('output');
     try {
         $arguments->parse();
     } catch (UnsupportedCommandException $e) {
         $output->error($e->getMessage());
     } catch (UnsupportedTaskException $e) {
         $output->error($e->getMessage());
     }
     // Check for interactivity flag and set on output accordingly
     if ($arguments->getOpt('non-interactive')) {
         $output->makeNonInteractive();
     }
     // Check for color flag and set on output accordingly
     if ($arguments->getOpt('no-colors')) {
         $output->makeUnColored();
     }
     // If task is help, set the output to our output class with extra methods for rendering help doc
     if ($arguments->get('task') == 'help') {
         $output = $output->getHelpOutput();
     }
     // If the format opt is present, try to use the appropriate output subclass
     if ($arguments->getOpt('format')) {
         $output = $output->getOutputFormatter($arguments->getOpt('format'));
     }
     // Register any user specific events
     if ($hooks = Config::get('hooks')) {
         foreach ($hooks as $trigger => $scripts) {
             foreach ($scripts as $script) {
                 Event::register($trigger, function () use($script, $output) {
                     if ($output->getMode() != 'minimal') {
                         $output->addLine("Running '{$script}'");
                     }
                     shell_exec(escapeshellcmd($script));
                 });
             }
         }
     }
     // Reset the output stored on the application
     App::forget('output');
     App::set('output', $output);
 }