-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathExtensionResolver.php
496 lines (481 loc) · 18.3 KB
/
ExtensionResolver.php
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\CloudDocker\Compose\Php;
use Composer\Semver\Semver;
use Magento\CloudDocker\App\ConfigurationMismatchException;
use Magento\CloudDocker\Config\Config;
use Magento\CloudDocker\Service\ServiceInterface;
/**
* Returns list of PHP extensions which will be enabled in Docker PHP container.
*/
class ExtensionResolver
{
public const EXTENSION_OS_DEPENDENCIES = 'extension_os_dependencies';
public const EXTENSION_PACKAGE_NAME = 'extension_package_name';
public const EXTENSION_TYPE = 'extension_type';
public const EXTENSION_TYPE_PECL = 'extension_type_pecl';
public const EXTENSION_TYPE_CORE = 'extension_type_core';
public const EXTENSION_TYPE_INSTALLATION_SCRIPT = 'extension_type_installation_script';
public const EXTENSION_CONFIGURE_OPTIONS = 'extension_configure_options';
public const EXTENSION_INSTALLATION_SCRIPT = 'extension_installation_script';
/**
* Extensions which should be installed by default
*/
public const DEFAULT_PHP_EXTENSIONS = [
'bcmath',
'bz2',
'calendar',
'exif',
'gd',
'gettext',
'intl',
'mysqli',
'pcntl',
'pdo_mysql',
'soap',
'sockets',
'sysvmsg',
'sysvsem',
'sysvshm',
'opcache',
'zip',
// Required for Magento 2.4.0+
'xsl',
'sodium',
];
/**
* Extensions which built-in and can't be uninstalled
*/
private const BUILTIN_EXTENSIONS = [
'ctype' => '>=7.0',
'curl' => '>=7.0',
'date' => '>=7.0',
'dom' => '>=7.0',
'fileinfo' => '>=7.0',
'filter' => '>=7.0',
'ftp' => '>=7.0',
'hash' => '>=7.0',
'iconv' => '>=7.0',
'json' => '>=7.0',
'mbstring' => '>=7.0',
'mysqlnd' => '>=7.0',
'openssl' => '>=7.0',
'pcre' => '>=7.0',
'pdo' => '>=7.0',
'pdo_sqlite' => '>=7.0',
'phar' => '>=7.0',
'posix' => '>=7.0',
'readline' => '>=7.0',
'session' => '>=7.0',
'simplexml' => '>=7.0',
'sqlite3' => '>=7.0',
'tokenizer' => '>=7.0',
'xml' => '>=7.0',
'xmlreader' => '>=7.0',
'xmlwriter' => '>=7.0',
'zlib' => '>=7.0',
];
/**
* Extensions which should be ignored
*/
private const IGNORED_EXTENSIONS = ['newrelic'];
/**
* @var Semver
*/
private $semver;
/**
* @param Semver $semver
*/
public function __construct(Semver $semver)
{
$this->semver = $semver;
}
/**
* Returns list of PHP extensions which will be enabled in Docker PHP container.
*
* @param Config $config
* @return array
* @throws ConfigurationMismatchException
*/
public function get(Config $config): array
{
$phpVersion = $config->getServiceVersion(ServiceInterface::SERVICE_PHP);
$enabledPhpExtensions = [];
foreach ($config->getEnabledPhpExtensions() as $phpExtension) {
is_array($phpExtension) ? : array_push($enabledPhpExtensions, $phpExtension);
}
$enabledExtensions = array_unique(
array_merge(self::DEFAULT_PHP_EXTENSIONS, $enabledPhpExtensions)
);
$phpExtensions = array_diff(
$enabledExtensions,
$config->getDisabledPhpExtensions(),
self::IGNORED_EXTENSIONS
);
$messages = [];
$result = [];
foreach ($phpExtensions as $phpExtName) {
if (isset(self::BUILTIN_EXTENSIONS[$phpExtName])
&& $this->semver::satisfies($phpVersion, self::BUILTIN_EXTENSIONS[$phpExtName])
) {
continue;
}
if (isset(self::getConfig()[$phpExtName])) {
$constraint = implode('||', array_keys(self::getConfig()[$phpExtName]));
if ($this->semver::satisfies($phpVersion, $constraint)) {
$result[] = $phpExtName;
continue;
}
$messages[] = "PHP extension $phpExtName is not available for PHP version $phpVersion.";
continue;
}
$messages[] = "PHP extension $phpExtName is not supported.";
}
if ($messages) {
throw new ConfigurationMismatchException(implode(PHP_EOL, $messages));
}
return $result;
}
/**
* @return array
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public static function getConfig(): array
{
return [
'bcmath' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'blackfire' => [
'>=7.2' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
self::EXTENSION_OS_DEPENDENCIES => [
'gnupg2',
'ca-certificates',
'lsb-release',
'software-properties-common'
],
// phpcs:disable
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
curl -L https://packages.blackfire.io/gpg.key | gpg --dearmor > blackfire.io-archive-keyring.gpg
install -o root -g root -m 644 blackfire.io-archive-keyring.gpg /etc/apt/trusted.gpg.d/
echo "deb http://packages.blackfire.io/debian any main" | tee /etc/apt/sources.list.d/blackfire.list
apt-get update
apt-get install blackfire-php
rm -rf /var/lib/apt/lists/*
BASH
// phpcs:enable
],
],
'bz2' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libbz2-dev'],
],
],
'calendar' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'exif' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'gd' => [
'>=7.0 <=7.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libjpeg62-turbo-dev', 'libpng-dev', 'libfreetype6-dev'],
self::EXTENSION_CONFIGURE_OPTIONS => [
'--with-freetype-dir=/usr/include/',
'--with-jpeg-dir=/usr/include/'
],
],
'>=7.4' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libjpeg62-turbo-dev', 'libpng-dev', 'libfreetype6-dev', 'libwebp-dev'],
self::EXTENSION_CONFIGURE_OPTIONS => [
'--with-freetype=/usr/include/',
'--with-jpeg=/usr/include/',
'--with-webp=/usr/include/'
],
],
],
'geoip' => [
'>=7.0 <8.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_OS_DEPENDENCIES => ['libgeoip-dev', 'wget'],
self::EXTENSION_PACKAGE_NAME => 'geoip-1.1.1',
],
],
'gettext' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'gmp' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libgmp-dev'],
],
],
'gnupg' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_OS_DEPENDENCIES => ['libgpgme11-dev'],
],
],
'igbinary' => [
'>=7.0 <8.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
],
'imagick' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_OS_DEPENDENCIES => ['libmagickwand-dev', 'libmagickcore-dev'],
],
],
'imap' => [
'>=7.0 <=7.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libc-client-dev', 'libkrb5-dev'],
self::EXTENSION_CONFIGURE_OPTIONS => ['--with-kerberos', '--with-imap-ssl'],
],
],
'intl' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libicu-dev'],
],
],
'ldap' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
self::EXTENSION_OS_DEPENDENCIES => ['libldap2-dev'],
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
if [ $(uname -m) = "x86_64" ]; then ldap_arch="x86_64-linux-gnu"; else ldap_arch="aarch64-linux-gnu"; fi
docker-php-ext-configure ldap --with-libdir=lib/\${ldap_arch}
BASH
],
],
'mailparse' => [
'<7.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_PACKAGE_NAME => 'mailparse-3.1.3',
],
'>=7.3' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
],
'mcrypt' => [
'>=7.0.0 <7.2' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libmcrypt-dev'],
],
],
'msgpack' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
],
'mysqli' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'oauth' => [
'>=7.0 <8.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
'>=8.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_OS_DEPENDENCIES => ['libpcre3-dev'],
],
],
'opcache' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_CONFIGURE_OPTIONS => ['--enable-opcache'],
],
],
'pcov' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
],
'pdo_mysql' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'propro' => [
'>=7.0 <8.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
],
'pspell' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libpspell-dev'],
],
],
'raphf' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
],
'recode' => [
'>=7.0 <=7.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['librecode0', 'librecode-dev'],
],
],
'redis' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL],
],
'shmop' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'soap' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'sockets' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'zookeeper' => [
'>=7.2 <8.2' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
// phpcs:disable
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
mkdir -p /tmp/zoo
cd /tmp/zoo
git clone https://github.com/php-zookeeper/php-zookeeper.git
curl -LO https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar -xf zookeeper-3.4.14.tar.gz
cp zookeeper-3.4.14/zookeeper-client/zookeeper-client-c/generated/zookeeper.jute.h zookeeper-3.4.14/zookeeper-client/zookeeper-client-c/include
cd zookeeper-3.4.14/zookeeper-client/zookeeper-client-c
./configure
sed -i 's/CFLAGS = -g -O2 -D_GNU_SOURCE/CFLAGS = -g -O2 -D_GNU_SOURCE -Wno-error=format-overflow -Wno-error=stringop-truncation/g' Makefile
make
make install
ldconfig
cd /tmp/zoo/php-zookeeper
phpize
./configure --with-libzookeeper-dir=../zookeeper-3.4.14/zookeeper-client/zookeeper-client-c
make
make install
BASH
// phpcs:enable
],
],
'sodium' => [
'>=7.0 <7.2' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
mkdir -p /tmp/libsodium
curl -sL https://github.com/jedisct1/libsodium/archive/1.0.18-RELEASE.tar.gz | tar xzf - -C /tmp/libsodium
cd /tmp/libsodium/libsodium-1.0.18-RELEASE/
./configure
make && make check
make install
cd /
rm -rf /tmp/libsodium
pecl install -o -f libsodium
BASH
],
'>=7.2' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
rm -f /usr/local/etc/php/conf.d/*sodium.ini
rm -f /usr/local/lib/php/extensions/*/*sodium.so
apt-get remove libsodium* -y
mkdir -p /tmp/libsodium
curl -sL https://github.com/jedisct1/libsodium/archive/1.0.18-RELEASE.tar.gz | tar xzf - -C /tmp/libsodium
cd /tmp/libsodium/libsodium-1.0.18-RELEASE/
./configure
make && make check
make install
cd /
rm -rf /tmp/libsodium
pecl install -o -f libsodium
BASH
]
],
'ssh2' => [
// SSH2 is not supported on 7.3
// https://serverpilot.io/docs/how-to-install-the-php-ssh2-extension
'>=7.0 <7.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_OS_DEPENDENCIES => ['libssh2-1', 'libssh2-1-dev'],
self::EXTENSION_PACKAGE_NAME => 'ssh2-1.1.2',
],
],
'sysvmsg' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'sysvsem' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'sysvshm' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'tidy' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libtidy-dev'],
],
],
'xdebug' => [
'>=7.2 <8.2' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_PACKAGE_NAME => 'xdebug-3.1.2',
],
'>=8.2 <8.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_PACKAGE_NAME => 'xdebug-3.2.0',
],
'>=8.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_PACKAGE_NAME => 'xdebug-3.3.0',
],
],
'xmlrpc' => [
'>=7.0 <8.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
'>=8.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_PACKAGE_NAME => 'xmlrpc-1.0.0RC3',
],
],
'xsl' => [
'>=7.0' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libxslt1-dev'],
],
],
'yaml' => [
'>=7.0 <7.1' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_OS_DEPENDENCIES => ['libyaml-dev'],
self::EXTENSION_PACKAGE_NAME => 'yaml-2.1.0',
],
'>=7.1' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
self::EXTENSION_OS_DEPENDENCIES => ['libyaml-dev'],
],
],
'zip' => [
'>=7.0 <=7.3' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libzip-dev', 'zip'],
self::EXTENSION_CONFIGURE_OPTIONS => ['--with-libzip'],
],
'>=7.4' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
self::EXTENSION_OS_DEPENDENCIES => ['libzip-dev', 'zip'],
],
],
'pcntl' => [
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
],
'ioncube' => [
'>=7.0 <8.0 || >8.0 <=8.1' => [
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
cd /tmp
if [ $(uname -m) = "x86_64" ]; then ioncube_arch="x86-64"; else ioncube_arch="aarch64"; fi
curl -O https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_\${ioncube_arch}.tar.gz
tar zxvf ioncube_loaders_lin_\${ioncube_arch}.tar.gz
export PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
export PHP_EXT_DIR=$(php-config --extension-dir)
cp "./ioncube/ioncube_loader_lin_\${PHP_VERSION}.so" "\${PHP_EXT_DIR}/ioncube.so"
rm -rf ./ioncube
rm ioncube_loaders_lin_\${ioncube_arch}.tar.gz
BASH
],
],
];
}
}