mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
Merge pull request #58 from skipperbent/development
[BUGFIX] Custom parameters regex is now working again.
This commit is contained in:
@@ -27,7 +27,7 @@ abstract class RouterEntry {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->settings = array();
|
$this->settings = array();
|
||||||
$this->settings['requestMethods'] = array();
|
$this->settings['requestMethods'] = array();
|
||||||
$this->settings['parametersRegex'] = array();
|
$this->settings['where'] = array();
|
||||||
$this->settings['parameters'] = array();
|
$this->settings['parameters'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ abstract class RouterEntry {
|
|||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function where(array $options) {
|
public function where(array $options) {
|
||||||
$this->parametersRegex = array_merge($this->parametersRegex, $options);
|
$this->where = array_merge($this->where, $options);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,11 +249,6 @@ abstract class RouterEntry {
|
|||||||
$isParameter = false;
|
$isParameter = false;
|
||||||
$parameter = '';
|
$parameter = '';
|
||||||
|
|
||||||
// Use custom parameter regex if it exists
|
|
||||||
if(is_array($this->parametersRegex) && isset($this->parametersRegex[$parameter])) {
|
|
||||||
$parameterRegex = $this->parametersRegex[$parameter];
|
|
||||||
}
|
|
||||||
|
|
||||||
$routeLength = strlen($route);
|
$routeLength = strlen($route);
|
||||||
for($i = 0; $i < $routeLength; $i++) {
|
for($i = 0; $i < $routeLength; $i++) {
|
||||||
|
|
||||||
@@ -275,6 +270,12 @@ abstract class RouterEntry {
|
|||||||
} elseif($isParameter && $character === '}') {
|
} elseif($isParameter && $character === '}') {
|
||||||
$required = true;
|
$required = true;
|
||||||
// Check for optional parameter
|
// Check for optional parameter
|
||||||
|
|
||||||
|
// Use custom parameter regex if it exists
|
||||||
|
if(is_array($this->where) && isset($this->where[$parameter])) {
|
||||||
|
$parameterRegex = $this->where[$parameter];
|
||||||
|
}
|
||||||
|
|
||||||
if($lastCharacter === '?') {
|
if($lastCharacter === '?') {
|
||||||
$parameter = substr($parameter, 0, strlen($parameter)-1);
|
$parameter = substr($parameter, 0, strlen($parameter)-1);
|
||||||
$regex .= '(?:(?:\/{0,1}(?P<'.$parameter.'>[^\/]*)))\\/{0,1}';
|
$regex .= '(?:(?:\/{0,1}(?P<'.$parameter.'>[^\/]*)))\\/{0,1}';
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class RouterResource extends RouterEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show
|
// Show
|
||||||
if($action && $this->postMethod === self::REQUEST_TYPE_GET) {
|
if(isset($parameters['id']) && $this->postMethod === self::REQUEST_TYPE_GET) {
|
||||||
return $this->call('show', $parameters);
|
return $this->call('show', $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user