public static function write($name, $value, $expires = null) { $self = self::getInstance(); $expires = $self->expire($expires); $path = Mapper::normalize(Mapper::base() . $self->path); return setcookie($self->name . '[' . $name . ']', self::encrypt($value), $expires, $path, $self->domain, $self->secure); }
/** * Faz a interpretação da URL, identificando as partes da URL. * * @param string $url URL a ser interpretada * @return array URL interpretada */ public function parseUrl($url = null) { $here = Mapper::normalize(is_null($url) ? Mapper::here() : $url); $url = Mapper::getRoute($here); $prefixes = join("|", Mapper::getPrefixes()); $parts = array("here", "prefix", "controller", "action", "id", "extension", "params"); preg_match("/^\\/(?:({$prefixes})(?:\\/|(?!\\w)))?(?:([a-z_-]*)\\/?)?(?:([a-z_-]*)\\/?)?(?:(\\d*))?(?:\\.([\\w]+))?(?:\\/?(.*))?/i", $url, $reg); foreach ($parts as $k => $key) { $this->path[$key] = $reg[$k]; } $this->path["namedParams"] = $this->path["params"] = array(); foreach (split("/", $reg[6]) as $param) { if (preg_match("/([^:]*):([^:]*)/", $param, $reg)) { $this->path["namedParams"][$reg[1]] = urldecode($reg[2]); } elseif ($param != "") { $this->path["params"][] = urldecode($param); } } $this->path["here"] = $here; if (empty($this->path["controller"])) { $this->path["controller"] = Mapper::getRoot(); } if (empty($this->path["action"])) { $this->path["action"] = "index"; } if (!empty($this->path["prefix"])) { $this->path["action"] = "{$this->path['prefix']}_{$this->path['action']}"; } if (empty($this->path["id"])) { $this->path["id"] = null; } if (empty($this->path["extension"])) { $this->path["extension"] = Config::read("defaultExtension"); } return $this->path; }
public function testNormalizeMailto() { $results = Mapper::normalize("mailto:spaghetti@spaghettiphp.org"); $expected = "mailto:spaghetti@spaghettiphp.org"; $this->assertEqual($expected, $results); }