Example #1
0
 /**
  * Runner.
  */
 public function run()
 {
     // Session
     if ($this->config->application['session'] && session_id() === "") {
         session_start();
     }
     // Internal Autoload mechanism
     if (isset($this->config->application['autoload'])) {
         foreach ($this->config->application['autoload'] as $path) {
             $relativePath = $this->config->application['base'] . DIRECTORY_SEPARATOR . ltrim(rtrim($path, '/'), '/');
             $absolutePath = realpath($relativePath);
             // Register only if path exists
             if (file_exists($absolutePath)) {
                 $this->autoload->register($absolutePath);
             }
         }
     }
     // Needed for 'ClosureContext' visibility
     $this->autoload->register(dirname(__FILE__) . '/Closure/');
     // Register Application instance
     // So it can be injected within the user's controller
     $this->container->register($this);
     // Prepare routes
     foreach ($this->config->route as $expression => $route) {
         $this->route->set($expression, $route);
     }
     // Parse request, the actual route (URI) parsing process
     if ($this->route->parseRequest()) {
         $this->dispatch();
     } else {
         if (!$this->config->application['production']) {
             $this->http->header($this->http->getValue('SERVER_PROTOCOL') . ' 404 Not Found', true, 404);
             throw new Exception('Route Not Found');
         } else {
             $this->view->layout('error')->page('error.404')->render();
         }
     }
 }
Example #2
0
 /**
  * Runner.
  */
 public function run($request = null, $param = array())
 {
     if (isset($request)) {
         $this->command->setRequest($request);
     }
     if (count($param) > 0) {
         foreach ($param as $pk => $pv) {
             $this->param->{$pk} = $pv;
         }
     }
     // Internal Autoload mechanism
     if (isset($this->config->application['autoload'])) {
         foreach ($this->config->application['autoload'] as $path) {
             $relativePath = $this->config->application['base'] . DIRECTORY_SEPARATOR . ltrim(rtrim($path, '/'), '/');
             $absolutePath = realpath($relativePath);
             // Register only if path exists
             if (file_exists($absolutePath)) {
                 $this->autoload->register($absolutePath);
             }
         }
     }
     // Needed for 'ClosureContext' visibility
     $this->autoload->register(dirname(__FILE__) . '/Closure/');
     // Register Application instance
     // So it can be injected within the user's controller
     $this->container->register($this);
     // Prepare routes
     foreach ($this->config->route as $expression => $route) {
         $this->route->set($expression, $route);
     }
     // Parse request, the actual route (URI) parsing process
     if ($this->route->parseRequest()) {
         return $this->dispatch();
     } else {
         throw new Exception('Route Not Found');
     }
 }