mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
More optimisations
This commit is contained in:
@@ -8,7 +8,7 @@ abstract class LoadableRoute extends RouterEntry implements ILoadableRoute
|
||||
const PARAMETER_OPTIONAL_SYMBOL = '?';
|
||||
|
||||
protected $url;
|
||||
protected $names = array();
|
||||
protected $names = [];
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
@@ -60,7 +60,8 @@ abstract class LoadableRoute extends RouterEntry implements ILoadableRoute
|
||||
* Get route names
|
||||
* @return array
|
||||
*/
|
||||
public function getNames() {
|
||||
public function getNames()
|
||||
{
|
||||
return $this->names;
|
||||
}
|
||||
|
||||
@@ -109,6 +110,7 @@ abstract class LoadableRoute extends RouterEntry implements ILoadableRoute
|
||||
public function setName($name)
|
||||
{
|
||||
array_push($this->names, $name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -118,8 +120,10 @@ abstract class LoadableRoute extends RouterEntry implements ILoadableRoute
|
||||
* @param array $names
|
||||
* @return static $this
|
||||
*/
|
||||
public function setNames(array $names) {
|
||||
public function setNames(array $names)
|
||||
{
|
||||
$this->names = $names;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ class RouterBase
|
||||
}
|
||||
}
|
||||
|
||||
if($group !== null) {
|
||||
if ($group !== null) {
|
||||
|
||||
/* Add the parent group */
|
||||
$route->setGroup($group);
|
||||
@@ -437,7 +437,7 @@ class RouterBase
|
||||
throw new \InvalidArgumentException('Invalid type for getParams. Must be array or null');
|
||||
}
|
||||
|
||||
if($getParams === null) {
|
||||
if ($getParams === null) {
|
||||
$getParams = $_GET;
|
||||
}
|
||||
|
||||
@@ -481,6 +481,7 @@ class RouterBase
|
||||
}
|
||||
|
||||
/* No result so we assume that someone is using a hardcoded url and join everything together. */
|
||||
|
||||
return '/' . trim(join('/', array_merge((array)$name, (array)$parameters)), '/') . '/' . $this->arrayToParams($getParams);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class RouterController extends LoadableRoute implements IControllerRoute
|
||||
throw new NotFoundHttpException(sprintf('Method %s does not exist in class %s', $method, $className), 404);
|
||||
}
|
||||
|
||||
call_user_func_array(array($class, $method), $this->getParameters());
|
||||
call_user_func_array([$class, $method], $this->getParameters());
|
||||
|
||||
return $class;
|
||||
}
|
||||
@@ -86,6 +86,7 @@ class RouterController extends LoadableRoute implements IControllerRoute
|
||||
public function setController($controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -104,6 +105,7 @@ class RouterController extends LoadableRoute implements IControllerRoute
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,6 +197,7 @@ abstract class RouterEntry
|
||||
public function setRequestMethods(array $methods)
|
||||
{
|
||||
$this->requestMethods = $methods;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -246,6 +247,7 @@ abstract class RouterEntry
|
||||
public function setParent(RouterEntry $parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -256,6 +258,7 @@ abstract class RouterEntry
|
||||
public function setCallback($callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -292,12 +295,14 @@ abstract class RouterEntry
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->callback = sprintf('%s@%s', $this->getClass(), $method);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->callback = sprintf('%s@%s', $class, $this->getMethod());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -308,12 +313,14 @@ abstract class RouterEntry
|
||||
public function setMiddleware($middleware)
|
||||
{
|
||||
$this->middlewares[] = $middleware;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMiddlewares(array $middlewares)
|
||||
{
|
||||
$this->middlewares = $middlewares;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -324,6 +331,7 @@ abstract class RouterEntry
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -334,6 +342,7 @@ abstract class RouterEntry
|
||||
public function setDefaultNamespace($namespace)
|
||||
{
|
||||
$this->defaultNamespace = $namespace;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -373,6 +382,7 @@ abstract class RouterEntry
|
||||
public function setParameters($parameters)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -385,6 +395,7 @@ abstract class RouterEntry
|
||||
public function setWhere(array $options)
|
||||
{
|
||||
$this->where = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -397,6 +408,7 @@ abstract class RouterEntry
|
||||
public function setMatch($regex)
|
||||
{
|
||||
$this->regex = $regex;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ use Pecee\Http\Request;
|
||||
class RouterGroup extends RouterEntry
|
||||
{
|
||||
protected $prefix;
|
||||
protected $domains = array();
|
||||
protected $exceptionHandlers = array();
|
||||
protected $domains = [];
|
||||
protected $exceptionHandlers = [];
|
||||
|
||||
public function matchDomain(Request $request)
|
||||
{
|
||||
@@ -18,6 +18,7 @@ class RouterGroup extends RouterEntry
|
||||
|
||||
if ($parameters !== null) {
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -41,6 +42,7 @@ class RouterGroup extends RouterEntry
|
||||
public function setExceptionHandlers(array $handlers)
|
||||
{
|
||||
$this->exceptionHandlers = $handlers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -57,6 +59,7 @@ class RouterGroup extends RouterEntry
|
||||
public function setDomains(array $domains)
|
||||
{
|
||||
$this->domains = $domains;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -67,6 +70,7 @@ class RouterGroup extends RouterEntry
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefix = '/' . trim($prefix, '/');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -110,7 +114,7 @@ class RouterGroup extends RouterEntry
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
if ($this->prefix !== null) {
|
||||
$values['prefix'] = $this->getPrefix();
|
||||
|
||||
@@ -18,11 +18,13 @@ class RouterRoute extends LoadableRoute
|
||||
|
||||
// Match on custom defined regular expression
|
||||
if ($this->regex !== null) {
|
||||
$parameters = array();
|
||||
$parameters = [];
|
||||
if (preg_match('/(' . $this->regex . ')/is', $request->getHost() . $url, $parameters)) {
|
||||
$this->parameters = (array)$parameters[0];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -33,6 +35,7 @@ class RouterRoute extends LoadableRoute
|
||||
|
||||
if ($parameters !== null) {
|
||||
$this->parameters = array_merge($this->parameters, $parameters);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user