mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 18:23:26 +03:00
More changes
This commit is contained in:
@@ -10,7 +10,7 @@ class InputCollection implements \IteratorAggregate
|
||||
*
|
||||
* @param string $index
|
||||
* @param string|null $default
|
||||
* @return InputItem
|
||||
* @return InputItem|mixed
|
||||
*/
|
||||
public function findFirst($index, $default = null)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,9 @@ namespace Pecee\SimpleRouter;
|
||||
|
||||
abstract class LoadableRoute extends RouterEntry implements ILoadableRoute
|
||||
{
|
||||
const PARAMETERS_REGEX_MATCH = '{([A-Za-z\-\_]*?)\?{0,1}}';
|
||||
const PARAMETERS_REGEX_MATCH = '%s([\w\-\_]*?)\%s{0,1}%s';
|
||||
const PARAMETER_MODIFIERS = '{}';
|
||||
const PARAMETER_OPTIONAL_SYMBOL = '?';
|
||||
|
||||
protected $url;
|
||||
protected $alias;
|
||||
@@ -22,12 +24,11 @@ abstract class LoadableRoute extends RouterEntry implements ILoadableRoute
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = ($url === '/') ? '/' : '/' . trim($url, '/') . '/';
|
||||
$regex = sprintf(static::PARAMETERS_REGEX_MATCH, static::PARAMETER_MODIFIERS[0], static::PARAMETER_OPTIONAL_SYMBOL, static::PARAMETER_MODIFIERS[1]);
|
||||
|
||||
if (preg_match_all('/' . static::PARAMETERS_REGEX_MATCH . '/is', $this->url, $matches)) {
|
||||
if (count($matches[1]) > 0) {
|
||||
foreach ($matches[1] as $key) {
|
||||
$this->parameters[$key] = null;
|
||||
}
|
||||
if (preg_match_all('/' . $regex . '/is', $this->url, $matches)) {
|
||||
foreach ($matches[1] as $key) {
|
||||
$this->parameters[$key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ use Pecee\Http\Response;
|
||||
class RouterBase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var static
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
protected $parameterModifiers = '{}';
|
||||
protected $parameterOptionalSymbol = '?';
|
||||
|
||||
/**
|
||||
* Current request
|
||||
* @var Request
|
||||
@@ -341,8 +341,8 @@ class RouterBase
|
||||
foreach ($params as $param => $value) {
|
||||
$value = (isset($parameters[$param])) ? $parameters[$param] : $value;
|
||||
|
||||
$param1 = $this->parameterModifiers[0] . $param . $this->parameterModifiers[1];
|
||||
$param2 = $this->parameterModifiers[0] . $param . $this->parameterOptionalSymbol . $this->parameterModifiers[1];
|
||||
$param1 = LoadableRoute::PARAMETER_MODIFIERS[0] . $param . LoadableRoute::PARAMETER_MODIFIERS[1];
|
||||
$param2 = LoadableRoute::PARAMETER_MODIFIERS[0] . $param . LoadableRoute::PARAMETER_OPTIONAL_SYMBOL . LoadableRoute::PARAMETER_MODIFIERS[1];
|
||||
|
||||
if (stripos($url, $param1) !== false || stripos($url, $param) !== false) {
|
||||
$url = str_ireplace([$param1, $param2], $value, $url);
|
||||
|
||||
@@ -376,9 +376,9 @@ abstract class RouterEntry
|
||||
$output['middleware'] = $this->middlewares;
|
||||
}
|
||||
|
||||
if (count($this->where) > 0) {
|
||||
//$output['where'] = $this->where;
|
||||
}
|
||||
/*if (count($this->where) > 0) {
|
||||
$output['where'] = $this->where;
|
||||
}*/
|
||||
|
||||
if (count($this->requestMethods) > 0) {
|
||||
$output['method'] = $this->requestMethods;
|
||||
@@ -399,7 +399,7 @@ abstract class RouterEntry
|
||||
*/
|
||||
public function setData(array $settings)
|
||||
{
|
||||
if (isset($settings['namespace']) && $this->namespace === null) {
|
||||
if (isset($settings['namespace'])) {
|
||||
$this->setNamespace($settings['namespace']);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,13 +201,12 @@ class SimpleRouter
|
||||
{
|
||||
$route = new RouterRoute($url, $callback);
|
||||
$route->setRequestMethods($requestMethods);
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
if ($settings !== null) {
|
||||
$route->setData($settings);
|
||||
}
|
||||
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
static::router()->addRoute($route);
|
||||
|
||||
return $route;
|
||||
@@ -225,12 +224,12 @@ class SimpleRouter
|
||||
{
|
||||
$route = new RouterRoute($url, $callback);
|
||||
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
if ($settings !== null) {
|
||||
$route->setData($settings);
|
||||
}
|
||||
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
static::router()->addRoute($route);
|
||||
|
||||
return $route;
|
||||
@@ -248,12 +247,12 @@ class SimpleRouter
|
||||
{
|
||||
$route = new RouterController($url, $controller);
|
||||
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
if ($settings !== null) {
|
||||
$route->setData($settings);
|
||||
}
|
||||
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
static::router()->addRoute($route);
|
||||
|
||||
return $route;
|
||||
|
||||
Reference in New Issue
Block a user