Example #1
0
 public function __construct($params, $base_dir)
 {
     // Construction of the AbstractApplication
     parent::__construct($params, $base_dir);
     $mm = $this->sm->get('pegase.core.module_manager');
     // Services are now loaded
     try {
         // We send the event
         $event = new ApplicationEvent('application.loaded');
         $response = $this->sm->get('pegase.core.event_manager')->send($event);
         if ($response != null) {
             $response->send();
             return;
         }
         // get the router
         $router = $this->sm->get('pegase.core.router');
         $uri = $this->sm->get('pegase.core.request')->get_uri();
         $controller_and_method = $router->get_with_uri($uri);
         if ($controller_and_method == null) {
             echo "Router Error: The URI '" . $uri . "' doesn't match with any route !";
         } else {
             $controller = $controller_and_method[0];
             $method = $controller_and_method[1];
             $params = $controller_and_method[2];
             $response = call_user_func_array(array($controller, $method), $params);
             //PegaseException new NGException("test");
             $response->send();
         }
         $event = new ApplicationEvent('application.end');
         $this->sm->get('pegase.core.event_manager')->send($event);
     } catch (PegaseException $e) {
         $content = "<p>Caught PegaseException ('" . str_replace("\n", '<br />', $e->getMessage()) . "'):<br />" . str_replace("\n", '<br />', $e) . "</p>";
         $event = new ExceptionEvent("application.exception", $content);
         $response = $this->sm->get('pegase.core.event_manager')->send($event);
         if ($response == null) {
             $response = new Response();
             // Getting the 'twig' service
             $twig = $this->sm->get('pegase.component.template.twig');
             // creating a response
             $response = new Response();
             $response->write($twig->render($mm->get_file('Pegase/Core', 'Application/Views/exception.twig.html'), array('content' => $content)));
         }
         $response->send();
     } catch (\Exception $e) {
         $content = "<p>Caught " . get_class($e) . " ('" . str_replace("\n", '<br />', $e->getMessage()) . "'):<br />" . str_replace("\n", '<br />', $e) . "</p>";
         $event = new ExceptionEvent("application.exception", $content);
         $response = $this->sm->get('pegase.core.event_manager')->send($event);
         if ($response == null) {
             $response = new Response();
             // Getting the 'twig' service
             $twig = $this->sm->get('pegase.component.template.twig');
             // creating a response
             $response = new Response();
             $response->write($twig->render($mm->get_file('Pegase/Core', 'Application/Views/exception.twig.html'), array('content' => $content)));
         }
         $response->send();
     }
 }
Example #2
0
 public function __construct($params, $argc, $argv, $base_dir)
 {
     parent::__construct($params, $base_dir);
     $sm = $this->sm;
     $shell = new \Pegase\Core\Shell\Service\Shell($sm, array($argc, $argv));
     $sm->set('pegase.core.shell', $shell);
     //$shell->load_commands();
     $output = $shell->get_output();
     $formater = $output->get_text_formater();
     // les commandes ont besoin de $shell dans le conteneur
     // c'est pour cela que le service n'est pas crée et chargé en même temps
     $module_manager = $sm->get('pegase.core.module_manager');
     //    $module_manager->load_commands($sm);
     // -------
     try {
         if ($argc >= 2) {
             $commande = $argv[1];
             array_shift($argv);
             // on enlève le premier élément de argv
             array_shift($argv);
             // idem: on enlève le nom de la commande,
             // ainsi, on ne laisse que les paramètres de la commande dans $argv
             if ($shell->contains($commande)) {
                 $shell->execute($commande, $argv);
             } else {
                 $output->write_line($formater->set_color('The command ', 'blue') . $formater->set_color($commande, 'red') . $formater->set_color(' is not defined, maybe you wanna call one of these commands: ', 'blue'));
                 $shell->execute('shell:commands:search', array($commande));
             }
         } else {
             $shell->execute('shell:commands:help', array());
         }
         //throw new NGException("test");
     } catch (NGException $e) {
         $shell->set_color('green', 'red');
         echo "Caught NGException ('", $e->getMessage(), "'):\n", $e, "\n";
     }
     //$shell->get_output()->set_color(0)->end_line();
 }