mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
+6
-1
@@ -9,7 +9,12 @@
|
||||
"simple-php-router",
|
||||
"laravel",
|
||||
"pecee",
|
||||
"php"
|
||||
"php",
|
||||
"framework",
|
||||
"url-handling",
|
||||
"input-handler",
|
||||
"routing-engine",
|
||||
"request-handler"
|
||||
],
|
||||
"license": "MIT",
|
||||
"support": {
|
||||
|
||||
@@ -18,6 +18,7 @@ use Pecee\SimpleRouter\SimpleRouter as Router;
|
||||
* @param string|array|null $parameters
|
||||
* @param array|null $getParams
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
function url($name = null, $parameters = null, $getParams = null)
|
||||
{
|
||||
|
||||
@@ -28,15 +28,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
*/
|
||||
public function loadMiddleware(Request $request)
|
||||
{
|
||||
$max = count($this->getMiddlewares());
|
||||
|
||||
if ($max === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $max; $i++) {
|
||||
|
||||
$middleware = $this->getMiddlewares()[$i];
|
||||
foreach ($this->getMiddlewares() as $middleware) {
|
||||
|
||||
if (is_object($middleware) === false) {
|
||||
$middleware = $this->loadClass($middleware);
|
||||
|
||||
@@ -543,7 +543,7 @@ abstract class Route implements IRoute
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array
|
||||
* @return array
|
||||
*/
|
||||
public function getMiddlewares()
|
||||
{
|
||||
|
||||
@@ -16,12 +16,6 @@ use Pecee\SimpleRouter\Route\IRoute;
|
||||
class Router
|
||||
{
|
||||
|
||||
/**
|
||||
* The instance of this class
|
||||
* @var static
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Current request
|
||||
* @var Request
|
||||
@@ -119,15 +113,12 @@ class Router
|
||||
protected function processRoutes(array $routes, IGroupRoute $group = null, IRoute $parent = null)
|
||||
{
|
||||
// Loop through each route-request
|
||||
$max = count($routes) - 1;
|
||||
|
||||
$exceptionHandlers = [];
|
||||
|
||||
$url = ($this->request->getRewriteUrl() !== null) ? $this->request->getRewriteUrl() : $this->request->getUri()->getPath();
|
||||
|
||||
for ($i = $max; $i >= 0; $i--) {
|
||||
|
||||
$route = $routes[$i];
|
||||
foreach ($routes as $route) {
|
||||
|
||||
if ($parent !== null) {
|
||||
|
||||
@@ -202,15 +193,9 @@ class Router
|
||||
public function loadRoutes()
|
||||
{
|
||||
/* Initialize boot-managers */
|
||||
if (count($this->bootManagers) !== 0) {
|
||||
|
||||
$max = count($this->bootManagers) - 1;
|
||||
|
||||
/* @var $manager IRouterBootManager */
|
||||
for ($i = $max; $i >= 0; $i--) {
|
||||
$manager = $this->bootManagers[$i];
|
||||
$manager->boot($this->request);
|
||||
}
|
||||
/* @var $manager IRouterBootManager */
|
||||
foreach ($this->bootManagers as $manager) {
|
||||
$manager->boot($this->request);
|
||||
}
|
||||
|
||||
/* Loop through each route-request */
|
||||
@@ -243,12 +228,9 @@ class Router
|
||||
|
||||
$url = ($this->request->getRewriteUrl() !== null) ? $this->request->getRewriteUrl() : $this->request->getUri()->getPath();
|
||||
|
||||
$max = count($this->processedRoutes) - 1;
|
||||
|
||||
/* @var $route ILoadableRoute */
|
||||
for ($i = $max; $i >= 0; $i--) {
|
||||
foreach ($this->processedRoutes as $key => $route) {
|
||||
|
||||
$route = $this->processedRoutes[$i];
|
||||
|
||||
/* If the route matches */
|
||||
if ($route->matchRoute($url, $this->request) === true) {
|
||||
@@ -273,7 +255,7 @@ class Router
|
||||
$rewriteUrl = $this->request->getRewriteUrl();
|
||||
|
||||
if ($rewriteUrl !== null && $rewriteUrl !== $url) {
|
||||
unset($this->processedRoutes[$i]);
|
||||
unset($this->processedRoutes[$key]);
|
||||
$this->processedRoutes = array_values($this->processedRoutes);
|
||||
|
||||
return $this->routeRequest(true);
|
||||
@@ -388,12 +370,8 @@ class Router
|
||||
*/
|
||||
public function findRoute($name)
|
||||
{
|
||||
$max = count($this->processedRoutes) - 1;
|
||||
|
||||
/* @var $route ILoadableRoute */
|
||||
for ($i = $max; $i >= 0; $i--) {
|
||||
|
||||
$route = $this->processedRoutes[$i];
|
||||
foreach ($this->processedRoutes as $route) {
|
||||
|
||||
/* Check if the name matches with a name on the route. Should match either router alias or controller alias. */
|
||||
if ($route->hasName($name)) {
|
||||
@@ -492,12 +470,8 @@ class Router
|
||||
|
||||
/* Loop through all the routes to see if we can find a match */
|
||||
|
||||
$max = count($this->processedRoutes) - 1;
|
||||
|
||||
/* @var $route ILoadableRoute */
|
||||
for ($i = $max; $i >= 0; $i--) {
|
||||
|
||||
$route = $this->processedRoutes[$i];
|
||||
foreach ($this->processedRoutes as $route) {
|
||||
|
||||
/* Check if the route contains the name/alias */
|
||||
if ($route->hasName($controller) === true) {
|
||||
|
||||
@@ -367,7 +367,7 @@ class SimpleRouter
|
||||
* @param string|null $name
|
||||
* @param string|array|null $parameters
|
||||
* @param array|null $getParams
|
||||
* @throws \Exception
|
||||
* @throws \InvalidArgumentException
|
||||
* @return string
|
||||
*/
|
||||
public static function getUrl($name = null, $parameters = null, $getParams = null)
|
||||
|
||||
Reference in New Issue
Block a user