mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 04:37:46 +08:00
Upgrade the minimum php version to 8.0 for dispatcher (#4240)
This commit is contained in:
parent
2b75daf92b
commit
c80c64b4e1
@ -18,7 +18,7 @@
|
||||
"source": "https://github.com/hyperf/hyperf"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"php": ">=8.0",
|
||||
"psr/container": "^1.0|^2.0",
|
||||
"psr/http-server-middleware": "^1.0",
|
||||
"psr/http-message": "^1.0",
|
||||
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="./vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
<testsuites>
|
||||
<testsuite name="Tests">
|
||||
<directory suffix="Test.php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -15,51 +15,30 @@ use Hyperf\Dispatcher\Exceptions\InvalidArgumentException;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
abstract class AbstractRequestHandler
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewares = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $offset = 0;
|
||||
|
||||
/**
|
||||
* @var null|MiddlewareInterface|object
|
||||
*/
|
||||
protected $coreHandler;
|
||||
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
protected int $offset = 0;
|
||||
|
||||
/**
|
||||
* @param array $middlewares All middlewares to dispatch by dispatcher
|
||||
* @param MiddlewareInterface|object $coreHandler The core middleware of dispatcher
|
||||
*/
|
||||
public function __construct(array $middlewares, $coreHandler, ContainerInterface $container)
|
||||
public function __construct(protected array $middlewares, protected $coreHandler, protected ContainerInterface $container)
|
||||
{
|
||||
$this->middlewares = array_values($middlewares);
|
||||
$this->coreHandler = $coreHandler;
|
||||
$this->container = $container;
|
||||
$this->middlewares = array_values($this->middlewares);
|
||||
}
|
||||
|
||||
protected function handleRequest($request)
|
||||
{
|
||||
if (! isset($this->middlewares[$this->offset]) && ! empty($this->coreHandler)) {
|
||||
if (! isset($this->middlewares[$this->offset])) {
|
||||
$handler = $this->coreHandler;
|
||||
} else {
|
||||
$handler = $this->middlewares[$this->offset];
|
||||
is_string($handler) && $handler = $this->container->get($handler);
|
||||
}
|
||||
if (! method_exists($handler, 'process')) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid middleware, it has to provide a process() method.'));
|
||||
if (! $handler || ! method_exists($handler, 'process')) {
|
||||
throw new InvalidArgumentException('Invalid middleware, it has to provide a process() method.');
|
||||
}
|
||||
return $handler->process($request, $this->next());
|
||||
}
|
||||
|
@ -18,14 +18,8 @@ use Psr\Http\Server\MiddlewareInterface;
|
||||
|
||||
class HttpDispatcher extends AbstractDispatcher
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
public function __construct(private ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function dispatch(...$params): ResponseInterface
|
||||
|
Loading…
Reference in New Issue
Block a user