Ejemplo n.º 1
0
 public static function getInstance($type = 'default')
 {
     if (!isset(self::$instance[$type])) {
         self::$instance[$type] = new static(\Panada\Resource\Config::database()[$type]);
     }
     return self::$instance[$type];
 }
Ejemplo n.º 2
0
 private function routingHandler()
 {
     $routes = Config::routes();
     Router::$patterns = $routes['pattern'];
     Router::$defaults = $routes['defaults'];
     foreach ($routes['route'] as $name => $route) {
         $class = $route['controller'];
         $method = $route['action'];
         unset($route['controller'], $route['action']);
         Router::route($name, $route, ['class' => $class, 'method' => $method]);
     }
     $uriComponents = ['host' => $this->uri->getHost(), 'port' => $this->uri->getPort(), 'method' => $this->uri->getRequestMethod(), 'scheme' => $this->uri->getScheme(), 'path' => '/' . $this->uri->getPathInfo()];
     // match
     if ($result = Router::find($uriComponents)) {
         try {
             $instance = new $result['class']();
         } catch (LoaderException $e) {
             if ($nextHandler = next($this->requstHandler)) {
                 $this->{$nextHandler}();
                 return;
             } else {
                 $this->throwHTTPException();
             }
         }
         $variables = Router::$variables;
         unset($variables['method'], $variables['protocol'], $variables['subdomain'], $variables['domain'], $variables['port']);
         $args = array_values($variables);
         $this->run($instance, $result['method'], $args);
     } else {
         if ($nextHandler = next($this->requstHandler)) {
             $this->{$nextHandler}();
             return;
         } else {
             $this->throwHTTPException();
         }
     }
 }
Ejemplo n.º 3
0
 public static function getInstance($type = 'default')
 {
     return new static(Resource\Config::database()[$type], false);
 }