protected function isPOST($fieldName = '') { if ($fieldName == '') { $fieldName = $this->fieldName; } return $this->request->isPOST(strtolower($fieldName)); }
/** * Checks if a url matches with an route. * @param string $orignalUrl * @param array $route * @return bool */ protected function urlIsMatching($orignalUrl, $route) { $routeUrl = $route['Url']; if ($routeUrl == '*' || strtolower($orignalUrl) == $routeUrl) { $request = new Request(); $request->setRoute($route); $request->setUrl($orignalUrl); return $request; } elseif (strpos($routeUrl, '{') !== false && strpos($routeUrl, '}') !== false) { // contains a variable $routeUrlParts = explode('/', $routeUrl); $orignalUrlParts = explode('/', $orignalUrl); // have the same part length if (count($routeUrlParts) == count($orignalUrlParts)) { for ($index = 0; $index < count($routeUrlParts); $index++) { if (strlen($routeUrlParts[$index]) >= 3 && $routeUrlParts[$index][0] == '{') { // it's a variable $key = substr($routeUrlParts[$index], 1, -1); if (isset($route['Parameters'][$key]) && !preg_match($route['Parameters'][$key], $orignalUrlParts[$index])) { return null; } } else { if (strtolower($routeUrlParts[$index]) != $orignalUrlParts[$index]) { // not matching return null; } } } Log::writeLine('Route matching: ' . $route['Url']); $request = new Request(); $request->setRoute($route); $request->setUrl($orignalUrl); // matching successfull // save url parameter for ($index = 0; $index < count($routeUrlParts); $index++) { if (strlen($routeUrlParts[$index]) >= 3 && $routeUrlParts[$index][0] == '{') { // it's a variable // the key is the name between the brakets $key = substr($routeUrlParts[$index], 1, -1); // add to url parameters $request->getParameters()->add($key, $orignalUrlParts[$index]); if (isset($route['Parameters'][$key])) { Log::writeLine('Url parameter: ' . $key . ' -> ' . $route['Parameters'][$key] . ' -> ' . $orignalUrlParts[$index]); } else { Log::writeLine('Url parameter: ' . $key . ' -> ' . $orignalUrlParts[$index]); } } } return $request; } } return null; }