Skip to content

Commit

Permalink
处理方法返回值
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Nov 6, 2023
1 parent 1417c1b commit 0cbc144
Show file tree
Hide file tree
Showing 93 changed files with 139 additions and 397 deletions.
4 changes: 1 addition & 3 deletions src/Aop/Aop/FilterArgAop.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ class FilterArgAop
{
/**
* 过滤方法参数.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Aop\Annotation\FilterArg::class])]
#[Before]
public function parse(JoinPoint $joinPoint)
public function parse(JoinPoint $joinPoint): void
{
$class = BeanFactory::getObjectClass($joinPoint->getTarget());
$method = $joinPoint->getMethod();
Expand Down
4 changes: 1 addition & 3 deletions src/Aop/Aop/InjectArgAop.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ class InjectArgAop
{
/**
* 方法参数注入.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Aop\Annotation\InjectArg::class])]
#[Around]
public function parse(AroundJoinPoint $joinPoint)
public function parse(AroundJoinPoint $joinPoint): mixed
{
$class = BeanFactory::getObjectClass($joinPoint->getTarget());
$method = $joinPoint->getMethod();
Expand Down
18 changes: 9 additions & 9 deletions src/Async/Aop/AsyncAop.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ class AsyncAop
{
/**
* 异步执行.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Async\Annotation\Async::class])]
#[Around]
public function parseAsync(AroundJoinPoint $joinPoint)
public function parseAsync(AroundJoinPoint $joinPoint): mixed
{
$result = \Imi\Async\Async::exec(static fn () => $joinPoint->proceed());
$className = BeanFactory::getObjectClass($joinPoint->getTarget());
Expand All @@ -32,16 +30,16 @@ public function parseAsync(AroundJoinPoint $joinPoint)
{
return $result;
}

return null;
}

/**
* 延后执行.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Async\Annotation\Defer::class])]
#[Around]
public function parseDefer(AroundJoinPoint $joinPoint)
public function parseDefer(AroundJoinPoint $joinPoint): mixed
{
$result = \Imi\Async\Async::defer(static fn () => $joinPoint->proceed());
$className = BeanFactory::getObjectClass($joinPoint->getTarget());
Expand All @@ -50,16 +48,16 @@ public function parseDefer(AroundJoinPoint $joinPoint)
{
return $result;
}

return null;
}

/**
* 延后执行.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Async\Annotation\DeferAsync::class])]
#[Around]
public function parseDeferAsync(AroundJoinPoint $joinPoint)
public function parseDeferAsync(AroundJoinPoint $joinPoint): mixed
{
$result = \Imi\Async\Async::deferAsync(static fn () => $joinPoint->proceed());
$className = BeanFactory::getObjectClass($joinPoint->getTarget());
Expand All @@ -68,5 +66,7 @@ public function parseDeferAsync(AroundJoinPoint $joinPoint)
{
return $result;
}

return null;
}
}
4 changes: 1 addition & 3 deletions src/Cache/Aop/CacheEvictAop.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ class CacheEvictAop

/**
* 处理 CacheEvict 注解.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Cache\Annotation\CacheEvict::class])]
#[Around]
public function parseCacheEvict(AroundJoinPoint $joinPoint)
public function parseCacheEvict(AroundJoinPoint $joinPoint): mixed
{
$class = BeanFactory::getObjectClass($joinPoint->getTarget());
$method = $joinPoint->getMethod();
Expand Down
4 changes: 1 addition & 3 deletions src/Cache/Aop/CachePutAop.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ class CachePutAop

/**
* 处理 CachePut 注解.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Cache\Annotation\CachePut::class])]
#[Around]
public function parseCachePut(AroundJoinPoint $joinPoint)
public function parseCachePut(AroundJoinPoint $joinPoint): mixed
{
$methodReturn = $joinPoint->proceed();
$method = $joinPoint->getMethod();
Expand Down
4 changes: 1 addition & 3 deletions src/Cache/Aop/CacheableAop.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ class CacheableAop

/**
* 处理 Cacheable 注解.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\Cache\Annotation\Cacheable::class])]
#[Around]
public function parseCacheable(AroundJoinPoint $joinPoint)
public function parseCacheable(AroundJoinPoint $joinPoint): mixed
{
$target = $joinPoint->getTarget();
$class = BeanFactory::getObjectClass($target);
Expand Down
1 change: 1 addition & 0 deletions src/Components/amqp/src/Queue/QueueConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ protected function bindConsumer(): void
protected function consume(IMessage $message): mixed
{
$this->queue->push($message);

return null;
}
}
15 changes: 3 additions & 12 deletions src/Components/fpm/tests/Web/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
#[Controller(prefix: '/')]
class IndexController extends HttpController
{
/**
* @return mixed
*/
#[Action]
#[Route(url: '/')]
public function index()
public function index(): mixed
{
$response = RequestContext::get('response');
$response->getBody()->write('imi');
Expand Down Expand Up @@ -178,11 +175,8 @@ public function redirect(): mixed
return RequestContext::get('response')->redirect('/', StatusCode::MOVED_PERMANENTLY);
}

/**
* @return mixed
*/
#[Action]
public function download(?string $contentType = null, ?string $outputFileName = null)
public function download(?string $contentType = null, ?string $outputFileName = null): mixed
{
return RequestContext::get('response')->sendFile(__FILE__, $contentType, $outputFileName);
}
Expand Down Expand Up @@ -258,12 +252,9 @@ public function singletonResponse2(): void
ResponseProxy::__setProxyInstance($this->response->withBody(new MemoryStream('imi niubi-2')));
}

