public function readHttpData($data) { $data = Filter::key($this->getName(), $data); if (!is_null($data)) { $this->setAttribute('checked', 'checked'); } }
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())); } } } }
/** * @dataProvider skypes */ public function testSkype($skype, $ok) { $res = $ok ? $skype : false; $this->assertTrue(Filter::skype($skype) === $res); }
protected function _validate_url() { return false !== Filter::url($this->value(), false); }
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'; }
protected function check_dow($value) { $values = explode(',', $value); foreach ($values as $val) { if ($val == '*') { return true; } if (Filter::int($val, 0, 7, false) !== false and $this->time['dow'] == $val) { return true; } } return false; }