2016-07-05 20:19:23 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-19 18:07:59 +03:00
|
|
|
namespace Shlinkio\Shlink\Rest\Action;
|
2016-07-05 20:19:23 +03:00
|
|
|
|
2017-03-25 12:04:48 +03:00
|
|
|
use Fig\Http\Message\RequestMethodInterface;
|
|
|
|
use Fig\Http\Message\StatusCodeInterface;
|
2018-03-26 19:49:28 +03:00
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
2016-08-08 13:33:58 +03:00
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use Psr\Log\NullLogger;
|
2019-02-27 00:56:43 +03:00
|
|
|
|
2018-10-28 10:24:06 +03:00
|
|
|
use function array_merge;
|
2016-07-05 20:19:23 +03:00
|
|
|
|
2018-03-26 19:49:28 +03:00
|
|
|
abstract class AbstractRestAction implements RequestHandlerInterface, RequestMethodInterface, StatusCodeInterface
|
2016-07-05 20:19:23 +03:00
|
|
|
{
|
2018-05-01 19:16:44 +03:00
|
|
|
protected const ROUTE_PATH = '';
|
2018-05-01 19:28:37 +03:00
|
|
|
protected const ROUTE_ALLOWED_METHODS = [];
|
2018-05-01 19:16:44 +03:00
|
|
|
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var LoggerInterface */
|
2016-08-08 13:33:58 +03:00
|
|
|
protected $logger;
|
|
|
|
|
2019-08-01 20:49:54 +03:00
|
|
|
public function __construct(?LoggerInterface $logger = null)
|
2016-08-08 13:33:58 +03:00
|
|
|
{
|
|
|
|
$this->logger = $logger ?: new NullLogger();
|
|
|
|
}
|
2018-05-01 19:16:44 +03:00
|
|
|
|
|
|
|
public static function getRouteDef(array $prevMiddleware = [], array $postMiddleware = []): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => static::class,
|
2018-10-28 10:24:06 +03:00
|
|
|
'middleware' => array_merge($prevMiddleware, [static::class], $postMiddleware),
|
2018-05-01 19:16:44 +03:00
|
|
|
'path' => static::ROUTE_PATH,
|
2018-05-01 19:28:37 +03:00
|
|
|
'allowed_methods' => static::ROUTE_ALLOWED_METHODS,
|
2018-05-01 19:16:44 +03:00
|
|
|
];
|
|
|
|
}
|
2016-07-05 20:19:23 +03:00
|
|
|
}
|