Example #1
0
 /**
  * Instantiate front controller. Request and response objects are optional
  * 
  * @param Request  $request
  * @param Response $response
  */
 public function __construct(Request $request = null, Response $response = null)
 {
     // Lazy load request
     if (!isset($request)) {
         // Set default method
         $method = 'get';
         // Only overwrite request method when it is set correctly
         if (\array_key_exists('REQUEST_METHOD', $_SERVER)) {
             // Get request method
             $method = \strtolower($_SERVER['REQUEST_METHOD']);
         }
         // Create request
         $this->request = new Request($method, $_REQUEST);
     } else {
         $this->request = $request;
     }
     // Lazy load response
     if (!isset($response)) {
         $this->response = new Response();
     } else {
         $this->response = $response;
     }
     // Enable debug mode when set
     if ('on' === $this->request->getParam('debug')) {
         \error_reporting(-1);
         \ini_set('display_errors', 'On');
         $this->response->enableDebug();
     }
 }