shlink/module/Rest/src/Action/AbstractRestAction.php

38 lines
1 KiB
PHP
Raw Normal View History

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
use Fig\Http\Message\RequestMethodInterface;
use Fig\Http\Message\StatusCodeInterface;
2018-03-26 19:49:28 +03:00
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
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
{
protected const ROUTE_PATH = '';
protected const ROUTE_ALLOWED_METHODS = [];
/** @var LoggerInterface */
protected $logger;
public function __construct(?LoggerInterface $logger = null)
{
$this->logger = $logger ?: new NullLogger();
}
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::ROUTE_ALLOWED_METHODS,
];
}
2016-07-05 20:19:23 +03:00
}