public function __construct() { $this->contentType("text/plain"); $this->status(200); $view_class = Ac::config("views.class", "Ac_View"); $this->view = new $view_class(); }
/** * Constructor (protected access) * * @param array|null $context If present, these are used instead of global server variables * @return void */ protected function __construct(array $context = null) { if (!empty($context)) { $this->context = array_merge(self::$default_context, $context); } else { $con = array(); $_SERVER = array_merge(self::$default_server, $_SERVER); /** * In some HTTP servers DOCUMENT_ROOT points to a unaccessible directory or is not set */ $_SERVER['DOCUMENT_ROOT'] = substr($_SERVER['SCRIPT_FILENAME'], 0, -strlen($_SERVER['SCRIPT_NAME'])); /** * Server name, domain or hostname */ $con['host'] = $_SERVER['SERVER_NAME']; $con["host_id"] = ac_str_slug($con["host"], "_", array(".")); $con["host_url"] = ""; /** * Scheme and protocol version */ $protocol = explode('/', trim($_SERVER["SERVER_PROTOCOL"]), 2); $https = strtolower($_SERVER["HTTPS"]) == "on" ? true : false; $con["scheme"] = $https ? 'https' : strtolower($protocol[0]); $con["version"] = strtolower($protocol[1]); /** * Server port */ $con["port"] = $_SERVER['SERVER_PORT']; $con["host_url"] = $con["scheme"] . '://' . $con["host"] . ($con["port"] == 80 ? "" : ":" . $con["port"]) . "/"; /** * Request origin (sent by modern browsers in preflight Cross Domain requests) */ $con["origin"] = $_SERVER["HTTP_ORIGIN"]; /** * Request method (supports method overriding using X_REQUEST_METHOD in POST) */ $con['method'] = isset($_POST["X_REQUEST_METHOD"]) ? $_POST["X_REQUEST_METHOD"] : $_SERVER['REQUEST_METHOD']; /** * Directory: * Relative directory or subdirectory of the public document root */ if (isset($_SERVER["SCRIPT_NAME"])) { $dir = explode("/", trim($_SERVER["SCRIPT_NAME"], "/ ")); array_pop($dir); //script file, usually index.php $dir = implode("/", $dir); $dir = !empty($dir) ? $dir . "/" : null; } else { $dir = ""; } $con['directory'] = $dir; /* * Resource: * Request resource (without directory or query string) */ $resource = ''; if (!empty($_SERVER["PATH_INFO"])) { $resource = $_SERVER["PATH_INFO"]; } else { $currentUri = explode("?", $_SERVER["REQUEST_URI"], 2); $resource = substr(trim($currentUri[0], "/ "), strlen($con['directory'])); } $con['resource'] = explode('.', trim($resource, '/ ') . "/"); if ($con["resource"] == "/") { $con["resource"] = ""; } /** * Requested resource format */ if (empty($con['resource']) || count($con['resource']) == 1) { $con['resource'] = implode('.', $con['resource']); $con['format'] = Ac::config("http.default_format", "html"); } else { $con['format'] = strtolower(array_pop($con['resource'])); if (empty($con['format'])) { $con['format'] = Ac::config("http.default_format", "html"); } $con['resource'] = implode('.', $con['resource']); } /** * Query string */ $con['query_string'] = $_SERVER["QUERY_STRING"]; /** * Raw input stream (readable one time only; not available for mutipart/form-data requests) */ $rawInput = @file_get_contents('php://input'); if (!$rawInput) { $rawInput = ''; } $con['raw_input'] = $rawInput; /** * Client user agent */ $con['user_agent'] = $_SERVER["HTTP_USER_AGENT"]; /** * Client keyboard language (comma separated and lowercased) */ $con['languages'] = preg_replace("/\\;q\\=[0-9]{1,}\\.[0-9]{1,}/", "", $_SERVER["HTTP_ACCEPT_LANGUAGE"]); /** * Client IP */ $con['client_ip'] = in_array($_SERVER["REMOTE_ADDR"], array('::1', '127.0.0.1')) ? 'localhost' : $_SERVER["REMOTE_ADDR"]; /** * Is CLI ? */ $con['is_cli'] = PHP_SAPI == "cli"; /** * Is AJAX ? */ $con['is_ajax'] = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; $this->context = $con; $this->generateId(); } }
public static function setConfig($name, $value, $module = null) { if (empty($module)) { if (!empty($name)) { self::$config[$name] = $value; } else { self::$config = $value; } } else { if (!empty($name)) { self::$config["modules.config"][$module][$name] = $value; } else { self::$config["modules.config"][$module] = $value; } } }
public function config($name = null, $default = false) { return Ac::config($name, $default, $this->name); }
protected function findAction() { $controller = $this->controller; $resource = $this->params; if (!is_array($resource)) { $resource = explode("/", $resource); } if (count($resource) > 0 && !empty($resource[0])) { $action = "__handle"; $part = $resource[0]; $fn = "action_" . strtolower(ac_str_slug($part, "_")); if ($fn == "action_index" && Ac::config("router.on_index")) { $fn = Ac::config("router.on_index"); } if (method_exists($controller, $fn)) { $this->actionUrl = $this->controllerUrl . $part . "/"; $action = $fn; array_shift($this->params); } } else { $action = "__index"; } $this->action = $action; return $action; }