mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
Add more mapping annotations
This commit is contained in:
parent
940105c0f8
commit
dda195767d
@ -20,6 +20,10 @@ use Hyperf\Di\Aop\ArroundInterface;
|
|||||||
*/
|
*/
|
||||||
class Aspect extends AbstractAnnotation
|
class Aspect extends AbstractAnnotation
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public function collect(string $className, ?string $target): void
|
public function collect(string $className, ?string $target): void
|
||||||
{
|
{
|
||||||
// @TODO Add order property.
|
// @TODO Add order property.
|
||||||
|
@ -31,12 +31,13 @@ class Inject extends AbstractAnnotation
|
|||||||
$this->docReader = new PhpDocReader();
|
$this->docReader = new PhpDocReader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public function collect(string $className, ?string $target): void
|
public function collect(string $className, ?string $target): void
|
||||||
{
|
{
|
||||||
if (! $this->value) {
|
if (null !== $this->value) {
|
||||||
$this->value = $this->docReader->getPropertyClass(ReflectionManager::reflectClass($className)->getProperty($target));
|
$this->value = $this->docReader->getPropertyClass(ReflectionManager::reflectClass($className)->getProperty($target));
|
||||||
}
|
|
||||||
if (isset($this->value)) {
|
|
||||||
AnnotationCollector::collectProperty($className, $target, static::class, $this->value);
|
AnnotationCollector::collectProperty($className, $target, static::class, $this->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
src/http-server/src/Annotation/DeleteMapping.php
Normal file
41
src/http-server/src/Annotation/DeleteMapping.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hyperf\HttpServer\Annotation;
|
||||||
|
|
||||||
|
use Hyperf\Di\Annotation\AbstractAnnotation;
|
||||||
|
use Hyperf\Di\Annotation\AnnotationCollector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"METHOD"})
|
||||||
|
*/
|
||||||
|
class DeleteMapping extends AbstractAnnotation
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $path;
|
||||||
|
|
||||||
|
public function __construct($value = null)
|
||||||
|
{
|
||||||
|
parent::__construct($value);
|
||||||
|
if (isset($value['path'])) {
|
||||||
|
$this->path = $value['path'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function collect(string $className, ?string $target): void
|
||||||
|
{
|
||||||
|
if ($this->methods && $this->path) {
|
||||||
|
AnnotationCollector::collectMethod($className, $target, static::class, [
|
||||||
|
'methods' => ['DELETE'],
|
||||||
|
'path' => $this->path,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
src/http-server/src/Annotation/GetMapping.php
Normal file
41
src/http-server/src/Annotation/GetMapping.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hyperf\HttpServer\Annotation;
|
||||||
|
|
||||||
|
use Hyperf\Di\Annotation\AbstractAnnotation;
|
||||||
|
use Hyperf\Di\Annotation\AnnotationCollector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"METHOD"})
|
||||||
|
*/
|
||||||
|
class GetMapping extends AbstractAnnotation
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $path;
|
||||||
|
|
||||||
|
public function __construct($value = null)
|
||||||
|
{
|
||||||
|
parent::__construct($value);
|
||||||
|
if (isset($value['path'])) {
|
||||||
|
$this->path = $value['path'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function collect(string $className, ?string $target): void
|
||||||
|
{
|
||||||
|
if ($this->methods && $this->path) {
|
||||||
|
AnnotationCollector::collectMethod($className, $target, static::class, [
|
||||||
|
'methods' => ['GET'],
|
||||||
|
'path' => $this->path,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
src/http-server/src/Annotation/PatchMapping.php
Normal file
41
src/http-server/src/Annotation/PatchMapping.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hyperf\HttpServer\Annotation;
|
||||||
|
|
||||||
|
use Hyperf\Di\Annotation\AbstractAnnotation;
|
||||||
|
use Hyperf\Di\Annotation\AnnotationCollector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"METHOD"})
|
||||||
|
*/
|
||||||
|
class PatchMapping extends AbstractAnnotation
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $path;
|
||||||
|
|
||||||
|
public function __construct($value = null)
|
||||||
|
{
|
||||||
|
parent::__construct($value);
|
||||||
|
if (isset($value['path'])) {
|
||||||
|
$this->path = $value['path'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function collect(string $className, ?string $target): void
|
||||||
|
{
|
||||||
|
if ($this->methods && $this->path) {
|
||||||
|
AnnotationCollector::collectMethod($className, $target, static::class, [
|
||||||
|
'methods' => ['PATCH'],
|
||||||
|
'path' => $this->path,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
src/http-server/src/Annotation/PostMapping.php
Normal file
41
src/http-server/src/Annotation/PostMapping.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hyperf\HttpServer\Annotation;
|
||||||
|
|
||||||
|
use Hyperf\Di\Annotation\AbstractAnnotation;
|
||||||
|
use Hyperf\Di\Annotation\AnnotationCollector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"METHOD"})
|
||||||
|
*/
|
||||||
|
class PostMapping extends AbstractAnnotation
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $path;
|
||||||
|
|
||||||
|
public function __construct($value = null)
|
||||||
|
{
|
||||||
|
parent::__construct($value);
|
||||||
|
if (isset($value['path'])) {
|
||||||
|
$this->path = $value['path'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function collect(string $className, ?string $target): void
|
||||||
|
{
|
||||||
|
if ($this->methods && $this->path) {
|
||||||
|
AnnotationCollector::collectMethod($className, $target, static::class, [
|
||||||
|
'methods' => ['POST'],
|
||||||
|
'path' => $this->path,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
src/http-server/src/Annotation/PutMapping.php
Normal file
41
src/http-server/src/Annotation/PutMapping.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hyperf\HttpServer\Annotation;
|
||||||
|
|
||||||
|
use Hyperf\Di\Annotation\AbstractAnnotation;
|
||||||
|
use Hyperf\Di\Annotation\AnnotationCollector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"METHOD"})
|
||||||
|
*/
|
||||||
|
class PutMapping extends AbstractAnnotation
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $path;
|
||||||
|
|
||||||
|
public function __construct($value = null)
|
||||||
|
{
|
||||||
|
parent::__construct($value);
|
||||||
|
if (isset($value['path'])) {
|
||||||
|
$this->path = $value['path'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function collect(string $className, ?string $target): void
|
||||||
|
{
|
||||||
|
if ($this->methods && $this->path) {
|
||||||
|
AnnotationCollector::collectMethod($className, $target, static::class, [
|
||||||
|
'methods' => ['PUT'],
|
||||||
|
'path' => $this->path,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,7 +33,7 @@ class RequestMapping extends AbstractAnnotation
|
|||||||
|
|
||||||
public function __construct($value = null)
|
public function __construct($value = null)
|
||||||
{
|
{
|
||||||
$this->value = $value;
|
parent::__construct($value);
|
||||||
if (isset($value['methods'])) {
|
if (isset($value['methods'])) {
|
||||||
// Explode a string to a array
|
// Explode a string to a array
|
||||||
$this->methods = explode(',', Str::upper(str_replace(' ', '', $value['methods'])));
|
$this->methods = explode(',', Str::upper(str_replace(' ', '', $value['methods'])));
|
||||||
@ -43,6 +43,9 @@ class RequestMapping extends AbstractAnnotation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
public function collect(string $className, ?string $target): void
|
public function collect(string $className, ?string $target): void
|
||||||
{
|
{
|
||||||
if ($this->methods && $this->path) {
|
if ($this->methods && $this->path) {
|
||||||
|
@ -21,6 +21,11 @@ use Hyperf\Di\Exception\ConflictAnnotationException;
|
|||||||
use Hyperf\Di\ReflectionManager;
|
use Hyperf\Di\ReflectionManager;
|
||||||
use Hyperf\HttpServer\Annotation\AutoController;
|
use Hyperf\HttpServer\Annotation\AutoController;
|
||||||
use Hyperf\HttpServer\Annotation\Controller;
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
|
use Hyperf\HttpServer\Annotation\DeleteMapping;
|
||||||
|
use Hyperf\HttpServer\Annotation\GetMapping;
|
||||||
|
use Hyperf\HttpServer\Annotation\PatchMapping;
|
||||||
|
use Hyperf\HttpServer\Annotation\PostMapping;
|
||||||
|
use Hyperf\HttpServer\Annotation\PutMapping;
|
||||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
use Hyperf\Utils\Str;
|
use Hyperf\Utils\Str;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
@ -128,8 +133,17 @@ class DispatcherFactory
|
|||||||
|
|
||||||
$router->addGroup($prefix, function ($router) use ($className, $methodMetadata) {
|
$router->addGroup($prefix, function ($router) use ($className, $methodMetadata) {
|
||||||
foreach ($methodMetadata as $method => $values) {
|
foreach ($methodMetadata as $method => $values) {
|
||||||
if (isset($values[RequestMapping::class])) {
|
$mappingAnnotations = [
|
||||||
$item = $values[RequestMapping::class];
|
RequestMapping::class,
|
||||||
|
GetMapping::class,
|
||||||
|
PostMapping::class,
|
||||||
|
PutMapping::class,
|
||||||
|
PatchMapping::class,
|
||||||
|
DeleteMapping::class,
|
||||||
|
];
|
||||||
|
foreach ($mappingAnnotations as $mappingAnnotation) {
|
||||||
|
if (isset($values[$mappingAnnotation])) {
|
||||||
|
$item = $values[$mappingAnnotation];
|
||||||
if ($item['path'][0] !== '/') {
|
if ($item['path'][0] !== '/') {
|
||||||
$item['path'] = '/' . $item['path'];
|
$item['path'] = '/' . $item['path'];
|
||||||
}
|
}
|
||||||
@ -139,6 +153,7 @@ class DispatcherFactory
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ abstract class Pool implements PoolInterface
|
|||||||
*/
|
*/
|
||||||
protected $option;
|
protected $option;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
protected $currentConnections = 0;
|
protected $currentConnections = 0;
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
@ -77,9 +80,6 @@ abstract class Pool implements PoolInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getCurrentConnections(): int
|
public function getCurrentConnections(): int
|
||||||
{
|
{
|
||||||
return $this->currentConnections;
|
return $this->currentConnections;
|
||||||
|
@ -101,17 +101,11 @@ class PoolOption implements PoolOptionInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function getWaitTimeout(): float
|
public function getWaitTimeout(): float
|
||||||
{
|
{
|
||||||
return $this->waitTimeout;
|
return $this->waitTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param float $waitTimeout
|
|
||||||
*/
|
|
||||||
public function setWaitTimeout(float $waitTimeout): self
|
public function setWaitTimeout(float $waitTimeout): self
|
||||||
{
|
{
|
||||||
$this->waitTimeout = $waitTimeout;
|
$this->waitTimeout = $waitTimeout;
|
||||||
|
Loading…
Reference in New Issue
Block a user