Completed
Push — master ( 96a033...7625bb )
by Henry
07:07
created

includes/Bootstrap/Common.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Bootstrap;
3
4
use PDO;
5
use Redaxscript\Client;
6
use Redaxscript\Server;
7
use function function_exists;
8
use function getenv;
9
use function is_dir;
10
use function opcache_get_status;
11
use function strpos;
12
use function strtolower;
13
use function version_compare;
14
15
/**
16
 * children class to boot the common
17
 *
18
 * @since 3.1.0
19
 *
20
 * @package Redaxscript
21
 * @category Bootstrap
22
 * @author Henry Ruhs
23
 */
24
25
class Common extends BootstrapAbstract
26
{
27
	/**
28
	 * automate run
29
	 *
30
	 * @since 3.1.0
31
	 */
32
33 3
	public function autorun() : void
34
	{
35 3
		$this->_setServer();
36 3
		$this->_setClient();
37 3
		$this->_setDriver();
38 3
		$this->_setModule();
39 3
		$this->_setPhp();
40 3
		$this->_setOpcache();
41 3
	}
42
43
	/**
44
	 * set the server
45
	 *
46
	 * @since 3.1.0
47
	 */
48
49 3
	protected function _setServer() : void
50
	{
51 3
		$file = new Server\File($this->_request);
52 3
		$root = new Server\Root($this->_request);
53 3
		$host = new Server\Host($this->_request);
54 3
		$token = new Server\Token($this->_request);
55
56
		/* set the registry */
57
58 3
		$this->_registry->set('file', $file->getOutput());
59 3
		$this->_registry->set('root', $root->getOutput());
60 3
		$this->_registry->set('host', $host->getOutput());
61 3
		$this->_registry->set('token', $token->getOutput());
62 3
	}
63
64
	/**
65
	 * set the client
66
	 *
67
	 * @since 3.1.0
68
	 */
69
70 3
	protected function _setClient() : void
71
	{
72 3
		$browser = new Client\Browser($this->_request);
73 3
		$version = new Client\Version($this->_request);
74 3
		$engine = new Client\Engine($this->_request);
75 3
		$mobile = new Client\Mobile($this->_request);
76 3
		$tablet = new Client\Tablet($this->_request);
77 3
		$desktop = new Client\Desktop($this->_request);
78
79
		/* set the registry */
80
81 3
		$this->_registry->set('myBrowser', $browser->getOutput());
82 3
		$this->_registry->set('myBrowserVersion', $version->getOutput());
83 3
		$this->_registry->set('myEngine', $engine->getOutput());
84 3
		$this->_registry->set('myMobile', $mobile->getOutput());
85 3
		$this->_registry->set('myTablet', $tablet->getOutput());
86 3
		$this->_registry->set('myDesktop', $desktop->getOutput());
87 3
	}
88
89
	/**
90
	 * set the driver
91
	 *
92
	 * @since 3.1.0
93
	 */
94
95 3
	protected function _setDriver() : void
96
	{
97 3
		$driverArray = [];
98
99
		/* process driver */
100
101 3
		foreach (PDO::getAvailableDrivers() as $driver)
102
		{
103 3
			$driver = $driver === 'sqlsrv' ? 'mssql' : $driver;
104 3
			if (is_dir('database' . DIRECTORY_SEPARATOR . $driver))
105
			{
106 3
				$driverArray[$driver] = $driver;
107
			}
108
		}
109 3
		$this->_registry->set('driverArray', $driverArray);
110 3
	}
111
112
	/**
113
	 * set the module
114
	 *
115
	 * @since 3.1.0
116
	 */
117
118 3
	protected function _setModule() : void
119
	{
120 3
		$moduleArray = function_exists('apache_get_modules') ? apache_get_modules() : [];
121
		$fallbackArray =
122
		[
123 3
			'mod_deflate' => 'REDIRECT_MOD_DEFLATE',
124
			'mod_brotli' => 'REDIRECT_MOD_BROTLI',
125
			'mod_security' => 'REDIRECT_MOD_SECURITY',
126
			'mod_rewrite' => 'REDIRECT_MOD_REWRITE',
127
			'mod_headers' => 'REDIRECT_MOD_HEADERS'
128
		];
129
130
		/* process fallback */
131 3
132
		if (!$moduleArray)
133 3
		{
134
			foreach ($fallbackArray as $key => $value)
135 3
			{
136
				if (getenv($value) === 'on')
137 1
				{
138
					$moduleArray[$key] = true;
139
				}
140
			}
141 3
		}
142 3
		$this->_registry->set('moduleArray', $moduleArray);
143
	}
144
145
	/**
146
	 * set the php
147
	 *
148
	 * @since 3.2.3
149
	 */
150 3
151
	protected function _setPhp() : void
152 3
	{
153 3
		$phpOs = strtolower(PHP_OS);
154 3
		$phpVersion = PHP_VERSION;
155
		if (strpos($phpOs, 'linux') === 0)
156 3
		{
157
			$this->_registry->set('phpOs', 'linux');
158
		}
159
		else if (strpos($phpOs, 'win') === 0)
160
		{
161
			$this->_registry->set('phpOs', 'windows');
162 3
		}
163 3
		$this->_registry->set('phpVersion', $phpVersion);
164 3
		$this->_registry->set('phpStatus', version_compare($phpVersion, '7.2', '>='));
0 ignored issues
show
\version_compare($phpVersion, '7.2', '>=') is of type boolean, but the function expects a string|array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
	}
166
167
	/**
168
	 * set the opcache
169
	 *
170
	 * @since 4.0.0
171
	 */
172 3
173
	protected function _setOpcache() : void
174 3
	{
175 3
		$opcacheArray = function_exists('opcache_get_status') ? opcache_get_status(false) : [];
176 3
		$this->_registry->set('opcacheArray', $opcacheArray);
177
	}
178
}
179