Exemplo n.º 1
0
 /**
  * Renders the response for the exception.
  *
  * @return Response The response to be sent.
  */
 public function render($exception)
 {
     $exception = $exception instanceof PHP7ErrorException ? $exception->getError() : $exception;
     list(, $baseClass) = namespaceSplit(get_class($exception));
     if (substr($baseClass, -9) === 'Exception') {
         $baseClass = substr($baseClass, 0, -9);
     }
     $action = (new Text($baseClass))->camelBackize() ?: 'error500';
     $class = Core::className('Error', 'Controller', 'Controller');
     $controller = new $class();
     if (!in_array($action, get_class_methods($controller))) {
         $action = "processError";
     }
     return $controller->callAction($action, ["exception" => $exception, "request" => Router::getInstance()->request()]);
 }
Exemplo n.º 2
0
 /**
  * Main function
  *
  * @param array $argv argument list
  * @return mixed
  */
 public function main(array $argv)
 {
     $parser = $this->getParser();
     $parser->process($argv);
     if ($parser->optionIsSet("help")) {
         $this->out($parser->helpText());
         return 0;
     }
     $output = [['Route name', 'URI template', 'Defaults']];
     foreach (Router::getInstance()->routes() as $route) {
         $name = $route->name();
         if (\CoreTyson\isEmpty($name)) {
             $name = "Unnamed";
         }
         $output[] = [$name, $route->template, json_encode($route->defaults)];
     }
     $this->helper('Table')->output($output);
     $this->out();
 }
Exemplo n.º 3
0
 /**
  * Generates a formatted error message
  *
  * @param \Exception $exception Exception instance
  * @return string Formatted message
  */
 protected function _getMessage(Exception $exception)
 {
     $exception = $exception instanceof PHP7ErrorException ? $exception->getError() : $exception;
     $config = Configuration::getInstance();
     $message = sprintf("[%s] %s", get_class($exception), $exception->getMessage());
     $debug = $config->get('debug');
     if ($debug && method_exists($exception, 'getAttributes')) {
         $attributes = $exception->getAttributes();
         if ($attributes) {
             $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
         }
     }
     $request = Router::getInstance()->request();
     if ($request) {
         $message .= $this->_requestContext($request);
     }
     if ($config->get('Error/printTrace', false)) {
         $message .= "\nStack Trace:\n" . $exception->getTraceAsString() . "\n\n";
     }
     return $message;
 }
Exemplo n.º 4
0
 /**
  * Create a response thats redirects to given $url.
  *
  * @param string $url A string or array-based URL pointing to another location within the app,
  *     or an absolute URL
  * @param int $statusCode HTTP status code (eg: 301)
  * @return Response
  */
 public static function redirect(string $url, int $statusCode = 302)
 {
     $response = new Response();
     $response->statusCode($statusCode);
     if (strpos($url, '#') !== false) {
         $url = Router::getInstance()->url(substr($url, 1));
     }
     if (!$response->location()) {
         $response->location($url);
     }
     return $response;
 }
Exemplo n.º 5
0
 /**
  * Returns a URL based on provided parameters.
  *
  * @param string $url URL Name
  * @param array $params
  * @return string URL
  */
 public function build(string $url, array $params = [])
 {
     return \CoreTyson\h(Router::getInstance()->url($url, $params));
 }
Exemplo n.º 6
0
<?php

use CoreTyson\Network\Request;
use CoreTyson\Router\Router;
require "../config/bootstrap.php";
Router::getInstance()->dispatch(Request::createFromGlobals())->send();
Exemplo n.º 7
0
<?php

use CoreTyson\Router\Router;
$router = Router::getInstance();
$router->get('/', "App");