Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function run(Core $app, Http $answer) : Answer
 {
     # Build an answer: in cli, the http answer does not interest us
     $help = PHP_EOL . " Commands" . PHP_EOL . PHP_EOL . "   controller  Run a controller class by its name" . PHP_EOL . "   protocol    Protocol you wanna provide (http, https) to generate absolute url" . PHP_EOL . "   domain      Domain name you wanna provide to generate absolute url" . PHP_EOL . "   port        Network port you wanna provide (80, 443, 8000...) to generate absolute url" . PHP_EOL . "   directory   Directory of the application, relative to the web root" . PHP_EOL . "   path        Relative path to the bootstrap file in web context" . PHP_EOL . "   url         Call an url based on the router" . PHP_EOL . PHP_EOL . " Example" . PHP_EOL . PHP_EOL . "   core url:/article/1 protocol:https domain:myapp.com" . PHP_EOL . PHP_EOL;
     # Returns the answer
     return $answer->setData($help);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function run(Core $app, Http $answer) : Answer
 {
     # Create the render and set some attributes
     $render = new Html($app->getCore() . 'views/welcome.php');
     # Returns the answer
     return $answer->setData($render->run($app));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function run(Core $app, Http $answer) : Answer
 {
     # Set a default error
     $answer->setStatus(500);
     $data['error'] = $data['title'] = 'Exception';
     # Create the render and set some attributes
     $render = new Html($app->getCore() . 'views/exception.php');
     if ($app->getException() !== null) {
         # Core custom exception only
         if ($app->getException() instanceof \Core\HttpException) {
             $answer->setStatus($app->getException()->getStatus());
         }
         if (defined('insight')) {
             # Get the detailed exception
             $data['error'] = sprintf("%s\n\n#  %s(%s)\n%s", $app->getException()->getMessage(), $app->getException()->getFile(), $app->getException()->getLine(), str_replace('Stack trace:', '', $app->getException()->getTraceAsString()));
         } else {
             # Get an user acceptable error message
             $data['error'] = $app->getException()->getMessage();
         }
     }
     # Returns the answer
     return $answer->setData($render->run($app, $data));
 }
Пример #4
0
 public function testWrongRedirection()
 {
     $this->expectException(\Exception::class);
     $answer = new Http();
     $answer->doRedirection('http://127.0.0.1/', 500);
 }