Last active
October 23, 2018 10:29
-
-
Save hron84/3fc19a7d0612ba3bb650209be999ea01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function val($x) { | |
if($x === true) { return 'on'; } | |
elseif($x === false) { return 'off'; } | |
else { return (string)$x; } | |
} | |
function isDrupalReady() { | |
$result = true; | |
$errors = array(); | |
$required_exts = array( | |
array('mysql', 'mysqli', 'pdo_mysql'), | |
'curl', | |
'gd', | |
'json', | |
'mbstring', | |
'openssl', | |
'pcre', | |
'pdo', | |
'SimpleXML', | |
'xml', | |
'xmlrpc', | |
); | |
$required_ini = array( | |
'mbstring.http_input' => array('pass', ''), | |
'magic_quotes_gpc' => array(false, NULL, ''), | |
'safe_mode' => array(false, NULL, ''), | |
'register_globals' => array(false, NULL, ''), | |
'session.auto_start' => 0, | |
'session.cache_limiter' => 'nocache', | |
); | |
foreach($required_exts as $ext) { | |
if(!is_array($ext)) { | |
if(!extension_loaded($ext)) { | |
$result = false; | |
$errors[] = "Missing PHP extension $ext"; | |
} | |
} else { | |
$found = 0; | |
foreach($ext as $i) { | |
if(extension_loaded($i)) { $found++; } | |
} | |
if($found == 0) { | |
$result = false; | |
$errors[] = "One of the following extensions should be present: " . implode(',', $ext); | |
} | |
} | |
} | |
foreach($required_ini as $ini => $val) { | |
$current = ini_get($ini); | |
if(!is_array($val)) { | |
if(is_numeric($val)) { | |
if($current < $val) { | |
$result = false; | |
$errors[] = sprintf("Drupal.org recommends %s to set minimum %s", $ini, $val); | |
} | |
} else { | |
if($current !== $val) { | |
$result = false; | |
$errors[] = sprintf("Drupal.org recommends %s to set %s value", $ini, val($val)); | |
} | |
} | |
} else { | |
if(!in_array($current, $val)) { | |
$result = false; | |
$errors[] = sprintf("Drupal.org recommends %s to be set one of these values: %s", $ini, join(', ', $val)); | |
} | |
} | |
} | |
return array('result' => $result, 'errors' => $errors); | |
} | |
$readiness = isDrupalReady(); | |
$php_version = phpversion(); | |
if($readiness['result'] == true) { | |
echo "Your PHP {$php_version} installation is Drupal-ready!" . PHP_EOL; | |
} else { | |
echo "Your PHP {$php_version} installation does not follow Drupal.org recommendations, please fix following problems:" . PHP_EOL; | |
foreach($readiness['errors'] as $error) { | |
echo " >> {$error}" . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: