Example #1
0
 /**
  * Application entry point.
  */
 public static function start()
 {
     // hide errors
     error_reporting(E_ALL);
     ini_set('display_errors', 0);
     // use UTC on server
     date_default_timezone_set('UTC');
     // error/exception Handlers
     set_error_handler([__CLASS__, 'error']);
     set_exception_handler([__CLASS__, 'exception']);
     register_shutdown_function([__CLASS__, 'shutdown']);
     // configuration
     define('BRAMBLE_URL', self::get_app_url());
     Stopwatch::start()->register();
     Log::time('~init');
     // handle request
     Request::execute();
 }
Example #2
0
 /**
  * Execute the controller action.
  */
 public static function execute()
 {
     $instance = self::get();
     // take over buffering
     if (ob_get_level() === 0) {
         ob_start();
     }
     Log::debug("[uri] {$instance->method()} /{$instance->m_uri}");
     try {
         $routes = RouteMap::instance();
         $instance->m_route = $routes->find($instance->m_uri, $instance->m_method);
         if (!$instance->m_route) {
             throw new KnownException('E_ROUTING_ROUTE_NOT_FOUND', ['uri' => $instance->uri(), 'method' => $instance->method()]);
         }
         $controller_class_name = $instance->m_route->controller();
         try {
             $controller = new $controller_class_name($instance);
         } catch (\Exception $e) {
             throw new KnownException('E_INTERNAL_CONTROLLER_FAILED');
         }
         if (!$controller instanceof Controller) {
             throw new KnownException('E_INTERNAL_CONTROLLER_INVALID');
         }
         $response = $controller->execute();
     } catch (KnownException $e) {
         $response = $e->response();
     } catch (\Exception $e) {
         $response = (new KnownException('E_INTERNAL', NULL, $e))->response();
     }
     /*$leaked = ob_get_contents();
     		if ($leaked) {
     			// ignore for now
     		}*/
     ob_end_clean();
     // write instrumentation to log
     Log::time('~response');
     Stopwatch::instance()->stop();
     $response->body($response->body());
     $response->send();
 }