Removed options bypass in actions in favor of implicit options middleware

This commit is contained in:
Alejandro Celaya 2017-04-13 09:45:31 +02:00
parent 596d1ee797
commit ec4a413a5b
7 changed files with 6 additions and 36 deletions

View file

@ -3,13 +3,9 @@ namespace Shlinkio\Shlink\Rest\Action;
use Fig\Http\Message\RequestMethodInterface;
use Fig\Http\Message\StatusCodeInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Zend\Diactoros\Response\EmptyResponse;
abstract class AbstractRestAction implements MiddlewareInterface, RequestMethodInterface, StatusCodeInterface
{
@ -22,29 +18,4 @@ abstract class AbstractRestAction implements MiddlewareInterface, RequestMethodI
{
$this->logger = $logger ?: new NullLogger();
}
/**
* Process an incoming server request and return a response, optionally delegating
* to the next middleware component to create the response.
*
* @param Request $request
* @param DelegateInterface $delegate
*
* @return Response
*/
public function process(Request $request, DelegateInterface $delegate)
{
if ($request->getMethod() === self::METHOD_OPTIONS) {
return new EmptyResponse();
}
return $this->dispatch($request, $delegate);
}
/**
* @param Request $request
* @param DelegateInterface $delegate
* @return null|Response
*/
abstract protected function dispatch(Request $request, DelegateInterface $delegate);
}

View file

@ -55,7 +55,7 @@ class AuthenticateAction extends AbstractRestAction
* @param DelegateInterface $delegate
* @return null|Response
*/
public function dispatch(Request $request, DelegateInterface $delegate)
public function process(Request $request, DelegateInterface $delegate)
{
$authData = $request->getParsedBody();
if (! isset($authData['apiKey'])) {

View file

@ -56,7 +56,7 @@ class CreateShortcodeAction extends AbstractRestAction
* @param DelegateInterface $delegate
* @return null|Response
*/
public function dispatch(Request $request, DelegateInterface $delegate)
public function process(Request $request, DelegateInterface $delegate)
{
$postData = $request->getParsedBody();
if (! isset($postData['longUrl'])) {

View file

@ -47,7 +47,7 @@ class EditTagsAction extends AbstractRestAction
* @param DelegateInterface $delegate
* @return null|Response
*/
protected function dispatch(Request $request, DelegateInterface $delegate)
public function process(Request $request, DelegateInterface $delegate)
{
$shortCode = $request->getAttribute('shortCode');
$bodyParams = $request->getParsedBody();

View file

@ -48,7 +48,7 @@ class GetVisitsAction extends AbstractRestAction
* @param DelegateInterface $delegate
* @return null|Response
*/
public function dispatch(Request $request, DelegateInterface $delegate)
public function process(Request $request, DelegateInterface $delegate)
{
$shortCode = $request->getAttribute('shortCode');
$startDate = $this->getDateQueryParam($request, 'startDate');

View file

@ -6,7 +6,6 @@ use Interop\Http\ServerMiddleware\DelegateInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
@ -50,7 +49,7 @@ class ListShortcodesAction extends AbstractRestAction
* @param DelegateInterface $delegate
* @return null|Response
*/
public function dispatch(Request $request, DelegateInterface $delegate)
public function process(Request $request, DelegateInterface $delegate)
{
try {
$params = $this->queryToListParams($request->getQueryParams());

View file

@ -47,7 +47,7 @@ class ResolveUrlAction extends AbstractRestAction
* @param DelegateInterface $delegate
* @return null|Response
*/
public function dispatch(Request $request, DelegateInterface $delegate)
public function process(Request $request, DelegateInterface $delegate)
{
$shortCode = $request->getAttribute('shortCode');