mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
[TASK] Updated
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user