This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* UglyRouter class. | ||
*/ | ||
|
||
namespace Alltube; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use Slim\Router; | ||
|
||
/** | ||
* Extend Slim's router class in order to disable URL rewriting. | ||
*/ | ||
class UglyRouter extends Router | ||
{ | ||
/** | ||
* Dispatch router for HTTP request. | ||
* | ||
* @param ServerRequestInterface $request The current HTTP request object | ||
* | ||
* @return array | ||
* | ||
* @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 | ||
); | ||
} | ||
|
||
/** | ||
* Build the path for a named route including the base path. | ||
* | ||
* @param string $name Route name | ||
* @param array $data Named argument replacement data | ||
* @param array $queryParams Optional query string parameters | ||
* | ||
* @throws \RuntimeException If named route does not exist | ||
* @throws \InvalidArgumentException If required data not provided | ||
* | ||
* @return string | ||
*/ | ||
public function pathFor($name, array $data = [], array $queryParams = []) | ||
{ | ||
$url = str_replace('/', '/?page=', $this->relativePathFor($name, $data, $queryParams)); | ||
|
||
if ($this->basePath) { | ||
$url = $this->basePath.$url; | ||
} | ||
|
||
return $url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ convert: false | |
avconv: vendor/bin/ffmpeg | ||
rtmpdump: vendor/bin/rtmpdump | ||
curl: /usr/bin/curl | ||
uglyUrls: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* UglyRouterTest class. | ||
*/ | ||
|
||
namespace Alltube\Test; | ||
|
||
use Alltube\UglyRouter; | ||
use Slim\Http\Environment; | ||
use Slim\Http\Headers; | ||
use Slim\Http\Request; | ||
use Slim\Http\Stream; | ||
use Slim\Http\Uri; | ||
|
||
/** | ||
* Unit tests for the UglyRouter class. | ||
*/ | ||
class UglyRouterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* UglyRouter instance. | ||
* | ||
* @var UglyRouter | ||
*/ | ||
private $router; | ||
|
||
/** | ||
* Prepare tests. | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->router = new UglyRouter(); | ||
$this->router->map(['GET'], '/foo', 'print')->setName('foo'); | ||
} | ||
|
||
/** | ||
* Test the dispatch() function. | ||
* | ||
* @return void | ||
*/ | ||
public function testDispatch() | ||
{ | ||
$this->assertEquals( | ||
[1, 'route0', []], | ||
$this->router->dispatch( | ||
new Request( | ||
'GET', | ||
Uri::createFromString('http://example.com/?page=foo'), | ||
Headers::createFromEnvironment(new Environment()), | ||
[], | ||
[], | ||
new Stream(fopen('php://temp', 'r')) | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Test the pathFor() function. | ||
* | ||
* @return void | ||
*/ | ||
public function testPathFor() | ||
{ | ||
$this->assertEquals( | ||
'/?page=foo', | ||
$this->router->pathFor('foo', [], []) | ||
); | ||
} | ||
|
||
/** | ||
* Test the pathFor() function with a base path. | ||
* | ||
* @return void | ||
*/ | ||
public function testPathForWithBasePath() | ||
{ | ||
$this->router->setBasePath('/bar'); | ||
$this->assertEquals( | ||
'/bar/?page=foo', | ||
$this->router->pathFor('foo', [], []) | ||
); | ||
} | ||
} |