File: //srv/htdocs/wp-content/mu-plugins/wp-cloud-client/src/Handler/PhpVerifyHandler.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\Handler;
final class PhpVerifyHandler extends AbstractHandler {
private const REQUIREMENTS = [
'extensions' => [
'retrieve_func' => 'get_loaded_extensions',
'expected' => [
'Core',
'PDO',
'Phar',
'Reflection',
'SPL',
'SimpleXML',
'bcmath',
'bz2',
'ctype',
'curl',
'date',
'dom',
'exif',
'fileinfo',
'filter',
'ftp',
'gd',
'hash',
'iconv',
'imagick',
'imap',
'json',
'libxml',
'mbstring',
'mysqli',
'mysqlnd',
'openssl',
'pcre',
'pdo_mysql',
'posix',
'readline',
'session',
'soap',
'sodium',
'standard',
'tokenizer',
'xml',
'xmlreader',
'xmlwriter',
'zip',
'zlib',
],
],
'transports' => [
'retrieve_func' => 'stream_get_transports',
'expected' => [
'ssl',
'tcp',
'tls',
'tlsv1.0',
'tlsv1.1',
'tlsv1.2',
'udg',
'udp',
'unix',
],
],
'streams' => [
'retrieve_func' => 'stream_get_wrappers',
'expected' => [
'compress.bzip2',
'compress.zlib',
'data',
'file',
'ftp',
'ftps',
'glob',
'http',
'https',
'phar',
'php',
'zip',
],
],
];
/**
* Return the action name.
*
* @return string Action name.
*/
public function action(): string {
return 'php_verify';
}
/**
* Verify PHP extensions, transports, and stream wrappers.
*
* @param array<string, mixed> $params Action parameters.
* @return array<string, mixed> Verification result.
*/
public function execute( array $params ): array {
$missing = [];
foreach ( self::REQUIREMENTS as $type => $requirement ) {
/**
* Retrieval function name.
*
* @var callable-string $func
*/
$func = $requirement['retrieve_func'];
/**
* Available items from the retrieval function.
*
* @var list<string> $got
*/
$got = $func();
$got = array_flip( $got );
foreach ( $requirement['expected'] as $item ) {
if ( ! isset( $got[ $item ] ) ) {
if ( ! isset( $missing[ $type ] ) ) {
$missing[ $type ] = [];
}
$missing[ $type ][] = $item;
}
}
}
if ( empty( $missing ) ) {
return [ 'all_good' => true ];
}
return [ 'missing' => $missing ];
}
}