[TASK] Updated

This commit is contained in:
Simon Sessingø
2015-09-21 19:40:14 +02:00
parent 266ebdf7d7
commit 85470bbbd7
5 changed files with 184 additions and 73 deletions
+35 -2
View File
@@ -11,12 +11,36 @@ class RouterRoute extends RouterEntry {
public function __construct($url, $callback) {
parent::__construct();
$this->url = $url;
$this->callback = $callback;
$this->setUrl($url);
$this->setCallback($callback);
$this->settings['aliases'] = array();
}
protected function parseParameters($url) {
$parameters = array();
preg_match_all('/{([A-Za-z\-\_]*?)}/is', $url, $parameters);
if(isset($parameters[1]) && count($parameters[1]) > 0) {
return $parameters[1];
}
return null;
}
protected function parseParameter($path) {
$parameters = array();
preg_match('/{([A-Za-z\-\_]*?)}/is', $path, $parameters);
if(isset($parameters[1]) && count($parameters[1]) > 0) {
return $parameters[1];
}
return null;
}
public function getRoute($requestMethod, &$url) {
// Check if request method is allowed
@@ -73,6 +97,15 @@ class RouterRoute extends RouterEntry {
* @return self
*/
public function setUrl($url) {
$parameters = $this->parseParameters($url);
if($parameters !== null) {
foreach($parameters as $param) {
$this->parameters[$param] = '';
}
}
$this->url = $url;
return $this;
}