/** * Gets a request attribute. * * @param string $name HttpRequest attribute. * @param string $default Default value (not required) * * @return mixed */ public function get($name, $default = "") { $param = Arr::get($_REQUEST, $name, $default); if ($_SERVER["REQUEST_METHOD"] == "GET" && is_string($param)) { $param = urldecode($param); } return $param; }
/** * Is the next thing a speudo filter? * * @return false|CssParserFilterPseudo */ protected function pseudoFilter() { if (!$this->match("/^\\:/")) { return false; } if (!(list($name) = $this->is("identifier"))) { throw new TextParserException("Invalid identifier", $this); } $filter = Arr::get($this->_pseudoFilters, $name, null); if ($filter === null) { throw new TextParserException("Unknown pseudo-filter", $this); } $input = ""; if ($this->eq("(")) { if (!($input = $this->is($filter["entity"]))) { throw new TextParserException("Invalid input", $this); } if (is_array($input)) { $input = $input[0]; } if (!$this->eq(")")) { throw new TextParserException("Invalid expression", $this); } } $pseudoFilter = CssParserFilterPseudoFactory::getInstance($filter["classname"], $input, $filter["user_def_function"]); return $pseudoFilter; }
/** * Gets a cookie. * * @param string $name Cookie name * * @return mixed */ public function getCookie($name) { return Arr::get($_COOKIE, $name); }
/** * Constructor. * * Example: * ```PHP * $uri = new Uri("http://*****:*****@host:8080/path/to/url?aaa=1&bbb=2#tagname"); * echo $uri->getScheme() . "\n"; * echo $uri->getHost() . "\n"; * echo $uri->getPort() . "\n"; * echo $uri->getUsername() . "\n"; * echo $uri->getPassword() . "\n"; * echo $uri->getPath() . "\n"; * echo $uri->getQuery() . "\n"; * echo $uri->getFragment() . "\n"; * ``` * * @param string $uri URI */ public function __construct($uri) { $this->_uri = $uri; // parses the uri $urlInfo = parse_url($uri); if ($urlInfo === false) { throw new UriException("The given URI is not well formed"); } // gets the uri info $this->_scheme = Arr::get($urlInfo, "scheme"); $this->_host = Arr::get($urlInfo, "host"); $this->_port = Arr::get($urlInfo, "port"); $this->_username = Arr::get($urlInfo, "user"); $this->_password = Arr::get($urlInfo, "pass"); $this->_path = Arr::get($urlInfo, "path"); $this->_query = Arr::get($urlInfo, "query"); $this->_fragment = Arr::get($urlInfo, "fragment"); }
/** * Fetches elements from an array. * * This function is especially suitable for getting optional arguments. * * For example: * ```php * function test($title, $message, $x, $y, $options) { * $args = Arr::fetch(func_get_args(), array( * // `title` is a required string * "title" => "string", * // `message` is an optional string and has a default value * "message" => array( * "type" => "string", * "default" => "Default message ..." * ), * // `x` is an optional string or number and has a default value * "x" => array( * "type" => "string|number", * "default" => 0 * ), * // `y` is an optional string or number and has a default value * "y" => array( * "type" => "string|number", * "default" => 0 * ), * // `options` is an optional array * "options" => array( * "type" => "array", * required => false * ) * ); * print_r($args); * } * // this throws an InvalidArgumentException, as 'title' is required. * test(120, 250); * ``` * * @param array $arr Array of mixed elements * @param array $descriptors Associative array of descriptors. * * @throws InvalidArgumentException * @return array */ public static function fetch($arr, $descriptors) { $args = new ArrArguments($arr); foreach ($descriptors as $name => $descriptor) { $types = array(); $default = null; $required = false; if (is_string($descriptor)) { $types = explode("|", $descriptor); } elseif (is_array($descriptor)) { $types = explode("|", Arr::get($descriptor, "type")); $default = Arr::get($descriptor, "default"); $required = Arr::get($descriptor, "required", !Arr::exist($descriptor, "default")); } $desc = new ArrArgumentsDescriptor($types, $default, $required); $args->registerDescriptor($name, $desc); } return $args->fetch(); }
/** * Gets a 'form parameter'. * * This function returns `null` if the parameter does not exist. * * @param string $name Parameter name * * @return HttpRequestFormData */ public function getFormParam($name) { return Arr::get($this->formParams, $name); }
/** * Gets HTTP option. * * @param string $name Option name * * @return string */ public function getOption($name) { return Arr::get($this->_options, $name); }
/** * Gets a request attribute. * * @param string $name Request attribute. * @param string $default Default value (not required) * * @return mixed */ public function get($name, $default = "") { return Arr::get($_COOKIE, $name, $default); }
/** * Gets a session attribute. * * @param string $name Attribute name * * @return mixed */ public function getSession($name) { $this->_startSession(); return Arr::get($_SESSION, $name); }
/** * Gets a request attribute. * * @param string $name Request attribute. * @param string $default Default value (not required) * * @return mixed */ public function get($name, $default = "") { HttpSession::start(); return Arr::get($_SESSION, $name, $default); }
/** * Gets the upload error message. * * When an error has occurred, this function returns the error message. * * @return string */ public function getErrorMessage() { $errno = $this->getErrorNumber(); return Arr::get($this->_errors, $errno, "Unknown error"); }
/** * Constructor. * * For more information about parameters see: * http://php.net/manual/en/function.htmlspecialchars.php * * Parameters: * ```text * $options["flags"] : Flags(not required, default is ENT_COMPAT | ENT_HTML401) * $options["encoding"]: Encoding (not required, default is ini_get("default_charset")) * $options["double_encode"]: Double encode (not required, default is true) * ``` * * Examples: * ```php * // the most simple way * $xml = new XmlEncoder(); * echo $xml->encode("Rick & Morty"); * * // more elaborated way * $xml = new XmlEncoder([ * "flags" => ENT_QUOTES|ENT_XML1, * "encoding" => "ISO-8859-1", * "double_encode" => false * ]); * echo $xml->encode("Rick & Morty"); * ``` * * @param array $options Options */ public function __construct($options = []) { $this->_flags = Arr::get($options, "flags", ENT_COMPAT | ENT_HTML401); $this->_encoding = Arr::get($options, "encoding", ini_get("default_charset")); $this->_doubleEncode = Arr::get($options, "double_encode", true); }