Merge branch 'master' of github.com:hyperf-cloud/hyperf

This commit is contained in:
huangzhhui 2019-06-06 21:07:47 +08:00
commit 002bc568ad
7 changed files with 4 additions and 144 deletions

View File

@ -1,62 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Framework;
use Psr\Http\Message\ResponseInterface;
use Throwable;
/**
* @deprecated
*/
abstract class ExceptionHandler
{
/**
* Determine if the exception should propagate to next handler.
*
* @var bool
*/
protected $propagationStopped = false;
/**
* Handle the exception, and return the specified result.
*/
abstract public function handle(Throwable $throwable, ResponseInterface $response);
/**
* Determine if the current exception handler should handle the exception,.
*
* @return bool
* If return true, then this exception handler will handle the exception,
* If return false, then delegate to next handler
*/
abstract public function isValid(Throwable $throwable): bool;
/**
* Stop propagate the exception to next handler.
*/
public function stopPropagation(): bool
{
$this->propagationStopped = true;
return $this->propagationStopped;
}
/**
* Is propagation stopped ?
* This will typically only be used by the handler to determine if the
* provious handler halted propagation.
*/
public function isPropagationStopped(): bool
{
return $this->propagationStopped;
}
}

View File

@ -1,70 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Framework;
use Hyperf\Dispatcher\AbstractDispatcher;
use Hyperf\Utils\Context;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Throwable;
/**
* @deprecated
*/
class ExceptionHandlerDispatcher extends AbstractDispatcher
{
/**
* @var ContainerInterface
*/
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* {@inheritdoc}
*/
public function dispatch(...$params)
{
return parent::dispatch(...$params);
}
/**
* {@inheritdoc}
*/
public function handle(...$params)
{
/**
* @var Throwable
* @var string[] $handlers
*/
[$throwable, $handlers] = $params;
$response = Context::get(ResponseInterface::class);
foreach ($handlers as $handler) {
if (! $this->container->has($handler)) {
throw new \InvalidArgumentException(sprintf('Invalid exception handler %s.', $handler));
}
$handlerInstance = $this->container->get($handler);
if (! $handlerInstance instanceof ExceptionHandler || ! $handlerInstance->isValid($throwable)) {
continue;
}
$response = $handlerInstance->handle($throwable, $response);
if ($handlerInstance->isPropagationStopped()) {
break;
}
}
return $response;
}
}

View File

@ -19,7 +19,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
/**
* @inheritDoc
* {@inheritdoc}
*/
class CoreMiddleware extends \Hyperf\RpcServer\CoreMiddleware
{

View File

@ -17,7 +17,6 @@ use Hyperf\Utils\Packer\JsonPacker;
class DataFormatter implements DataFormatterInterface
{
/**
* @var JsonPacker
*/

View File

@ -12,10 +12,8 @@ declare(strict_types=1);
namespace Hyperf\JsonRpc;
use Hyperf\Framework\ExceptionHandlerDispatcher;
use Hyperf\HttpMessage\Server\Request as Psr7Request;
use Hyperf\HttpMessage\Server\Response as Psr7Response;
use Hyperf\HttpServer\MiddlewareManager;
use Hyperf\HttpServer\Server;
use Hyperf\Rpc\ProtocolManager;
use Hyperf\Server\Exception\InvalidArgumentException;
@ -25,7 +23,6 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Swoole\Http\Request as SwooleRequest;
use Swoole\Http\Response as SwooleResponse;
use Throwable;
class HttpServer extends Server
{

View File

@ -72,23 +72,20 @@ class JsonRpcHttpTransporter implements TransporterInterface
$url = $schema . $uri;
$response = $this->getClient()->post($url, [
'headers' => [
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
],
'body' => $data,
]);
if ($response->getStatusCode() === 200) {
return $response->getBody()->getContents();
} else {
}
}
public function getClient(): Client
{
$client = $this->clientFactory->create([
return $this->clientFactory->create([
'timeout' => ($this->connectTimeout + $this->recvTimeout),
]);
return $client;
}
public function getLoadBalancer(): ?LoadBalancerInterface

View File

@ -13,8 +13,8 @@ declare(strict_types=1);
namespace Hyperf\JsonRpc;
use Hyperf\HttpMessage\Server\Request as Psr7Request;
use Hyperf\HttpMessage\Uri\Uri;
use Hyperf\HttpMessage\Server\Response as Psr7Response;
use Hyperf\HttpMessage\Uri\Uri;
use Hyperf\Rpc\ProtocolManager;
use Hyperf\RpcServer\Server;
use Hyperf\Server\ServerManager;
@ -27,7 +27,6 @@ use Swoole\Server as SwooleServer;
class TcpServer extends Server
{
/**
* @var ProtocolManager
*/