/** * {@inheritdoc} */ public function run(Core $app, Http $answer) : Answer { # Build an answer: in cli, the http answer does not interest us $help = PHP_EOL . "[33m Commands[0m" . PHP_EOL . PHP_EOL . "[32m controller[0m Run a controller class by its name" . PHP_EOL . "[32m protocol[0m Protocol you wanna provide (http, https) to generate absolute url" . PHP_EOL . "[32m domain[0m Domain name you wanna provide to generate absolute url" . PHP_EOL . "[32m port[0m Network port you wanna provide (80, 443, 8000...) to generate absolute url" . PHP_EOL . "[32m directory[0m Directory of the application, relative to the web root" . PHP_EOL . "[32m path[0m Relative path to the bootstrap file in web context" . PHP_EOL . "[32m url[0m Call an url based on the router" . PHP_EOL . PHP_EOL . "[33m Example[0m" . PHP_EOL . PHP_EOL . " core [32murl[0m:/article/1 [32mprotocol[0m:https [32mdomain[0m:myapp.com" . PHP_EOL . PHP_EOL; # Returns the answer return $answer->setData($help); }
/** * {@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)); }
/** * {@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)); }
public function testWrongRedirection() { $this->expectException(\Exception::class); $answer = new Http(); $answer->doRedirection('http://127.0.0.1/', 500); }