2017-01-10 22:37:29 +00:00
|
|
|
<?php
|
2019-10-03 19:24:12 +00:00
|
|
|
|
2017-01-10 22:37:29 +00:00
|
|
|
/**
|
|
|
|
* UglyRouter class.
|
|
|
|
*/
|
2017-01-10 22:39:58 +00:00
|
|
|
|
2017-01-10 22:37:29 +00:00
|
|
|
namespace Alltube;
|
|
|
|
|
2018-02-05 15:48:58 +00:00
|
|
|
use InvalidArgumentException;
|
2017-01-10 22:37:29 +00:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
2018-02-05 15:48:58 +00:00
|
|
|
use RuntimeException;
|
2017-01-10 22:39:58 +00:00
|
|
|
use Slim\Router;
|
2017-01-10 22:37:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend Slim's router class in order to disable URL rewriting.
|
|
|
|
*/
|
|
|
|
class UglyRouter extends Router
|
|
|
|
{
|
|
|
|
/**
|
2017-01-10 22:39:58 +00:00
|
|
|
* Dispatch router for HTTP request.
|
2017-01-10 22:37:29 +00:00
|
|
|
*
|
2017-01-10 22:39:58 +00:00
|
|
|
* @param ServerRequestInterface $request The current HTTP request object
|
2017-01-10 22:37:29 +00:00
|
|
|
*
|
2020-05-13 20:28:05 +00:00
|
|
|
* @return mixed[]
|
2017-01-10 22:37:29 +00:00
|
|
|
*
|
|
|
|
* @link https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
|
|
|
|
*/
|
|
|
|
public function dispatch(ServerRequestInterface $request)
|
|
|
|
{
|
|
|
|
parse_str($request->getUri()->getQuery(), $args);
|
|
|
|
$uri = '/';
|
|
|
|
if (isset($args['page'])) {
|
|
|
|
$uri .= $args['page'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->createDispatcher()->dispatch(
|
|
|
|
$request->getMethod(),
|
|
|
|
$uri
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-10 22:39:58 +00:00
|
|
|
* Build the path for a named route including the base path.
|
2017-01-10 22:37:29 +00:00
|
|
|
*
|
2020-05-13 20:28:05 +00:00
|
|
|
* @param string $name Route name
|
|
|
|
* @param string[] $data Named argument replacement data
|
|
|
|
* @param string[] $queryParams Optional query string parameters
|
2017-01-10 22:37:29 +00:00
|
|
|
*
|
2020-05-13 20:28:05 +00:00
|
|
|
* @return string
|
2018-02-05 15:48:58 +00:00
|
|
|
* @throws InvalidArgumentException If required data not provided
|
2020-05-13 20:28:05 +00:00
|
|
|
* @throws RuntimeException If named route does not exist
|
2017-01-10 22:37:29 +00:00
|
|
|
*/
|
|
|
|
public function pathFor($name, array $data = [], array $queryParams = [])
|
|
|
|
{
|
|
|
|
$url = str_replace('/', '/?page=', $this->relativePathFor($name, $data, $queryParams));
|
|
|
|
|
|
|
|
if ($this->basePath) {
|
2019-10-03 19:24:12 +00:00
|
|
|
$url = $this->basePath . $url;
|
2017-01-10 22:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
}
|