public function readHttpData($data) { $data = Filter::key($this->getName(), $data); if (!is_null($data)) { $this->setAttribute('checked', 'checked'); } }
/** * Sets/gets label's attribute */ public function labelAttribute($name, $value = null) { if (is_null($value)) { return Filter::key($name, $this->labelAttributes); } $this->labelAttributes[$name] = $value; return $this; }
protected static function init() { if (is_null(static::$routes)) { static::$routes = new Container(); if ($config = Config::get("routes")) { foreach ($config as $key => $route) { static::add($key, $route["path"], Filter::key("defaults", $route, array()), Filter::key("requisites", $route, array())); } } } }
public function readHttpData($data) { $this->setValue(Filter::key($this->getName(), $data)); }
/** * Create regular expression for the host or for the path * * @param string $pattern * @param string $style - "host" or "path" * @return string */ protected function compile($pattern, $style) { $regex = $pattern; // $regex = preg_replace('#[.\\+?[^\\]$()<>=!]#', '\\\\$0', $regex); if ($style === "host") { $delimiter = "."; $defaultRequisites = "[^.,;?<>]+"; } elseif ($style === "path") { $delimiter = "/"; $defaultRequisites = "[^/,;?<>]+"; } else { throw new \Exception("Unknown style {$style}"); } preg_match_all("#\\{(\\w+)\\}#", $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); foreach ($matches as $match) { $variable = $match[1][0]; $varPattern = $match[0][0]; // {variable} $varPos = $match[0][1]; $capture = Filter::key($variable, $this->requisites, $defaultRequisites); $nextChar = isset($pattern[$varPos + strlen($varPattern)]) ? $pattern[$varPos + strlen($varPattern)] : ""; $prevChar = $varPos > 0 ? $pattern[$varPos - 1] : ""; if ($this->hasDefault($variable)) { // Make variables that have default values optional // Also make delimiter (if next char is a delimiter) to be also optional if ($style == "host" and $nextChar == $delimiter and ($prevChar == "" or $prevChar == $delimiter)) { $regex = preg_replace("#" . $varPattern . $delimiter . "#", "((?P<" . $variable . ">" . $capture . ")" . $delimiter . ")?", $regex); } elseif ($style == "path" and ($prevChar == $delimiter and $nextChar == $delimiter or $prevChar == $delimiter and $nextChar == "" and $varPos > 1)) { $regex = preg_replace("#" . $delimiter . $varPattern . "#", "(" . $delimiter . "(?P<" . $variable . ">" . $capture . "))?", $regex); } else { $regex = preg_replace("#" . $varPattern . "#", "((?P<" . $variable . ">" . $capture . "))?", $regex); } } else { $regex = preg_replace("#" . $varPattern . "#", "(?P<" . $variable . ">" . $capture . ")", $regex); } $this->variables[$variable] = $this->getDefault($variable); } if ($style == "host") { $regex = str_replace(".", "\\.", $regex); } else { $regex = "/?" . $regex; } return "#^" . $regex . '$#siuD'; }