From d01c3424097f2ec4231f60a9eeb9eb159b2ea1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=A3=E8=A8=80=E5=B0=B1=E6=98=AFSiam?= <59419979@qq.com> Date: Sun, 8 Oct 2023 16:49:13 +0800 Subject: [PATCH] Set ClosureProcess default enable start. (#67) --- .php-cs-fixer.php | 1 + README-CN.md | 6 +++++- README.md | 6 +++++- example/index.php | 1 + src/App.php | 1 + src/BoundInterface.php | 1 + src/ConfigProvider.php | 1 + src/Constant.php | 1 + src/ContainerProxy.php | 1 + src/Factory/AppFactory.php | 1 + src/Factory/ClosureCommand.php | 1 + src/Factory/ClosureProcess.php | 3 ++- src/Factory/CommandFactory.php | 1 + src/Factory/CronFactory.php | 1 + src/Factory/ExceptionHandlerFactory.php | 1 + src/Factory/MiddlewareFactory.php | 1 + src/Factory/ParameterParser.php | 1 + src/Factory/ProcessFactory.php | 1 + src/Preset/Default.php | 1 + src/Preset/Preset.php | 1 + src/Preset/SwooleCoroutine.php | 1 + src/Preset/Swow.php | 1 + tests/Cases/Http/ContainerTest.php | 1 + tests/Cases/Http/RouteTest.php | 1 + tests/HttpTestCase.php | 1 + 25 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index f10c2a6..78541f6 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -85,6 +85,7 @@ 'single_quote' => true, 'standardize_not_equals' => true, 'multiline_comment_opening_closing' => true, + 'single_line_empty_body' => false, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/README-CN.md b/README-CN.md index bc77b83..23b2372 100644 --- a/README-CN.md +++ b/README-CN.md @@ -223,10 +223,14 @@ $app = AppFactory::create(); $app->addProcess(function(){ while (true) { sleep(1); - $this->get(StdoutLoggerInterface::class)->info('Processing...'); + $this->container->get(StdoutLoggerInterface::class)->info('Processing...'); } })->setName('nano-process')->setNums(1); +$app->addProcess(function(){ + $this->container->get(StdoutLoggerInterface::class)->info('根据env判定是否需要启动进程...'); +})->setName('nano-process')->setNums(1)->setEnable(\Hyperf\Support\env('PROCESS_ENABLE', true)))); + $app->run(); ``` diff --git a/README.md b/README.md index 90e7cf8..18c3b19 100644 --- a/README.md +++ b/README.md @@ -214,10 +214,14 @@ $app = AppFactory::create(); $app->addProcess(function(){ while (true) { sleep(1); - $this->get(StdoutLoggerInterface::class)->info('Processing...'); + $this->container->get(StdoutLoggerInterface::class)->info('Processing...'); } })->setName('nano-process')->setNums(1); +$app->addProcess(function(){ + $this->container->get(StdoutLoggerInterface::class)->info('Determine whether the process needs to be started based on env...'); +})->setName('nano-process')->setNums(1)->setEnable(\Hyperf\Support\env('PROCESS_ENABLE', true)))); + $app->run(); ``` diff --git a/example/index.php b/example/index.php index 61e4b0f..10e12db 100644 --- a/example/index.php +++ b/example/index.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; use Exception; diff --git a/src/App.php b/src/App.php index ce680f5..485e8ff 100644 --- a/src/App.php +++ b/src/App.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; use Closure; diff --git a/src/BoundInterface.php b/src/BoundInterface.php index 5f34620..622d3a4 100644 --- a/src/BoundInterface.php +++ b/src/BoundInterface.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; interface BoundInterface diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 7516843..d9f2fc1 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; class ConfigProvider diff --git a/src/Constant.php b/src/Constant.php index 7cfa887..3c53225 100644 --- a/src/Constant.php +++ b/src/Constant.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; class Constant diff --git a/src/ContainerProxy.php b/src/ContainerProxy.php index 0331e10..8ec6637 100644 --- a/src/ContainerProxy.php +++ b/src/ContainerProxy.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; use Hyperf\Contract\ContainerInterface; diff --git a/src/Factory/AppFactory.php b/src/Factory/AppFactory.php index 07132a6..9756f32 100644 --- a/src/Factory/AppFactory.php +++ b/src/Factory/AppFactory.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Dotenv\Dotenv; diff --git a/src/Factory/ClosureCommand.php b/src/Factory/ClosureCommand.php index f66d02c..9f9a00e 100644 --- a/src/Factory/ClosureCommand.php +++ b/src/Factory/ClosureCommand.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Closure; diff --git a/src/Factory/ClosureProcess.php b/src/Factory/ClosureProcess.php index f384315..8b6e313 100644 --- a/src/Factory/ClosureProcess.php +++ b/src/Factory/ClosureProcess.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Closure; @@ -22,7 +23,7 @@ class ClosureProcess extends AbstractProcess /** * @var bool|callable */ - private $enable; + private $enable = true; public function __construct(ContainerInterface $container, private Closure $closure) { diff --git a/src/Factory/CommandFactory.php b/src/Factory/CommandFactory.php index f70af9f..70ff8cf 100644 --- a/src/Factory/CommandFactory.php +++ b/src/Factory/CommandFactory.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Closure; diff --git a/src/Factory/CronFactory.php b/src/Factory/CronFactory.php index a96996d..28db5b9 100644 --- a/src/Factory/CronFactory.php +++ b/src/Factory/CronFactory.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Hyperf\Contract\ContainerInterface; diff --git a/src/Factory/ExceptionHandlerFactory.php b/src/Factory/ExceptionHandlerFactory.php index 87691f3..171a914 100644 --- a/src/Factory/ExceptionHandlerFactory.php +++ b/src/Factory/ExceptionHandlerFactory.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Closure; diff --git a/src/Factory/MiddlewareFactory.php b/src/Factory/MiddlewareFactory.php index 3b27805..27b9286 100644 --- a/src/Factory/MiddlewareFactory.php +++ b/src/Factory/MiddlewareFactory.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Closure; diff --git a/src/Factory/ParameterParser.php b/src/Factory/ParameterParser.php index bba6176..783db5e 100644 --- a/src/Factory/ParameterParser.php +++ b/src/Factory/ParameterParser.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Closure; diff --git a/src/Factory/ProcessFactory.php b/src/Factory/ProcessFactory.php index 909e8a4..814fab4 100644 --- a/src/Factory/ProcessFactory.php +++ b/src/Factory/ProcessFactory.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Factory; use Closure; diff --git a/src/Preset/Default.php b/src/Preset/Default.php index e63a382..2414eff 100644 --- a/src/Preset/Default.php +++ b/src/Preset/Default.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; use Hyperf\Server\Event; diff --git a/src/Preset/Preset.php b/src/Preset/Preset.php index b3eacb6..2af0457 100644 --- a/src/Preset/Preset.php +++ b/src/Preset/Preset.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano\Preset; /** diff --git a/src/Preset/SwooleCoroutine.php b/src/Preset/SwooleCoroutine.php index 92dad46..ec803b7 100644 --- a/src/Preset/SwooleCoroutine.php +++ b/src/Preset/SwooleCoroutine.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; use Hyperf\Server\CoroutineServer; diff --git a/src/Preset/Swow.php b/src/Preset/Swow.php index c21ca84..3165512 100644 --- a/src/Preset/Swow.php +++ b/src/Preset/Swow.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace Hyperf\Nano; use Hyperf\HttpServer\Server as HttpServer; diff --git a/tests/Cases/Http/ContainerTest.php b/tests/Cases/Http/ContainerTest.php index 6851332..99aee8a 100644 --- a/tests/Cases/Http/ContainerTest.php +++ b/tests/Cases/Http/ContainerTest.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace HyperfTest\Nano\Cases\Http; use Hyperf\Di\Container; diff --git a/tests/Cases/Http/RouteTest.php b/tests/Cases/Http/RouteTest.php index 31a0772..0f1b153 100644 --- a/tests/Cases/Http/RouteTest.php +++ b/tests/Cases/Http/RouteTest.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace HyperfTest\Nano\Cases\Http; use GuzzleHttp\RequestOptions; diff --git a/tests/HttpTestCase.php b/tests/HttpTestCase.php index bfc632f..a01be46 100644 --- a/tests/HttpTestCase.php +++ b/tests/HttpTestCase.php @@ -9,6 +9,7 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/nano/blob/master/LICENSE */ + namespace HyperfTest\Nano; use GuzzleHttp\Client;