Merge pull request #614 from huangzhhui/config-provider

Changed the structure of config provider
This commit is contained in:
黄朝晖 2019-09-26 10:57:26 +08:00 committed by GitHub
commit aebefbcff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 272 additions and 288 deletions

View File

@ -40,6 +40,29 @@ return ApplicationContext::setContainer($container);
- [#486](https://github.com/hyperf-cloud/hyperf/pull/486) Changed `getParsedBody` of Request is available to return JSON formatted data normally.
- [#523](https://github.com/hyperf-cloud/hyperf/pull/523) The command `db:model` will generate the singular class name of an plural table as default.
- [#614](https://github.com/hyperf-cloud/hyperf/pull/614) Changed the structure of config provider, also moved `config/dependencies.php` to `config/autoload/dependencies.php`, also you could place `dependencies` into config/config.php.
Changed the structure of config provider:
Before:
```php
'scan' => [
'paths' => [
__DIR__,
],
'collectors' => [],
],
```
Now:
```php
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
'collectors' => [],
],
],
```
## Deleted

View File

@ -25,11 +25,11 @@ class ConfigProvider
Packer::class => JsonPacker::class,
Consumer::class => ConsumerFactory::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -22,15 +22,15 @@ class ConfigProvider
'dependencies' => [
CacheInterface::class => Cache::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
'collectors' => [
CacheListenerCollector::class,
]
],
'collectors' => [
CacheListenerCollector::class,
]
],
'publish' => [
[

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -20,9 +20,11 @@ class ConfigProvider
'dependencies' => [
ClientInterface::class => Client::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -20,9 +20,11 @@ class ConfigProvider
'dependencies' => [
ClientInterface::class => ClientFactory::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -20,11 +20,12 @@ class ConfigProvider
'dependencies' => [
ClientInterface::class => Client::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -22,9 +22,11 @@ class ConfigProvider
'dependencies' => [
ConfigInterface::class => ConfigFactory::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -49,7 +49,7 @@ class ProviderConfig
protected static function loadProviders(array $providers): array
{
$providerConfigs = [];
foreach ($providers ?? [] as $provider) {
foreach ($providers as $provider) {
if (is_string($provider) && class_exists($provider) && method_exists($provider, '__invoke')) {
$providerConfigs[] = (new $provider())();
}

View File

@ -100,7 +100,7 @@ class ProviderConfigTest extends TestCase
$dependencies = $res['dependencies'];
$commands = $res['commands'];
$scanPaths = $res['scan']['paths'];
$scanPaths = $res['annotations']['scan']['paths'];
$publish = $res['publish'];
$listeners = $res['listeners'];

View File

@ -17,12 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'scan' => [
'paths' => [],
'collectors' => [
ConstantsCollector::class,
'annotations' => [
'scan' => [
'collectors' => [
ConstantsCollector::class,
],
],
],
];

View File

@ -17,12 +17,6 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'scan' => [
'paths' => [
],
],
'publish' => [
[
'id' => 'config',

View File

@ -29,9 +29,11 @@ class ConfigProvider
CrontabRegisterListener::class,
OnPipeMessageListener::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -50,9 +50,11 @@ class ConfigProvider
RollbackCommand::class,
StatusCommand::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke()
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -31,13 +31,15 @@ class ConfigProvider
'listeners' => [
BootApplicationListener::class,
],
'scan' => [
'paths' => [
__DIR__,
],
'collectors' => [
AnnotationCollector::class,
AspectCollector::class,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
'collectors' => [
AnnotationCollector::class,
AspectCollector::class,
],
],
],
];

View File

@ -48,22 +48,33 @@ class DefinitionSourceFactory
}
$serverDependencies = $configFromProviders['dependencies'] ?? [];
if (file_exists($configDir . '/dependencies.php')) {
$definitions = include $configDir . '/dependencies.php';
if (file_exists($configDir . '/autoload/dependencies.php')) {
$definitions = include $configDir . '/autoload/dependencies.php';
$serverDependencies = array_replace($serverDependencies, $definitions['dependencies'] ?? []);
}
$scanDirs = $configFromProviders['scan']['paths'] ?? [];
$ignoreAnnotations = [];
$collectors = $configFromProviders['scan']['collectors'] ?? [];
$scanDirs = $configFromProviders['annotations']['scan']['paths'] ?? [];
$ignoreAnnotations = $configFromProviders['annotations']['scan']['ignore_annotations'] ?? [];
$collectors = $configFromProviders['annotations']['scan']['collectors'] ?? [];
// Load the config/autoload/annotations.php and merge the config
if (file_exists($configDir . '/autoload/annotations.php')) {
$annotations = include $configDir . '/autoload/annotations.php';
$scanDirs = array_merge($scanDirs, $annotations['scan']['paths'] ?? []);
$ignoreAnnotations = $annotations['scan']['ignore_annotations'] ?? [];
$ignoreAnnotations = array_merge($ignoreAnnotations, $annotations['scan']['ignore_annotations'] ?? []);
$collectors = array_merge($collectors, $annotations['scan']['collectors'] ?? []);
}
// Load the config/config.php and merge the config
if (file_exists($configDir . '/config.php')) {
$configContent = include $configDir . '/config.php';
if (isset($configContent['annotations'])) {
$scanDirs = array_merge($scanDirs, $configContent['annotations']['scan']['paths'] ?? []);
$ignoreAnnotations = array_merge($ignoreAnnotations, $configContent['annotations']['scan']['ignore_annotations'] ?? []);
$collectors = array_merge($collectors, $configContent['annotations']['scan']['collectors'] ?? []);
}
}
$scanConfig = new ScanConfig($scanDirs, $ignoreAnnotations, $collectors);
return new DefinitionSource($serverDependencies, $scanConfig, $this->enableCache);

View File

@ -17,11 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -20,11 +20,11 @@ class ConfigProvider
'dependencies' => [
KVInterface::class => KVFactory::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -24,9 +24,11 @@ class ConfigProvider
ListenerProviderInterface::class => ListenerProviderFactory::class,
EventDispatcherInterface::class => EventDispatcherFactory::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -32,9 +32,11 @@ class ConfigProviderTest extends TestCase
ListenerProviderInterface::class => ListenerProviderFactory::class,
EventDispatcherInterface::class => EventDispatcherFactory::class,
],
'scan' => [
'paths' => [
str_replace('/tests', '/src', __DIR__),
'annotations' => [
'scan' => [
'paths' => [
str_replace('/tests', '/src', __DIR__),
],
],
],
], (new ConfigProvider())());

View File

@ -23,11 +23,11 @@ class ConfigProvider
'dependencies' => [
FormatterInterface::class => DefaultFormatter::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -25,9 +25,11 @@ class ConfigProvider
ApplicationInterface::class => ApplicationFactory::class,
StdoutLoggerInterface::class => StdoutLogger::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -39,9 +39,11 @@ class ConfigProvider
AuthorizationServiceInterface::class => FailAuthorizationService::class,
NamingStrategyInterface::class => NamingStrategy::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -16,13 +16,6 @@ class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => [
],
'scan' => [
'paths' => [
],
],
];
return [];
}
}

View File

@ -17,11 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -26,11 +26,11 @@ class ConfigProvider
ServerRequestInterface::class => Request::class,
ResponseInterface::class => Response::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -24,8 +24,6 @@ class ConfigProvider
'dependencies' => [
DataFormatter::class => DataFormatterFactory::class,
],
'commands' => [
],
'listeners' => [
RegisterProtocolListener::class,
value(function () {
@ -35,9 +33,11 @@ class ConfigProvider
return null;
}),
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -16,15 +16,6 @@ class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
],
'publish' => [
],
];
return [];
}
}

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -26,13 +26,11 @@ class ConfigProviderTest extends TestCase
$dir = str_replace('/tests', '/src', __DIR__);
$this->assertSame([
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
$dir,
'annotations' => [
'scan' => [
'paths' => [
$dir,
],
],
],
'publish' => [

View File

@ -17,10 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -19,16 +19,14 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
],
'collectors' => [
ListenerCollector::class,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
'collectors' => [
ListenerCollector::class,
],
],
],
];

View File

@ -25,15 +25,10 @@ class ConfigProvider
PaginatorInterface::class => Paginator::class,
LengthAwarePaginatorInterface::class => LengthAwarePaginator::class,
],
'commands' => [
],
'listeners' => [
PageResolverListener::class,
],
'scan' => [
'paths' => [
],
],
];
}
}

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -20,11 +20,11 @@ class ConfigProvider
'dependencies' => [
\Redis::class => Redis::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -19,16 +19,14 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'listeners' => [
AddConsumerDefinitionListener::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Hyperf\RpcServer;
use Hyperf\Dispatcher\AbstractDispatcher;
use Hyperf\Dispatcher\HttpDispatcher;
use Hyperf\Dispatcher\HttpRequestHandler;
use Psr\Container\ContainerInterface;

View File

@ -23,14 +23,14 @@ class ConfigProvider
'dependencies' => [
SwooleServer::class => SwooleServerFactory::class,
],
'commands' => [
],
'listeners' => [
InitProcessTitleListener::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -23,11 +23,11 @@ class ConfigProvider
'dependencies' => [
ConsulAgent::class => ConsulAgentFactory::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -19,15 +19,9 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
GenCommand::class,
],
'scan' => [
],
'publish' => [
],
];
}
}

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -16,15 +16,6 @@ class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
],
],
];
return [];
}
}

View File

@ -17,18 +17,16 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'listeners' => [
Listener\InitServerListener::class,
Listener\OnFinishListener::class,
Listener\OnTaskListener::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -25,11 +25,11 @@ class ConfigProvider
SwitchManager::class => SwitchManagerFactory::class,
Client::class => Client::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -24,9 +24,11 @@ class ConfigProvider
TranslatorLoaderInterface::class => FileLoaderFactory::class,
TranslatorInterface::class => TranslatorFactory::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -20,11 +20,11 @@ class ConfigProvider
'dependencies' => [
RenderInterface::class => Render::class,
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
'publish' => [

View File

@ -17,13 +17,11 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];

View File

@ -17,15 +17,15 @@ class ConfigProvider
public function __invoke(): array
{
return [
'dependencies' => [
],
'listeners' => [
Listener\InitSenderListener::class,
Listener\OnPipeMessageListener::class,
],
'scan' => [
'paths' => [
__DIR__,
'annotations' => [
'scan' => [
'paths' => [
__DIR__,
],
],
],
];