Reduced responsibilities of HttpHelper
This commit is contained in:
parent
3744f0429a
commit
6c9954f298
5 changed files with 24 additions and 28 deletions
|
@ -34,7 +34,7 @@ final class PostContentController extends AbstractController
|
|||
public function getPostContent($postName)
|
||||
{
|
||||
$post = $this->postService->getByName($postName);
|
||||
$this->networkingService->serve($this->fileDao->getFullPath($post->getContentPath()));
|
||||
$this->networkingService->serveFile($this->fileDao->getFullPath($post->getContentPath()));
|
||||
}
|
||||
|
||||
public function getPostThumbnail($postName, $size)
|
||||
|
@ -47,6 +47,6 @@ final class PostContentController extends AbstractController
|
|||
|
||||
$this->thumbnailService->generateIfNeeded($sourceName, $size, $size);
|
||||
$thumbnailName = $this->thumbnailService->getThumbnailName($sourceName, $size, $size);
|
||||
$this->networkingService->serve($this->fileDao->getFullPath($thumbnailName));
|
||||
$this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
namespace Szurubooru\Controllers;
|
||||
use Szurubooru\Dao\PublicFileDao;
|
||||
use Szurubooru\Entities\User;
|
||||
use Szurubooru\Helpers\HttpHelper;
|
||||
use Szurubooru\Router;
|
||||
use Szurubooru\Services\NetworkingService;
|
||||
use Szurubooru\Services\ThumbnailService;
|
||||
|
@ -13,20 +12,17 @@ final class UserAvatarController extends AbstractController
|
|||
private $fileDao;
|
||||
private $userService;
|
||||
private $networkingService;
|
||||
private $httpHelper;
|
||||
private $thumbnailService;
|
||||
|
||||
public function __construct(
|
||||
PublicFileDao $fileDao,
|
||||
UserService $userService,
|
||||
NetworkingService $networkingService,
|
||||
HttpHelper $httpHelper,
|
||||
ThumbnailService $thumbnailService)
|
||||
{
|
||||
$this->fileDao = $fileDao;
|
||||
$this->userService = $userService;
|
||||
$this->networkingService = $networkingService;
|
||||
$this->httpHelper = $httpHelper;
|
||||
$this->thumbnailService = $thumbnailService;
|
||||
}
|
||||
|
||||
|
@ -70,14 +66,14 @@ final class UserAvatarController extends AbstractController
|
|||
|
||||
private function serveFromUrl($url)
|
||||
{
|
||||
$this->httpHelper->redirect($url);
|
||||
$this->networkingService->redirect($url);
|
||||
}
|
||||
|
||||
private function serveFromFile($sourceName, $size)
|
||||
{
|
||||
$this->thumbnailService->generateIfNeeded($sourceName, $size, $size);
|
||||
$thumbnailName = $this->thumbnailService->getThumbnailName($sourceName, $size, $size);
|
||||
$this->networkingService->serve($this->fileDao->getFullPath($thumbnailName));
|
||||
$this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName));
|
||||
}
|
||||
|
||||
private function serveBlankFile($size)
|
||||
|
|
|
@ -30,11 +30,11 @@ final class Dispatcher
|
|||
$this->config = $config;
|
||||
$this->databaseConnection = $databaseConnection;
|
||||
$this->httpHelper = $httpHelper;
|
||||
$this->authService = $authService;
|
||||
$this->tokenService = $tokenService;
|
||||
|
||||
//if script fails prematurely, mark it as fail from advance
|
||||
$this->httpHelper->setResponseCode(500);
|
||||
$this->authService = $authService;
|
||||
$this->tokenService = $tokenService;
|
||||
|
||||
foreach ($controllerRepository->getControllers() as $controller)
|
||||
$controller->registerRoutes($router);
|
||||
|
|
|
@ -13,11 +13,6 @@ class HttpHelper
|
|||
header($key . ': ' . $value);
|
||||
}
|
||||
|
||||
public function output($data)
|
||||
{
|
||||
echo $data;
|
||||
}
|
||||
|
||||
public function outputJSON($data)
|
||||
{
|
||||
$encodedJson = json_encode((array) $data);
|
||||
|
@ -28,6 +23,11 @@ class HttpHelper
|
|||
$this->output($encodedJson);
|
||||
}
|
||||
|
||||
public function output($data)
|
||||
{
|
||||
echo $data;
|
||||
}
|
||||
|
||||
public function getRequestHeaders()
|
||||
{
|
||||
return getallheaders();
|
||||
|
@ -50,16 +50,4 @@ class HttpHelper
|
|||
$requestUri = preg_replace('/\?.*$/', '', $requestUri);
|
||||
return $requestUri;
|
||||
}
|
||||
|
||||
public function redirect($destination)
|
||||
{
|
||||
$this->setResponseCode(307);
|
||||
$this->setHeader('Location', $destination);
|
||||
}
|
||||
|
||||
public function nonCachedRedirect($destination)
|
||||
{
|
||||
$this->setResponseCode(303);
|
||||
$this->setHeader('Location', $destination);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class NetworkingService
|
|||
$this->httpHelper = $httpHelper;
|
||||
}
|
||||
|
||||
public function serve($fullPath, $options = [])
|
||||
public function serveFile($fullPath, $options = [])
|
||||
{
|
||||
$daysToLive = isset($options->daysToLive)
|
||||
? $options->daysToLive
|
||||
|
@ -93,4 +93,16 @@ class NetworkingService
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function redirect($destination)
|
||||
{
|
||||
$this->httpHelper->setResponseCode(307);
|
||||
$this->httpHelper->setHeader('Location', $destination);
|
||||
}
|
||||
|
||||
public function nonCachedRedirect($destination)
|
||||
{
|
||||
$this->httpHelper->setResponseCode(303);
|
||||
$this->httpHelper->setHeader('Location', $destination);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue