-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathSwoftHelper.php
More file actions
78 lines (68 loc) · 1.96 KB
/
SwoftHelper.php
File metadata and controls
78 lines (68 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php declare(strict_types=1);
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://swoft.org/docs
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace Swoft\Helper;
use RuntimeException;
use function extension_loaded;
use function implode;
use function version_compare;
use const PHP_VERSION;
use const SWOOLE_VERSION;
/**
* Class SwoftHelper
*
* @since 2.0
*/
class SwoftHelper
{
/**
* @param array $stats
*
* @return string
*/
public static function formatStats(array $stats): string
{
$strings = [];
foreach ($stats as $name => $count) {
$strings[] = "$name $count";
}
return implode(', ', $strings);
}
/**
* Check runtime extension conflict
*
* @param string $minPhp
* @param string $minSwoole
*/
public static function checkRuntime(string $minPhp = '7.1', string $minSwoole = '4.4.1'): void
{
if (version_compare(PHP_VERSION, $minPhp, '<')) {
throw new RuntimeException('Run the server requires PHP version > ' . $minPhp . '! current is ' . PHP_VERSION);
}
if (!extension_loaded('openswoole') && !extension_loaded('swoole')) {
throw new RuntimeException("Run the server, extension 'swoole' is required!");
}
if (version_compare(SWOOLE_VERSION, $minSwoole, '<')) {
throw new RuntimeException('Run the server requires swoole version > ' . $minSwoole . '! current is ' . SWOOLE_VERSION);
}
$conflicts = [
'blackfire',
'xdebug',
'uopz',
'xhprof',
'zend',
'trace',
];
foreach ($conflicts as $ext) {
if (extension_loaded($ext)) {
throw new RuntimeException("The extension of '{$ext}' must be closed, otherwise swoft will be affected!");
}
}
}
}