2016-07-05 20:19:23 +03:00
|
|
|
<?php
|
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;
|
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 = '';
|
|
|
|
protected const ALLOWED_METHODS = [];
|
|
|
|
|
2016-08-08 13:33:58 +03:00
|
|
|
/**
|
|
|
|
* @var LoggerInterface
|
|
|
|
*/
|
|
|
|
protected $logger;
|
|
|
|
|
|
|
|
public function __construct(LoggerInterface $logger = null)
|
|
|
|
{
|
|
|
|
$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,
|
|
|
|
'middleware' => \array_merge($prevMiddleware, [static::class], $postMiddleware),
|
|
|
|
'path' => static::ROUTE_PATH,
|
|
|
|
'allowed_methods' => static::ALLOWED_METHODS,
|
|
|
|
];
|
|
|
|
}
|
2016-07-05 20:19:23 +03:00
|
|
|
}
|