Ejemplo n.º 1
0
 /**
  * setConnection.
  *
  * @param   string group name
  * @param   string|array config
  */
 public static function setConnection($group, $params = array())
 {
     if (self::hasConnection($group)) {
         return false;
     }
     $class = '\\App\\Drivers\\DB\\' . implode('', array_map('ucfirst', explode('-', $group)));
     if (class_exists($class)) {
         try {
             $check = new ReflectionClass($class);
             if (!$check->implementsInterface('\\Viloveul\\Database\\IConnection')) {
                 throw new Exception('Database driver must implement of \\Viloveul\\Database\\IConnection');
             }
             self::$connections[$group] = $check->newInstance();
         } catch (ReflectionException $e) {
             throw new Exception($e->getMessage());
         }
     } else {
         $config = Configure::read('db', function ($value) use($group, $params) {
             return isset($value[$group]) ? $value[$group] : $params;
         });
         $dbconf = self::parseConfiguration($config);
         extract($dbconf);
         self::$connections[$group] = new Database\Manager($dsn, $username, $password, $prefix);
     }
 }
Ejemplo n.º 2
0
 /**
  * run
  * execute or running the application.
  */
 public function run()
 {
     $this->dispatcher->dispatch(Http\Request::createFromGlobals(), Configure::read('url_suffix'));
     $handler = $this->dispatcher->fetchHandler();
     if (empty($handler)) {
         throw new Exception('handler does not found');
     }
     try {
         $reflection = new ReflectionFunction($handler);
         $output = $reflection->invoke($this->dispatcher->fetchParams());
         $this->response->send($output);
     } catch (ReflectionException $e) {
         Debugger::handleException($e);
     }
 }