Skip to content

Commit

Permalink
Cleaner way to build the redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Oct 21, 2020
1 parent 7dead95 commit 7d856c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion classes/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use Alltube\Library\Downloader;
use Alltube\Library\Video;
use Alltube\LocaleManager;
use Alltube\SessionFactory;
use Aura\Session\Segment;
use Consolidation\Log\Logger;
use Psr\Container\ContainerInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Router;

/**
* Abstract class used by every controller.
Expand Down Expand Up @@ -76,6 +76,11 @@ abstract class BaseController
*/
protected $logger;

/**
* @var Router
*/
protected $router;

/**
* BaseController constructor.
*
Expand All @@ -89,6 +94,7 @@ public function __construct(ContainerInterface $container)
$this->sessionSegment = $session->getSegment(self::class);
$this->localeManager = $this->container->get('locale');
$this->downloader = $this->config->getDownloader();
$this->router = $this->container->get('router');
$this->logger = $this->container->get('logger');
$this->downloader->setLogger($this->logger);

Expand Down
2 changes: 1 addition & 1 deletion classes/Controller/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function download(Request $request, Response $response)
}
}
} else {
return $response->withRedirect($this->container->get('router')->pathFor('index'));
return $response->withRedirect($this->router->pathFor('index'));
}
}

Expand Down
8 changes: 4 additions & 4 deletions classes/Controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Alltube\Middleware\CspMiddleware;
use Exception;
use Slim\Http\StatusCode;
use Slim\Http\Uri;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Throwable;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -82,7 +83,7 @@ public function locale(Request $request, Response $response, array $data)
{
$this->localeManager->setLocale(new Locale($data['locale']));

return $response->withRedirect($this->container->get('router')->pathFor('index'));
return $response->withRedirect($this->router->pathFor('index'));
}

/**
Expand Down Expand Up @@ -209,14 +210,13 @@ public function info(Request $request, Response $response)
if ($this->config->convert && $request->getQueryParam('audio')) {
// We skip the info page and get directly to the download.
return $response->withRedirect(
$this->container->get('router')->pathFor('download') .
'?' . http_build_query($request->getQueryParams())
$this->router->pathFor('download', [], $request->getQueryParams())
);
} else {
return $this->getInfoResponse($request, $response);
}
} else {
return $response->withRedirect($this->container->get('router')->pathFor('index'));
return $response->withRedirect($this->router->pathFor('index'));
}
}

Expand Down

0 comments on commit 7d856c6

Please sign in to comment.