Merge pull request #142 from acelaya/develop

Develop
This commit is contained in:
Alejandro Celaya 2018-04-07 09:05:56 +02:00 committed by GitHub
commit e504daa1ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 36 deletions

View file

@ -2,6 +2,16 @@
### 1.8.1 ### 1.8.1
**Tasks**
* [141: Remove workaround used in PathVersionMiddleware](https://github.com/shlinkio/shlink/issues/141)
**Bugs:**
* [140: Installation failed. Warning thrown while trying to include doctrine script](https://github.com/shlinkio/shlink/issues/140)
### 1.8.0
**Features** **Features**
* [125: Implement a path which returns a 1px image instead of a redirection](https://github.com/shlinkio/shlink/issues/125) * [125: Implement a path which returns a 1px image instead of a redirection](https://github.com/shlinkio/shlink/issues/125)

View file

@ -21,7 +21,7 @@ return [
'priority' => 11, 'priority' => 11,
], ],
'pre-routing-rest' => [ 'pre-routing-rest' => [
// 'path' => '/rest', 'path' => '/rest',
'middleware' => [ 'middleware' => [
PathVersionMiddleware::class, PathVersionMiddleware::class,
], ],

0
data/infra/database/.gitignore vendored Normal file → Executable file
View file

0
data/infra/nginx/.gitignore vendored Normal file → Executable file
View file

View file

@ -134,7 +134,7 @@ class InstallCommand extends Command
if (! $this->isUpdate) { if (! $this->isUpdate) {
$this->io->write('Initializing database...'); $this->io->write('Initializing database...');
if (! $this->runCommand( if (! $this->runCommand(
'php vendor/bin/doctrine orm:schema-tool:create', 'php vendor/doctrine/orm/bin/doctrine.php orm:schema-tool:create',
'Error generating database.', 'Error generating database.',
$output $output
)) { )) {
@ -145,7 +145,7 @@ class InstallCommand extends Command
// Run database migrations // Run database migrations
$this->io->write('Updating database...'); $this->io->write('Updating database...');
if (! $this->runCommand( if (! $this->runCommand(
'php vendor/bin/doctrine-migrations migrations:migrate', 'php vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate',
'Error updating database.', 'Error updating database.',
$output $output
)) { )) {
@ -155,7 +155,7 @@ class InstallCommand extends Command
// Generate proxies // Generate proxies
$this->io->write('Generating proxies...'); $this->io->write('Generating proxies...');
if (! $this->runCommand( if (! $this->runCommand(
'php vendor/bin/doctrine orm:generate-proxies', 'php vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies',
'Error generating proxies.', 'Error generating proxies.',
$output $output
)) { )) {

View file

@ -18,27 +18,16 @@ class PathVersionMiddleware implements MiddlewareInterface
* @param RequestHandlerInterface $handler * @param RequestHandlerInterface $handler
* *
* @return Response * @return Response
* @throws \InvalidArgumentException
*/ */
public function process(Request $request, RequestHandlerInterface $handler): Response public function process(Request $request, RequestHandlerInterface $handler): Response
{ {
$uri = $request->getUri(); $uri = $request->getUri();
$path = $uri->getPath(); $path = $uri->getPath();
// TODO Workaround... Do not process the request if it does not start with rest
if (\strpos($path, '/rest') !== 0) {
return $handler->handle($request);
}
// If the path does not begin with the version number, prepend v1 by default for BC compatibility purposes // If the path does not begin with the version number, prepend v1 by default for BC compatibility purposes
if (\strpos($path, '/rest/v') !== 0) { if (\strpos($path, '/v') !== 0) {
$parts = \explode('/', $path); $request = $request->withUri($uri->withPath('/v1' . $uri->getPath()));
// Remove the first empty part and the rest part
\array_shift($parts);
\array_shift($parts);
// Prepend the version prefix
\array_unshift($parts, '/rest/v1');
$request = $request->withUri($uri->withPath(\implode('/', $parts)));
} }
return $handler->handle($request); return $handler->handle($request);

View file

@ -30,22 +30,7 @@ class PathVersionMiddlewareTest extends TestCase
*/ */
public function whenVersionIsProvidedRequestRemainsUnchanged() public function whenVersionIsProvidedRequestRemainsUnchanged()
{ {
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo')); $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/v2/foo'));
$delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalled();
}
/**
* @test
*/
public function whenPathDoesNotStartWithRestRemainsUnchanged()
{
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/foo'));
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->handle($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
@ -60,14 +45,14 @@ class PathVersionMiddlewareTest extends TestCase
*/ */
public function versionOneIsPrependedWhenNoVersionIsDefined() public function versionOneIsPrependedWhenNoVersionIsDefined()
{ {
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz')); $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/bar/baz'));
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) { $delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) {
$req = \array_shift($args); $req = \array_shift($args);
Assert::assertNotSame($request, $req); Assert::assertNotSame($request, $req);
Assert::assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath()); Assert::assertEquals('/v1/bar/baz', $req->getUri()->getPath());
return new Response(); return new Response();
}); });