Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Apr 7, 2018
2 parents 243075d + e504daa commit d2a0425
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 36 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

### 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**

* [125: Implement a path which returns a 1px image instead of a redirection](https://github.com/shlinkio/shlink/issues/125)
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/middleware-pipeline.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'priority' => 11,
],
'pre-routing-rest' => [
// 'path' => '/rest',
'path' => '/rest',
'middleware' => [
PathVersionMiddleware::class,
],
Expand Down
Empty file modified data/infra/database/.gitignore
100644 → 100755
Empty file.
Empty file modified data/infra/nginx/.gitignore
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions module/CLI/src/Command/Install/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function execute(InputInterface $input, OutputInterface $output)
if (! $this->isUpdate) {
$this->io->write('Initializing database...');
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.',
$output
)) {
Expand All @@ -145,7 +145,7 @@ public function execute(InputInterface $input, OutputInterface $output)
// Run database migrations
$this->io->write('Updating database...');
if (! $this->runCommand(
'php vendor/bin/doctrine-migrations migrations:migrate',
'php vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate',
'Error updating database.',
$output
)) {
Expand All @@ -155,7 +155,7 @@ public function execute(InputInterface $input, OutputInterface $output)
// Generate proxies
$this->io->write('Generating proxies...');
if (! $this->runCommand(
'php vendor/bin/doctrine orm:generate-proxies',
'php vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies',
'Error generating proxies.',
$output
)) {
Expand Down
17 changes: 3 additions & 14 deletions module/Rest/src/Middleware/PathVersionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,16 @@ class PathVersionMiddleware implements MiddlewareInterface
* @param RequestHandlerInterface $handler
*
* @return Response
* @throws \InvalidArgumentException
*/
public function process(Request $request, RequestHandlerInterface $handler): Response
{
$uri = $request->getUri();
$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 (\strpos($path, '/rest/v') !== 0) {
$parts = \explode('/', $path);
// 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)));
if (\strpos($path, '/v') !== 0) {
$request = $request->withUri($uri->withPath('/v1' . $uri->getPath()));
}

return $handler->handle($request);
Expand Down
21 changes: 3 additions & 18 deletions module/Rest/test/Middleware/PathVersionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,7 @@ public function setUp()
*/
public function whenVersionIsProvidedRequestRemainsUnchanged()
{
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/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'));
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/v2/foo'));

$delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->handle($request)->willReturn(new Response());
Expand All @@ -60,14 +45,14 @@ public function whenPathDoesNotStartWithRestRemainsUnchanged()
*/
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->handle(Argument::type(Request::class))->will(function (array $args) use ($request) {
$req = \array_shift($args);

Assert::assertNotSame($request, $req);
Assert::assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath());
Assert::assertEquals('/v1/bar/baz', $req->getUri()->getPath());
return new Response();
});

Expand Down

0 comments on commit d2a0425

Please sign in to comment.