From d619fa703381e774d6819f1213a3fc6cf46a5263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Tue, 25 Jun 2019 20:53:28 +0800 Subject: [PATCH] Removed framework dependency of di, command and dispatcher. --- src/framework/composer.json | 18 +++++++++--------- src/framework/src/ApplicationFactory.php | 8 ++++++-- .../src/Bootstrap/WorkerStartCallback.php | 10 +--------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/framework/composer.json b/src/framework/composer.json index aaddde846..66afd7bcf 100644 --- a/src/framework/composer.json +++ b/src/framework/composer.json @@ -16,23 +16,23 @@ "php": ">=7.2", "ext-swoole": ">=4.3", "fig/http-message-util": "^1.1.2", + "hyperf/contract": "~1.0.0", + "hyperf/utils": "~1.0.0", "psr/container": "^1.0", "psr/event-dispatcher": "^1.0", - "psr/log": "^1.0", - "hyperf/command": "~1.0.0", - "hyperf/contract": "~1.0.0", - "hyperf/di": "~1.0.0", - "hyperf/dispatcher": "~1.0.0", - "hyperf/utils": "~1.0.0" + "psr/log": "^1.0" }, "require-dev": { + "doctrine/common": "@stable", + "friendsofphp/php-cs-fixer": "^2.9", "malukenho/docheader": "^0.1.6", "mockery/mockery": "^1.0", - "phpunit/phpunit": "^7.0.0", - "friendsofphp/php-cs-fixer": "^2.9", - "doctrine/common": "@stable" + "phpunit/phpunit": "^7.0.0" }, "suggest": { + "hyperf/di": "Required to use Command annotation.", + "hyperf/dispatcher": "Required to use BootApplication event.", + "hyperf/command": "Required to use Command annotation." }, "autoload": { "files": [ diff --git a/src/framework/src/ApplicationFactory.php b/src/framework/src/ApplicationFactory.php index 44fc8dd41..b4bec362f 100644 --- a/src/framework/src/ApplicationFactory.php +++ b/src/framework/src/ApplicationFactory.php @@ -32,8 +32,12 @@ class ApplicationFactory $config = $container->get(ConfigInterface::class); $commands = $config->get('commands', []); // Append commands that defined by annotation. - $annotationCommands = AnnotationCollector::getClassByAnnotation(Command::class); - $annotationCommands = array_keys($annotationCommands); + $annotationCommands = []; + if (class_exists(AnnotationCollector::class) && class_exists(Command::class)) { + $annotationCommands = AnnotationCollector::getClassByAnnotation(Command::class); + $annotationCommands = array_keys($annotationCommands); + } + $commands = array_unique(array_merge($commands, $annotationCommands)); $application = new Application(); foreach ($commands as $command) { diff --git a/src/framework/src/Bootstrap/WorkerStartCallback.php b/src/framework/src/Bootstrap/WorkerStartCallback.php index 238de48f0..3b03f0bee 100644 --- a/src/framework/src/Bootstrap/WorkerStartCallback.php +++ b/src/framework/src/Bootstrap/WorkerStartCallback.php @@ -13,22 +13,15 @@ declare(strict_types=1); namespace Hyperf\Framework\Bootstrap; use Hyperf\Contract\StdoutLoggerInterface; -use Hyperf\Di\Container; use Hyperf\Framework\Event\AfterWorkerStart; use Hyperf\Framework\Event\BeforeWorkerStart; use Hyperf\Framework\Event\MainWorkerStart; use Hyperf\Framework\Event\OtherWorkerStart; -use Psr\Container\ContainerInterface; use Psr\EventDispatcher\EventDispatcherInterface; use Swoole\Server as SwooleServer; class WorkerStartCallback { - /** - * @var Container - */ - private $container; - /** * @var StdoutLoggerInterface */ @@ -39,9 +32,8 @@ class WorkerStartCallback */ private $eventDispatcher; - public function __construct(ContainerInterface $container, StdoutLoggerInterface $logger, EventDispatcherInterface $eventDispatcher) + public function __construct(StdoutLoggerInterface $logger, EventDispatcherInterface $eventDispatcher) { - $this->container = $container; $this->logger = $logger; $this->eventDispatcher = $eventDispatcher; }