/**
* @return array
*/
#[Action]
#[Route(url: '/type/{id}/{name}/{page}')]
public function type(int $id, string $name, int $page)
public function type(int $id, string $name, int $page): array
{
return compact('id', 'name', 'page');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@ class IndexController extends HttpController
#[GrpcService(serviceName: 'grpc.AuthService', interface: 'Grpc\\AuthServiceInterface')]
protected $authService;

/**
* @return mixed
*/
#[Action]
#[Route(url: '/')]
public function index()
public function index(): mixed
{
return $this->response;
}

/**
* 测试登录.
*
* @return mixed
*/
#[Action]
public function testLogin(string $phone, string $password)
public function testLogin(string $phone, string $password): array
{
$request = new LoginRequest();
$request->setPhone($phone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ class ProxyController extends HttpController
#[Inject(name: 'GrpcHttpProxy')]
protected GrpcHttpProxy $grpcHttpProxy;

/**
* @return mixed
*/
#[Action]
#[Route(url: 'grpc/{service}/{method}')]
public function proxy(string $service, string $method)
public function proxy(string $service, string $method): mixed
{
return $this->grpcHttpProxy->proxy('grpc', $this->request, $this->response, $service, $method);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Components/grpc/src/Client/Contract/IGrpcService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ interface IGrpcService extends IService
* 发送请求
* 成功返回 streamId
* $metadata 格式:['key' => ['value']].
*
* @return int|bool
*/
public function send(string $method, \Google\Protobuf\Internal\Message $message, array $metadata = []);
public function send(string $method, \Google\Protobuf\Internal\Message $message, array $metadata = []): int|bool;

/**
* 接收响应结果.
Expand Down
4 changes: 1 addition & 3 deletions src/Components/grpc/src/Client/GrpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ public function getOptions(): array
* 发送请求
*
* $metadata 格式:['key' => ['value']]
*
* @return int|bool
*/
public function send(string $package, string $service, string $name, \Google\Protobuf\Internal\Message $message, array $metadata = [])
public function send(string $package, string $service, string $name, \Google\Protobuf\Internal\Message $message, array $metadata = []): int|bool
{
if (!$this->isConnected())
{
Expand Down
4 changes: 1 addition & 3 deletions src/Components/grpc/src/Client/GrpcService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ public function getName(): string
* 发送请求
* 成功返回 streamId
* $metadata 格式:['key' => ['value']].
*
* @return int|bool
*/
public function send(string $method, \Google\Protobuf\Internal\Message $message, array $metadata = [])
public function send(string $method, \Google\Protobuf\Internal\Message $message, array $metadata = []): int|bool
{
return $this->client->send($this->package, $this->serviceName, $method, $message, $metadata);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Components/jwt/src/Aop/JWTValidationAop.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ class JWTValidationAop
{
/**
* 环绕注入.
*
* @return mixed
*/
#[PointCut(type: \Imi\Aop\PointCutType::ANNOTATION, allow: [\Imi\JWT\Annotation\JWTValidation::class])]
#[Around]
public function around(AroundJoinPoint $joinPoint)
public function around(AroundJoinPoint $joinPoint): mixed
{
$target = $joinPoint->getTarget();
$class = BeanFactory::getObjectClass($target);
Expand Down
6 changes: 4 additions & 2 deletions src/Components/jwt/src/Model/JWTConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class JWTConfig
* 设为 true 则为当前时间
* 设为 false 不设置
* 其它值则直接写入.
*
* @var bool|mixed
*/
private bool $issuedAt = true;
private mixed $issuedAt = true;

/**
* Token id.
Expand Down Expand Up @@ -174,7 +176,7 @@ public function getSubject(): ?string
*
* @return bool|mixed
*/
public function getIssuedAt()
public function getIssuedAt(): mixed
{
return $this->issuedAt;
}
Expand Down
10 changes: 2 additions & 8 deletions src/Components/jwt/tests/Test/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
#[Bean(name: 'A')]
class A
{
/**
* @return array
*/
#[JWTValidation(tokenParam: 'token', dataParam: 'data')]
public function test(?\Lcobucci\JWT\Token $token = null, ?\stdClass $data = null)
public function test(?\Lcobucci\JWT\Token $token = null, ?\stdClass $data = null): array
{
return [$token, $data];
}

/**
* @return array
*/
#[JWTValidation(name: 'b', tokenParam: 'token', dataParam: 'data')]
public function testFail(?\Lcobucci\JWT\Token $token = null, ?\stdClass $data = null)
public function testFail(?\Lcobucci\JWT\Token $token = null, ?\stdClass $data = null): array
{
return [$token, $data];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@
#[Controller(prefix: '/')]
class IndexController extends HttpController
{
/**
* @return mixed
*/
#[Action]
#[Route(url: '/')]
public function index()
public function index(): mixed
{
$this->response->getBody()->write('imi');

return $this->response;
}

/**
* @return mixed
*/
#[Action]
public function publish(int $memberId = 19260817)
public function publish(int $memberId = 19260817): array
{
$producer = KafkaPool::getInstance();
$producer->send('queue-imi-1', json_encode([
Expand All @@ -51,11 +45,8 @@ public function publish(int $memberId = 19260817)
];
}

/**
* @return mixed
*/
#[Action]
public function consume(int $memberId)
public function consume(int $memberId): array
{
$r1 = Redis::get($key1 = 'imi-kafka:consume:1:' . $memberId);
$r2 = Redis::get($key2 = 'imi-kafka:consume:QueueTest:' . $memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function ping(PingRequestPacket $request, ReceiveData $receiveData): ?Pin
*
* @return \BinSoul\Net\Mqtt\Packet\PublishAckPacket|\BinSoul\Net\Mqtt\Packet\PublishReceivedPacket|\BinSoul\Net\Mqtt\Packet\PublishReleasePacket|\BinSoul\Net\Mqtt\Packet\PublishCompletePacket|null
*/
public function publish(PublishRequestPacket $request, ReceiveData $receiveData)
public function publish(PublishRequestPacket $request, ReceiveData $receiveData): mixed
{
switch ($request->getTopic())
{
Expand Down
Loading

0 comments on commit 0cbc144

Please sign in to comment.