public function __construct() { if (!empty(Config::get('api_is_on'))) { if (Config::get('api_is_public') && Config::get('api_has_jsonp')) { header('Access-Control-Allow-Origin: *'); if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") { header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Access-Control-Max-Age: 1728000'); // 20 jours header("Content-Length: 0"); header("Content-Type: text/plain"); exit; } } } if (false === ($cache = Cache::get('access', get_class($this)))) { if (method_exists($this, '__melody_access')) { $this->__melody_access(); } if (method_exists($this, '__melody_init')) { $this->__melody_init(Request::getInstance()); } Cache::create('access', get_class($this), $this->method_access, 'on_demand'); } else { $this->method_access = $cache; } }
static function throwError($code, $msg = '') { if (empty(Config::getAll())) { if (!is_null(self::$apps)) { Config::loadFor(self::$apps); } else { Config::loadFor(array()); } } $action = !is_null(Config::get('access_error_' . $code . '_action')) ? Config::get('access_error_' . $code . '_action') : Config::get('access_error_default_action'); $method_array = !is_null(Config::get('access_error_' . $code . '_controller')) ? Config::get('access_error_' . $code . '_controller') : Config::get('access_error_default_controller'); if (is_null($action) || is_null($method_array)) { echo $code . ' : ' . $msg; exit; } else { list($controller, $method) = $method_array; switch ($action) { case 'redirect': self::redirectController($controller, $method, Tools::base64url_encode(serialize(array(FrontController::$uri, $code, $msg)))); break; case 'include': default: echo $controller::invoke($method, Request::getInstance(), $code, $msg); break; } } exit; }