function loadHostvars() { if (empty(self::$hosts)) { if (false === ($cache = Cache::get('coreconfig/host', 'hostconfig'))) { $vars = json_decode(file_get_contents(__DIR__ . '/config/hosts.json'), true); $host = implode('.', array_slice(explode('.', $_SERVER['HTTP_HOST']), -2)); if (is_null($vars)) { FrontController::throwError(500, 'Hosts config syntax error'); } else { self::$hosts = array('domain' => array(), 'path' => array(), 'base_config' => array('domain' => array(), 'path' => array())); self::$hosts['domain']['_' . $host] = array(); self::$hosts['path']['/'] = array('action' => 'redirect', 'recursive' => true, 'domain' => $host, 'full_domain' => false); self::$hosts['base_config'] = self::$hosts; foreach ($vars as $key => $var) { $full_domain = isset($var['full_domain']) && $var['full_domain']; self::$hosts['domain'][$full_domain ? '_' . $key : '_' . $key . '.' . $host] = array_filter(explode('/', substr($var['path'], 1))); self::$hosts['path'][$var['path']] = array('action' => $var['action'], 'recursive' => $var['recursive'], 'domain' => $full_domain ? $key : $key . '.' . $host, 'full_domain' => $full_domain); } Cache::create('coreconfig/host', 'hostconfig', self::$hosts, 'on_demand'); } } else { self::$hosts = $cache; } } }
public function __melody_invoke($method, $args) { $role = isset($_SESSION[Config::Core_get('session_content_varname')][Config::Core_get('access_role_session_key')]) ? $_SESSION[Config::Core_get('session_content_varname')][Config::Core_get('access_role_session_key')] : Config::Core_get('access_role_if_missing'); $access_role = isset($this->method_access[$method]) ? $this->method_access[$method] : (!is_null(Config::get('access_role_app')) ? Config::get('access_role_app') : Config::Core_get('access_role_default')); if ($role >= $access_role) { $class = get_class($this); if (false === ($cache = Cache::get('controller', $class . '_' . $method))) { ob_start(); $__melody_response = call_user_func_array(array($this, $method), $args); $buffer = ob_get_clean(); echo self::execute_view($__melody_response, $buffer, $class, $args[0]); } else { echo $cache; } } else { FrontController::throwError(403); } }
public function throwError($code, $msg = '') { FrontController::throwError($code, $msg); }
static function run($uri) { FrontController::routeTo($uri); }