function __construct($db_index = NULL, $installation_data = NULL) { $this->_core =& Vevui::get(); if ($installation_data && array_key_exists('missing', $installation_data)) { $this->_core->missing_component(get_class($this), $installation_data['missing']); } $config = $this->_core->e->db; if (NULL === $db_index) { $db_config_key = $config->default_schema; $db_config_value = $config->databases->{$db_config_key}; } else { $db_config_key = $db_index; $db_config_value = $config->databases->{$db_index}; } if (array_key_exists($db_config_key, self::$_drivers)) { $this->_drv =& self::$_drivers[$db_config_key]['drv']; } else { $drv = $db_config_value->drv; if (!self::$_sqldrv_loaded) { require SYS_PATH . '/core/sqldrv.php'; self::$_sqldrv_loaded = TRUE; } $drv_class = 'Drv_' . $drv; if (!class_exists($drv_class)) { require SYS_PATH . '/core/drvs/' . $drv . '.php'; } $data = Vevui::get_installation_data(); $data = array_key_exists('drv', $data) && array_key_exists($drv, $data['drv']) ? $data['drv'][$drv] : NULL; $this->_drv = new $drv_class($db_config_value, $data); self::$_drivers[$db_config_key]['drv'] =& $this->_drv; self::$_drivers[$db_config_key]['functions'] = $this->_drv->register_functions(); } $this->_config_key = $db_config_key; }
function __get($model_name) { $data = Vevui::get_installation_data(); $data = isset($data['m'][$model_name]) ? $data['m'][$model_name] : NULL; require APP_MODELS_PATH . '/' . $model_name . '.php'; return $this->{$model_name} = new $model_name($data); }
function __get($library_name) { $data = Vevui::get_installation_data(); if ($this->_user_libraries) { $folder = APP_LIBRARIES_PATH; $data = isset($data['ul'][$library_name]) ? $data['ul'][$library_name] : NULL; } else { $folder = SYS_PATH . '/libraries'; $data = isset($data['l'][$library_name]) ? $data['l'][$library_name] : NULL; } require $folder . '/' . $library_name . '.php'; return $this->{$library_name} = new $library_name($data); }
public function route() { $app = $this->e->app; $this->_uri = urldecode($_SERVER['REQUEST_URI']); // Strip /index.php if exists. $pos = strpos($this->_uri, '/index.php'); if (0 === $pos) { $this->_uri = substr($this->_uri, strlen('/index.php')); } // Check if query string is activated if ($app->query_string) { if (FALSE !== ($query_pos = strpos($this->_uri, '?'))) { $query_string = substr($this->_uri, $query_pos + 1); $this->_uri = substr($this->_uri, 0, $query_pos); // Check if query string character set is valid if (!preg_match('/^[=&' . $app->url_chars . ']+$/i', $query_string)) { $this->not_found(); } } } // Apply URI Routing rules if (property_exists($app, 'routes')) { foreach ($app->routes as $pattern => $redir) { $count = 0; $this->_uri = preg_replace('/' . str_replace('/', '\\/', $pattern) . '/', $redir, $this->_uri, 1, $count); if ($count) { break; } } } // Check if URI character set is valid if (!preg_match('/^[\\/' . $app->url_chars . ']+$/i', $this->_uri)) { $this->not_found(); } $uri_segs = explode('/', $this->_uri); $uri_segs_count = count($uri_segs); $this->_request_class = $app->default_controller; $this->_request_method = 'index'; $request_params = array(); if ('' !== $uri_segs[1]) { $this->_request_class = strtolower($uri_segs[1]); } if (2 < $uri_segs_count) { if ('' !== $uri_segs[2]) { $this->_request_method = $uri_segs[2]; } $request_params = array_slice($uri_segs, 3); } // Call controller/method $filepath = APP_CONTROLLERS_PATH . '/' . $this->_request_class . '.php'; require SYS_PATH . '/core/baselog.php'; require SYS_PATH . '/core/log.php'; require SYS_PATH . '/core/ctrl.php'; if (!file_exists($filepath)) { $this->not_found(); } require $filepath; $data = Vevui::get_installation_data(); $data = array_key_exists('c', $data) && array_key_exists($this->_request_class, $data['c']) ? $data['c'][$this->_request_class] : NULL; $this->_request_ctrl = new $this->_request_class($data); if (!is_subclass_of($this->_request_ctrl, 'Ctrl') || !strncmp($this->_request_method, '_', 1)) { $this->not_found(); } ob_start(); call_user_func_array(array($this->_request_ctrl, $this->_request_method), $request_params); ob_flush(); }