Added ide-helper component (#3714)

This commit is contained in:
李铭昕 2021-06-20 10:18:28 +08:00 committed by GitHub
parent 4a89d40f3b
commit a280656acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 1588 additions and 84 deletions

View File

@ -46,6 +46,7 @@
- [#3679](https://github.com/hyperf/hyperf/pull/3679) Added Nacos SDK component.
- [#3712](https://github.com/hyperf/hyperf/pull/3712) The input parameters of `InstanceProvider::update()` are modified to make it more friendly.
- [#3698](https://github.com/hyperf/hyperf/pull/3698) Support PHP8 Attribute which can replace doctrine annotations.
- [#3714](https://github.com/hyperf/hyperf/pull/3714) Added ide-helper component.
## Optimized

19
bin/generate-ide-helper Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\IDEHelper\AnnotationGenerator;
require_once 'vendor/autoload.php';
$generate = new AnnotationGenerator();
$generate->generate();

View File

@ -316,6 +316,7 @@
"HyperfTest\\Watcher\\": "src/watcher/tests/",
"HyperfTest\\WebSocketClient\\": "src/websocket-client/tests/",
"HyperfTest\\WebSocketServer\\": "src/websocket-server/tests/",
"Hyperf\\IDEHelper\\": "src/ide-helper/src/",
"Routeguide\\": "src/grpc-client/tests/Routeguide/"
}
},

View File

@ -119,7 +119,7 @@ class IndexController
}
}
```
> 注意: 使用`PHP8`的`Attributes`语法时, 应简化为`#[Middlewares(FooMiddleware::class, BarMiddleware::class)]`这种格式, 下同。
> 注意: 使用 `PHP8` 的`Attributes`语法时, 应简化为`#[Middlewares(FooMiddleware::class, BarMiddleware::class)]`这种格式, 下同。
#### 定义方法级别的中间件

View File

@ -19,6 +19,7 @@ parameters:
- %currentWorkingDirectory%/src/graphql/*
- %currentWorkingDirectory%/src/grpc/*
- %currentWorkingDirectory%/src/grpc-server/*
- %currentWorkingDirectory%/src/ide-helper/*
- %currentWorkingDirectory%/src/swagger/*
- %currentWorkingDirectory%/src/tracer/*
- %currentWorkingDirectory%/src/validation/*

View File

@ -1,42 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Amqp\Stub;
use Hyperf\Amqp\Connection\Socket;
use Hyperf\Utils\Context;
use Hyperf\Utils\Str;
use Mockery;
use Swoole\Coroutine\Channel;
use Swoole\Coroutine\Client;
class SocketStub extends Socket
{
public function connect()
{
$sock = Mockery::mock(Client::class);
$sock->connected = true;
$sock->shouldReceive('send')->andReturnUsing(function ($data) {
Context::set('test.amqp.send.data', $data);
});
$sock->shouldReceive('recv')->andReturnUsing(function ($timeout) {
return Str::random(1);
});
$this->channel = new Channel(1);
$this->channel->push($sock);
$this->connected = true;
$this->addHeartbeat();
$this->heartbeat();
}
}

View File

@ -1,40 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Amqp\Stub;
use Hyperf\Amqp\Connection\Socket;
use Swoole\Coroutine\Channel;
class SocketWithoutIOStub extends Socket
{
public $connectCount = 0;
public function __construct(bool $connected, string $host, int $port, float $timeout, int $heartbeat)
{
parent::__construct($host, $port, $timeout, $heartbeat);
$this->connected = $connected;
}
public function connect()
{
$this->channel = new Channel(1);
$this->waitTimeout = 0.1;
++$this->connectCount;
$this->addHeartbeat();
}
public function getConnectCount(): int
{
return $this->connectCount;
}
}

2
src/ide-helper/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
/src export-ignore
/.github export-ignore

View File

@ -0,0 +1,25 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
name: Release
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

21
src/ide-helper/LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Hyperf
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,31 @@
{
"name": "hyperf/ide-helper",
"description": "IDE help files for Hyperf.",
"license": "MIT",
"keywords": [
"php",
"swoole",
"hyperf",
"ide-helper"
],
"homepage": "https://hyperf.io",
"support": {
"docs": "https://hyperf.wiki",
"issues": "https://github.com/hyperf/hyperf/issues",
"pull-request": "https://github.com/hyperf/hyperf/pulls",
"source": "https://github.com/hyperf/hyperf"
},
"autoload-dev": {
"psr-4": {
"Hyperf\\IDEHelper\\": "src/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Amqp\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Consumer extends AbstractAnnotation
{
public function __construct($exchange, $routingKey, $queue, $name, $nums, $enable, $maxConsumption)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Amqp\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Producer extends AbstractAnnotation
{
public function __construct($exchange, $routingKey)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\AsyncQueue\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class AsyncQueueMessage extends AbstractAnnotation
{
public function __construct($pool, $delay, $maxAttempts)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Cache\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class CacheEvict extends AbstractAnnotation
{
public function __construct($prefix, $value, $all, $group, $collect)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Cache\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class CachePut extends AbstractAnnotation
{
public function __construct($prefix, $value, $ttl, $offset, $group)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Cache\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class Cacheable extends AbstractAnnotation
{
public function __construct($prefix, $value, $ttl, $listener, $offset, $group, $collect)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Cache\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class FailCache extends AbstractAnnotation
{
public function __construct($prefix, $value, $ttl, $listener, $group)
{
}
}

View File

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\CircuitBreaker\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"METHOD"})
* @property float $timeout
*/
#[Attribute(Attribute::TARGET_METHOD)]
class CircuitBreaker extends AbstractAnnotation
{
public function __construct($handler, $fallback, $duration, $successCounter, $failCounter, $value)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Command\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Command extends AbstractAnnotation
{
public function __construct()
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Config\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"PROPERTY"})
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
class Value extends AbstractAnnotation
{
public function __construct($key)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Constants\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Constants extends AbstractAnnotation
{
public function __construct()
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Crontab\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class Crontab extends AbstractAnnotation
{
public function __construct($name, $type, $rule, $singleton, $mutexPool, $mutexExpires, $onOneServer, $callback, $memo, $enable)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\DbConnection\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class Transactional extends AbstractAnnotation
{
public function __construct($connection, $attempts)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Di\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Aspect extends AbstractAnnotation
{
public function __construct($classes, $annotations, $priority)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Di\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"ALL"})
*/
#[Attribute]
class Debug extends AbstractAnnotation
{
public function __construct()
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Di\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"PROPERTY"})
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
class Inject extends AbstractAnnotation
{
public function __construct($value, $required, $lazy)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Event\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Listener extends AbstractAnnotation
{
public function __construct($priority)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\ExceptionHandler\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class ExceptionHandler extends AbstractAnnotation
{
public function __construct($server, $priority)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class AutoController extends AbstractAnnotation
{
public function __construct($prefix, $server, $options)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Controller extends AbstractAnnotation
{
public function __construct($prefix, $server, $options)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class DeleteMapping extends Mapping
{
public function __construct($methods, $path, $options)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class GetMapping extends Mapping
{
public function __construct($methods, $path, $options)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"ALL"})
*/
#[Attribute]
class Middleware extends AbstractAnnotation
{
public function __construct($middleware)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"ALL"})
*/
#[Attribute]
class Middlewares extends AbstractAnnotation
{
public function __construct($middlewares)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class PatchMapping extends Mapping
{
public function __construct($methods, $path, $options)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class PostMapping extends Mapping
{
public function __construct($methods, $path, $options)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class PutMapping extends Mapping
{
public function __construct($methods, $path, $options)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\HttpServer\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class RequestMapping extends Mapping
{
public function __construct($methods, $path, $options)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Kafka\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Consumer extends AbstractAnnotation
{
public function __construct($pool, $topic, $groupId, $memberId, $autoCommit, $nums, $enable)
{
}
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Metric\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class Counter extends AbstractAnnotation
{
public function __construct($name)
{
}
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Metric\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class Histogram extends AbstractAnnotation
{
public function __construct($name)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\ModelListener\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class ModelListener extends AbstractAnnotation
{
public function __construct($models)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Nats\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Consumer extends AbstractAnnotation
{
public function __construct($subject, $queue, $name, $nums, $pool)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Nsq\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Consumer extends AbstractAnnotation
{
public function __construct($topic, $channel, $name, $nums, $pool)
{
}
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Process\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target("CLASS")
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Process extends AbstractAnnotation
{
public function __construct($nums, $name, $redirectStdinStdout, $pipeType, $enableCoroutine)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\RateLimit\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class RateLimit extends AbstractAnnotation
{
public function __construct($create, $consume, $capacity, $limitCallback, $key, $waitTimeout)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Retry\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class BackoffRetryFalsy extends RetryFalsy
{
public function __construct($base, $sleepStrategyClass, $retryThrowables, $retryOnResultPredicate, $policies, $maxAttempts, $retryBudget, $retryOnThrowablePredicate, $ignoreThrowables, $fallback)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Retry\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class BackoffRetryThrowable extends RetryThrowable
{
public function __construct($base, $sleepStrategyClass, $retryThrowables, $policies, $maxAttempts, $retryBudget, $retryOnThrowablePredicate, $retryOnResultPredicate, $ignoreThrowables, $fallback)
{
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Retry\Annotation;
use Attribute;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class CircuitBreaker extends AbstractRetry
{
public function __construct($policies, $sleepStrategyClass, $maxAttempts, $circuitBreakerState, $base, $retryOnThrowablePredicate, $retryOnResultPredicate, $retryThrowables, $ignoreThrowables, $fallback)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Retry\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class Retry extends AbstractRetry
{
public function __construct($policies, $sleepStrategyClass, $maxAttempts, $retryBudget, $base, $retryOnThrowablePredicate, $retryOnResultPredicate, $retryThrowables, $ignoreThrowables, $fallback)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Retry\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class RetryFalsy extends Retry
{
public function __construct($retryThrowables, $retryOnResultPredicate, $policies, $sleepStrategyClass, $maxAttempts, $retryBudget, $base, $retryOnThrowablePredicate, $ignoreThrowables, $fallback)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Retry\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target({"METHOD"})
*/
#[Attribute(Attribute::TARGET_METHOD)]
class RetryThrowable extends Retry
{
public function __construct($retryThrowables, $policies, $sleepStrategyClass, $maxAttempts, $retryBudget, $base, $retryOnThrowablePredicate, $retryOnResultPredicate, $ignoreThrowables, $fallback)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\RpcServer\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class RpcService extends AbstractAnnotation
{
public function __construct($name, $server, $protocol, $publishTo)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Signal\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class Signal extends AbstractAnnotation
{
public function __construct($priority)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\SocketIOServer\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class Event extends AbstractAnnotation
{
public function __construct($event)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\SocketIOServer\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS)]
class SocketIONamespace extends AbstractAnnotation
{
public function __construct($namespace)
{
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Task\Annotation;
use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class Task extends AbstractAnnotation
{
public function __construct($workerId, $timeout)
{
}
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Tracer\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\Target;
use Hyperf\Di\Annotation\AbstractAnnotation;
/**
* @Annotation
* @Target({"CLASS", "METHOD"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
class Trace extends AbstractAnnotation
{
public function __construct($name, $tag)
{
}
}

View File

@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\IDEHelper;
use Hyperf\IDEHelper\Visitor\AnnotationIDEVisitor;
use Hyperf\Utils\Composer;
use ReflectionClass;
class AnnotationGenerator
{
/**
* @var string
*/
protected $output;
/**
* @var Ast
*/
protected $ast;
public function __construct(?string $output = null)
{
$this->output = $output ?: __DIR__ . '/../output';
$this->ast = new Ast();
}
public function generate(): void
{
$classMap = Composer::getLoader()->getClassMap();
foreach ($classMap as $value => $path) {
if (str_starts_with($value, 'Hyperf\\')) {
try {
$reflection = new ReflectionClass($value);
$attributes = $reflection->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getName() === 'Attribute') {
$code = $this->ast->generate($reflection, file_get_contents($path), [
AnnotationIDEVisitor::class,
]);
$target = $this->output . '/' . str_replace('\\', '/', $reflection->getName());
if (! is_dir(dirname($target))) {
mkdir(dirname($target), 0777, true);
}
file_put_contents($target . '.php', $code);
}
}
} catch (\Throwable) {
}
}
}
}
}

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\IDEHelper;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\Reader;
use PhpParser\NodeTraverser;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter\Standard;
use PhpParser\PrettyPrinterAbstract;
use ReflectionClass;
class Ast
{
private Parser $parser;
private PrettyPrinterAbstract $printer;
private Reader $reader;
public function __construct()
{
$parserFactory = new ParserFactory();
$this->parser = $parserFactory->create(ParserFactory::ONLY_PHP7);
$this->printer = new Standard();
$this->reader = new AnnotationReader();
}
public function generate(ReflectionClass $reflection, string $code, array $visitors = []): string
{
$stmts = $this->parser->parse($code);
$traverser = new NodeTraverser();
$metadata = new Metadata($this->reader, $reflection);
foreach ($visitors as $string) {
$visitor = new $string($metadata);
$traverser->addVisitor($visitor);
}
$modifiedStmts = $traverser->traverse($stmts);
return $this->printer->prettyPrintFile($modifiedStmts);
}
}

View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\IDEHelper;
use Doctrine\Common\Annotations\Reader;
use ReflectionClass;
class Metadata
{
public function __construct(
public Reader $reader,
public ReflectionClass $reflection
) {
}
}

View File

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\IDEHelper\Visitor;
use Hyperf\IDEHelper\Metadata;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use ReflectionClass;
class AnnotationIDEVisitor extends NodeVisitorAbstract
{
protected ReflectionClass $reflection;
public function __construct(public Metadata $metadata)
{
$this->reflection = $this->metadata->reflection;
}
public function afterTraverse(array $nodes)
{
foreach ($nodes as $node) {
if ($node instanceof Node\Stmt\Declare_) {
continue;
}
if ($node instanceof Node\Stmt\Namespace_) {
foreach ($node->stmts as $class) {
if (! $class instanceof Node\Stmt\Class_) {
continue;
}
$properties = [];
foreach ($this->reflection->getProperties() as $property) {
$properties[] = new Node\Param(new Node\Expr\Variable($property->getName()));
}
$class->stmts = [
new Node\Stmt\ClassMethod('__construct', [
'flags' => Node\Stmt\Class_::MODIFIER_PUBLIC,
'params' => $properties,
]),
];
}
}
}
}
}

View File

@ -306,7 +306,7 @@ EOD;
$cache = file_get_contents($cacheFile);
$scanCache = unserialize($cache);
$proxies = [];
foreach ($scanCache[1] as $class => $path){
foreach ($scanCache[1] as $class => $path) {
$proxies[$class] = $this->getPathLocalToBase($path);
}
$scanCache[1] = $proxies;