Skip to content

Commit 70aad1b

Browse files
committed
add LaravelS::getCustomProcesses()
1 parent f818e6f commit 70aad1b

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

README-CN.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,18 @@
110110

111111
| 依赖 | 说明 |
112112
| -------- | -------- |
113-
| [PHP](https://www.php.net/) | `>= 5.5.9` `推荐PHP7+` |
114-
| [Swoole](https://www.swoole.com/) | `>= 1.7.19` `从2.0.12开始不再支持PHP5` `推荐4.5.0+` |
115-
| [Laravel](https://laravel.com/)/[Lumen](https://lumen.laravel.com/) | `>= 5.1` `推荐8.0+` |
113+
| [PHP](https://www.php.net/) | `>= 5.5.9` `推荐7.4|8.2` |
114+
| [Swoole](https://www.swoole.com/) | `>= 1.7.19` `从2.0.12开始不再支持PHP5` `推荐4.5.11|5.1.1` |
115+
| [Laravel](https://laravel.com/)/[Lumen](https://lumen.laravel.com/) | `>= 5.1` `推荐10` |
116116

117117
## 安装
118118

119119
1.通过[Composer](https://getcomposer.org/)安装([packagist](https://packagist.org/packages/hhxsv5/laravel-s))。有可能找不到`3.0`版本,解决方案移步[#81](https://github.com/hhxsv5/laravel-s/issues/81)
120120
```bash
121-
composer require "hhxsv5/laravel-s:~3.7.0" -vvv
121+
# PHP >=5.5.9,<=7.4.33
122+
composer require "hhxsv5/laravel-s:~3.7.0"
123+
# PHP >=8.2.0
124+
composer require "hhxsv5/laravel-s:~3.8.0"
122125
# 确保你的composer.lock文件是在版本控制中
123126
```
124127

@@ -1117,8 +1120,9 @@ class WebSocketService implements WebSocketHandlerInterface
11171120
// app/Http/Controllers/TestController.php
11181121
public function testProcessWrite()
11191122
{
1120-
/**@var \Swoole\Process $process */
1121-
$process = app('swoole')->customProcesses['test'];
1123+
/**@var \Swoole\Process[] $process */
1124+
$customProcesses = \Hhxsv5\LaravelS\LaravelS::getCustomProcesses();
1125+
$process = $customProcesses['test'];
11221126
$process->write('TestController: write data' . time());
11231127
var_dump($process->read());
11241128
}

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,18 @@ Table of Contents
106106

107107
| Dependency | Requirement |
108108
| -------- | -------- |
109-
| [PHP](https://secure.php.net/) | `>= 5.5.9` `Recommend PHP7+` |
110-
| [Swoole](https://www.swoole.co.uk/) | `>= 1.7.19` `No longer support PHP5 since 2.0.12` `Recommend 4.5.0+` |
111-
| [Laravel](https://laravel.com/)/[Lumen](https://lumen.laravel.com/) | `>= 5.1` `Recommend 8.0+` |
109+
| [PHP](https://secure.php.net/) | `>= 5.5.9` `Recommend 7.4|8.2` |
110+
| [Swoole](https://www.swoole.co.uk/) | `>= 1.7.19` `No longer support PHP5 since 2.0.12` `Recommend 4.5.11|5.1.1` |
111+
| [Laravel](https://laravel.com/)/[Lumen](https://lumen.laravel.com/) | `>= 5.1` `Recommend 10` |
112112

113113
## Install
114114

115115
1.Require package via [Composer](https://getcomposer.org/)([packagist](https://packagist.org/packages/hhxsv5/laravel-s)).
116116
```bash
117-
composer require "hhxsv5/laravel-s:~3.7.0" -vvv
117+
# PHP >=5.5.9,<=7.4.33
118+
composer require "hhxsv5/laravel-s:~3.7.0"
119+
# PHP >=8.2.0
120+
composer require "hhxsv5/laravel-s:~3.8.0"
118121
# Make sure that your composer.lock file is under the VCS
119122
```
120123

@@ -1104,8 +1107,9 @@ To make our main server support more protocols not just Http and WebSocket, we b
11041107
// app/Http/Controllers/TestController.php
11051108
public function testProcessWrite()
11061109
{
1107-
/**@var \Swoole\Process $process */
1108-
$process = app('swoole')->customProcesses['test'];
1110+
/**@var \Swoole\Process[] $process */
1111+
$customProcesses = \Hhxsv5\LaravelS\LaravelS::getCustomProcesses();
1112+
$process = $customProcesses['test'];
11091113
$process->write('TestController: write data' . time());
11101114
var_dump($process->read());
11111115
}

src/LaravelS.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Swoole\Http\Request as SwooleRequest;
2323
use Swoole\Http\Response as SwooleResponse;
2424
use Swoole\Http\Server as HttpServer;
25+
use Swoole\Process;
2526
use Swoole\Server\Port;
2627
use Symfony\Component\Console\Style\OutputStyle;
2728
use Symfony\Component\HttpFoundation\BinaryFileResponse;
@@ -40,29 +41,32 @@ class LaravelS extends Server
4041
use InotifyTrait, LaravelTrait, LogTrait, ProcessTitleTrait, TimerTrait, CustomProcessTrait;
4142

4243
/**@var array */
43-
protected $laravelConf;
44+
protected array $laravelConf;
4445

4546
/**@var Laravel */
46-
protected $laravel;
47+
protected Laravel $laravel;
48+
49+
/**@var Process[] */
50+
protected static array $customProcesses = [];
4751

4852
public function __construct(array $svrConf, array $laravelConf)
4953
{
5054
parent::__construct($svrConf);
5155
$this->laravelConf = $laravelConf;
5256

53-
$timerConf = isset($this->conf['timer']) ? $this->conf['timer'] : [];
57+
$timerConf = $this->conf['timer'] ?? [];
5458
$timerConf['process_prefix'] = $svrConf['process_prefix'];
5559
$this->addTimerProcess($this->swoole, $timerConf, $this->laravelConf);
5660

57-
$inotifyConf = isset($this->conf['inotify_reload']) ? $this->conf['inotify_reload'] : [];
61+
$inotifyConf = $this->conf['inotify_reload'] ?? [];
5862
if (!isset($inotifyConf['watch_path'])) {
5963
$inotifyConf['watch_path'] = $this->laravelConf['root_path'];
6064
}
6165
$inotifyConf['process_prefix'] = $svrConf['process_prefix'];
6266
$this->addInotifyProcess($this->swoole, $inotifyConf, $this->laravelConf);
6367

64-
$processes = isset($this->conf['processes']) ? $this->conf['processes'] : [];
65-
$this->addCustomProcesses($this->swoole, $svrConf['process_prefix'], $processes, $this->laravelConf);
68+
$processes = $this->conf['processes'] ?? [];
69+
static::$customProcesses = $this->addCustomProcesses($this->swoole, $svrConf['process_prefix'], $processes, $this->laravelConf);
6670

6771
// Fire ServerStart event
6872
if (isset($this->conf['event_handlers']['ServerStart'])) {
@@ -71,6 +75,11 @@ public function __construct(array $svrConf, array $laravelConf)
7175
}
7276
}
7377

78+
public static function getCustomProcesses(): array
79+
{
80+
return static::$customProcesses;
81+
}
82+
7483
protected function beforeWebSocketHandShake(SwooleRequest $request)
7584
{
7685
// Start Laravel's lifetime, then support session ...middleware.

src/Swoole/Process/CustomProcessTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function addCustomProcesses(Server $swoole, $processPrefix, array $proces
1616
unlink($pidfile);
1717
}
1818

19-
/**@var []CustomProcessInterface $processList */
19+
/**@var []Process $processList */
2020
$processList = [];
2121
foreach ($processes as $name => $item) {
2222
if (empty($item['class'])) {

0 commit comments

Comments
 (0)