Skip to content

Commit b399e85

Browse files
Added ProcScanHandler which used to run application in windows.
Co-authored-by: 沈唁 <[email protected]>
1 parent ed3b489 commit b399e85

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/ScanHandler/ProcScanHandler.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace Hyperf\Di\ScanHandler;
13+
14+
class ProcScanHandler implements ScanHandlerInterface
15+
{
16+
public const SCAN_PROC_WORKER = 'SCAN_PROC_WORKER';
17+
18+
protected string $bin;
19+
20+
protected string $stub;
21+
22+
public function __construct(?string $bin = null, ?string $stub = null)
23+
{
24+
if ($bin === null) {
25+
$bin = PHP_BINARY;
26+
}
27+
28+
if ($stub === null) {
29+
$stub = BASE_PATH . '/bin/hyperf.php';
30+
}
31+
32+
$this->bin = $bin;
33+
$this->stub = $stub;
34+
}
35+
36+
public function scan(): Scanned
37+
{
38+
if (env(static::SCAN_PROC_WORKER)) {
39+
return new Scanned(false);
40+
}
41+
42+
$proc = proc_open(
43+
[$this->bin, $this->stub],
44+
[0 => STDIN, 1 => ['pipe', 'w'], 2 => ['redirect', 1]],
45+
$pipes,
46+
null,
47+
[static::SCAN_PROC_WORKER => '(true)']
48+
);
49+
50+
$output = '';
51+
do {
52+
$output .= fread($pipes[1], 8192);
53+
} while (! feof($pipes[1]));
54+
proc_close($proc);
55+
56+
return new Scanned(true);
57+
}
58+
}

0 commit comments

Comments
 (0)