static function getInstance($infos = array()) { if (!isset(self::$instance)) { if (empty($infos)) { $settings = array('host' => Config::get('database_host'), 'port' => Config::get('database_port'), 'unix_socket' => Config::get('database_unix_socket'), 'dbname' => Config::get('database_dbname'), 'charset' => Config::get('database_charset'), 'user' => Config::get('database_user'), 'pass' => Config::get('database_passwd')); self::$instance = self::connection($settings); } else { $settings = array('host' => $infos['host'], 'port' => Config::get('database_port'), 'unix_socket' => Config::get('database_unix_socket'), 'dbname' => $infos['dbnale'], 'charset' => Config::get('database_charset'), 'user' => $infos['user'], 'pass' => $infos['pass']); self::$instance = self::connection($settings); } } return self::$instance; }
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); } }
static function urlfor2($apps = array(), $controller = '', $method = '', $args = array(), $absolute = true) { $apps = is_array($apps) ? $apps : array($apps); $domain = Config::Host_getConfigFromPath($apps); $appsdomain = Config::Host_getConfigFromDomain($domain['domain']); $apps = array_slice(array_reverse($apps), 0, 0 - count($appsdomain)); $controller = $controller == 'home' ? '' : $controller; $method = $method == 'index' ? '' : $method; $domain = !is_null(Config::get('app_base_url')) ? Config::get('app_base_url') : strtolower(explode('/', $_SERVER['SERVER_PROTOCOL'])[0]) . '://' . $_SERVER['HTTP_HOST'] . '/'; // traitement apps if (!empty($apps)) { if (is_array($apps)) { $apps = join('/', $apps) . '/'; } else { $apps .= '/'; } } else { $apps = ''; } // traitement controller if (empty($controller)) { if (!empty($args)) { $controller = 'home'; } } // traitement method if (empty($method)) { if (!empty($args)) { $method = 'index'; } } // traitement separateur if (!empty($controller) && !empty($method)) { $separator = '-'; } else { $separator = ''; } // traitement arg if (!empty($args)) { if (is_array($args)) { $args = '/' . join('/', $args); } else { $args = '/' . $args; } } else { $args = ''; } return $domain . $apps . $controller . $separator . $method . $args; }
static function redirectURL($url, $absolute = false, $external = false) { if (!$external) { $absolute ? header('Location: /' . $url) : header('Location: ' . Config::get('app_base_url') . $url); } else { header('Location: ' . $url); } exit; }