mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +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
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function collect(string $className, ?string $target): void
|
||||
{
|
||||
// @TODO Add order property.
|
||||
|
@ -31,12 +31,13 @@ class Inject extends AbstractAnnotation
|
||||
$this->docReader = new PhpDocReader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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));
|
||||
}
|
||||
if (isset($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)
|
||||
{
|
||||
$this->value = $value;
|
||||
parent::__construct($value);
|
||||
if (isset($value['methods'])) {
|
||||
// Explode a string to a array
|
||||
$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
|
||||
{
|
||||
if ($this->methods && $this->path) {
|
||||
|
@ -21,6 +21,11 @@ use Hyperf\Di\Exception\ConflictAnnotationException;
|
||||
use Hyperf\Di\ReflectionManager;
|
||||
use Hyperf\HttpServer\Annotation\AutoController;
|
||||
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\Utils\Str;
|
||||
use Psr\Container\ContainerInterface;
|
||||
@ -128,15 +133,25 @@ class DispatcherFactory
|
||||
|
||||
$router->addGroup($prefix, function ($router) use ($className, $methodMetadata) {
|
||||
foreach ($methodMetadata as $method => $values) {
|
||||
if (isset($values[RequestMapping::class])) {
|
||||
$item = $values[RequestMapping::class];
|
||||
if ($item['path'][0] !== '/') {
|
||||
$item['path'] = '/' . $item['path'];
|
||||
$mappingAnnotations = [
|
||||
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] !== '/') {
|
||||
$item['path'] = '/' . $item['path'];
|
||||
}
|
||||
$router->addRoute($item['methods'], $item['path'], [
|
||||
$className,
|
||||
$method
|
||||
]);
|
||||
}
|
||||
$router->addRoute($item['methods'], $item['path'], [
|
||||
$className,
|
||||
$method
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -39,6 +39,9 @@ abstract class Pool implements PoolInterface
|
||||
*/
|
||||
protected $option;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $currentConnections = 0;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
@ -77,9 +80,6 @@ abstract class Pool implements PoolInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCurrentConnections(): int
|
||||
{
|
||||
return $this->currentConnections;
|
||||
|
@ -101,17 +101,11 @@ class PoolOption implements PoolOptionInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getWaitTimeout(): float
|
||||
{
|
||||
return $this->waitTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $waitTimeout
|
||||
*/
|
||||
public function setWaitTimeout(float $waitTimeout): self
|
||||
{
|
||||
$this->waitTimeout = $waitTimeout;
|
||||
|
Loading…
Reference in New Issue
Block a user