mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
Merge branch 'development' of https://github.com/skipperbent/simple-php-router into development
Conflicts: src/Pecee/SimpleRouter/RouterBase.php
This commit is contained in:
@@ -220,10 +220,10 @@ class RouterBase {
|
||||
}
|
||||
|
||||
public function arrayToParams(array $getParams = null, $includeEmpty = true) {
|
||||
if(is_array($getParams) && count($getParams) > 0) {
|
||||
foreach($getParams as $key=>$val) {
|
||||
if(!empty($val) || empty($val) && $includeEmpty) {
|
||||
$getParams[$key] = $key.'='.$val;
|
||||
if (is_array($getParams) && count($getParams) > 0) {
|
||||
foreach ($getParams as $key => $val) {
|
||||
if (!empty($val) || empty($val) && $includeEmpty) {
|
||||
$getParams[$key] = $key . '=' . $val;
|
||||
}
|
||||
}
|
||||
return join('&', $getParams);
|
||||
@@ -345,6 +345,7 @@ class RouterBase {
|
||||
|
||||
$url = '/' . trim(join('/', $url), '/') . '/';
|
||||
|
||||
|
||||
if($getParams !== null && count($getParams)) {
|
||||
$url .= '?' . $this->arrayToParams($getParams);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class RouterController extends RouterEntry {
|
||||
// Set callback
|
||||
$this->setCallback($this->controller . '@' . $this->method);
|
||||
|
||||
return $this;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -304,7 +304,7 @@ abstract class RouterEntry {
|
||||
|
||||
$max = count($parameterNames);
|
||||
|
||||
if(count($max)) {
|
||||
if($max) {
|
||||
for($i = 0; $i < $max; $i++) {
|
||||
$name = $parameterNames[$i];
|
||||
$parameterValue = (isset($parameterValues[$name['name']]) && !empty($parameterValues[$name['name']])) ? $parameterValues[$name['name']] : null;
|
||||
@@ -332,7 +332,7 @@ abstract class RouterEntry {
|
||||
throw new RouterException($middleware . ' must be instance of Middleware');
|
||||
}
|
||||
|
||||
/* @var $class Middleware */
|
||||
/* @var $class IMiddleware */
|
||||
$middleware->handle($request);
|
||||
}
|
||||
} else {
|
||||
@@ -341,7 +341,7 @@ abstract class RouterEntry {
|
||||
throw new RouterException($this->getMiddleware() . ' must be instance of Middleware');
|
||||
}
|
||||
|
||||
/* @var $class Middleware */
|
||||
/* @var $class IMiddleware */
|
||||
$middleware->handle($request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class RouterGroup extends RouterEntry {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function matchDomain() {
|
||||
protected function matchDomain(Request $request) {
|
||||
if($this->domain !== null) {
|
||||
|
||||
if(is_array($this->domain)) {
|
||||
@@ -20,7 +20,7 @@ class RouterGroup extends RouterEntry {
|
||||
for($i = 0; $i < $max; $i++) {
|
||||
$domain = $this->domain[$i];
|
||||
|
||||
$parameters = $this->parseParameters($domain, request()->getHost(), '[^.]*');
|
||||
$parameters = $this->parseParameters($domain, $request->getHost(), '[^.]*');
|
||||
|
||||
if($parameters !== null) {
|
||||
$this->parameters = $parameters;
|
||||
@@ -31,7 +31,7 @@ class RouterGroup extends RouterEntry {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parameters = $this->parseParameters($this->domain, request()->getHost(), '[^.]*');
|
||||
$parameters = $this->parseParameters($this->domain, $request->getHost(), '[^.]*');
|
||||
|
||||
if ($parameters !== null) {
|
||||
$this->parameters = $parameters;
|
||||
@@ -60,7 +60,7 @@ class RouterGroup extends RouterEntry {
|
||||
throw new RouterException('Method not allowed');
|
||||
}
|
||||
|
||||
if($this->matchDomain() === null) {
|
||||
if($this->matchDomain($request) === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class RouterResource extends RouterEntry {
|
||||
protected function call($method, $parameters) {
|
||||
$this->setCallback($this->controller . '@' . $method);
|
||||
$this->parameters = $parameters;
|
||||
return $this;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function matchRoute(Request $request) {
|
||||
|
||||
@@ -26,9 +26,9 @@ class RouterRoute extends RouterEntry {
|
||||
// Match on custom defined regular expression
|
||||
if($this->regexMatch) {
|
||||
$parameters = array();
|
||||
if(preg_match('/('.$this->regexMatch.')/is', request()->getHost() . $url, $parameters)) {
|
||||
if(preg_match('/('.$this->regexMatch.')/is', $request->getHost() . $url, $parameters)) {
|
||||
$this->parameters = (!is_array($parameters[0]) ? array($parameters[0]) : $parameters[0]);
|
||||
return $this;
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class RouterRoute extends RouterEntry {
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
return $this;
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -19,7 +19,7 @@ class SimpleRouter {
|
||||
* @throws RouterException
|
||||
*/
|
||||
public static function start($defaultNamespace = null) {
|
||||
$router = RouterBase::GetInstance();
|
||||
$router = RouterBase::getInstance();
|
||||
$router->setDefaultNamespace($defaultNamespace);
|
||||
$router->routeRequest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user