Created
May 7, 2010 17:18
-
-
Save jmhobbs/393739 to your computer and use it in GitHub Desktop.
Storytlr Requirements Check
This file contains hidden or 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 | |
class Check { | |
protected static $errors = 0; | |
protected static $include_found = true; | |
public static function no_errors () { | |
return true;//( 0 == self::$errors ); | |
} | |
public static function error_count () { | |
return self::$errors; | |
} | |
protected static function show_check_div ( $string, $class ) { | |
echo '<div class="' . $class . '">' . $string . '</div>'; | |
} | |
public static function good ( $string ) { self::show_check_div( $string, 'good' ); } | |
public static function bad ( $string ) { self::$errors++; self::show_check_div( $string, 'bad' ); } | |
public static function warn ( $string ) { self::show_check_div( $string, 'warn' ); } | |
// Check the level of php available | |
public static function PHP ( $required ) { | |
if( 1 == version_compare( $required, phpversion() ) ) | |
Check::bad( "Your PHP version is too low, the minimum required is $required." ); | |
else | |
Check::good( "PHP Version " . phpversion() . " meets requirement." ); | |
} | |
public static function SettingValue ( $setting, $expected ) { | |
if( $expected != ini_get( $setting ) ) | |
Check::bad( "PHP Setting '$setting' should be '". var_export( $expected, true ) . "'." ); | |
else | |
Check::good( "PHP Setting '$setting' is '" . var_export( $expected, true ) ."'." ); | |
} | |
// Check if a class exists | |
public static function ClassExists ( $class, $name, $warn_only=false ) { | |
if( class_exists( $class, false ) ) | |
Check::good( "Found $name." ); | |
else if( $warn_only ) | |
Check::warn( "Can not find $name." ); | |
else | |
Check::bad( "Can not find $name." ); | |
} | |
// Check if a function exists. | |
public static function FunctionExists ( $function, $name, $warn_only=false ) { | |
if( function_exists( $function ) ) | |
Check::good( "Found $name." ); | |
else if( $warn_only ) | |
Check::warn( "Can not find $name." ); | |
else | |
Check::bad( "Can not find $name." ); | |
} | |
// Check if a file can be included, is on the path. | |
public static function CanInclude ( $include, $name, $warn_only=false ) { | |
self::$include_found = true; | |
set_error_handler( 'Check::include_error_handler', E_WARNING ); | |
include_once( $include ); | |
restore_error_handler(); | |
if( self::$include_found ) | |
Check::good( "Found $name." ); | |
else if( $warn_only ) | |
Check::warn( "Can not find $name." ); | |
else | |
Check::bad( "Can not find $name." ); | |
return self::$include_found; | |
} | |
protected static function include_error_handler ( $errno, $errstr ) { | |
self::$include_found = false; | |
} | |
// Checks an extension existence by phpversion. Doesn't work for all extensions. | |
public static function ExtensionExists ( $extension, $name, $warn_only=false ) { | |
if( false !== phpversion( $extension ) ) | |
Check::good( "Found $name." ); | |
else if( $warn_only ) | |
Check::warn( "Can not find $name." ); | |
else | |
Check::bad( "Can not find $name." ); | |
} | |
public static function PathWritable ( $path, $warn_only=false ) { | |
$root = dirname( __FILE__ ) . '/../../'; | |
if( is_writable( $root . $path ) ) | |
Check::good( "$path is writable." ); | |
else if( $warn_only ) | |
Check::warn( "$path is not writable." ); | |
else | |
Check::bad( "$path is not writable." ); | |
} | |
} // Class Check | |
?> | |
<html> | |
<head> | |
<title>Storytlr Requirements Check</title> | |
<style type="text/css"> | |
.good, .bad, .warn { | |
padding: 5px; | |
font-weight: bold; | |
text-shadow: 1px 1px 2px #AAA; | |
color: #FFF; | |
} | |
.good { | |
background-color: #00BF00; | |
} | |
.bad { | |
background-color: #BF2C00; | |
} | |
.warn { | |
background-color: #BFB900; | |
} | |
</style> | |
</head> | |
<body> | |
<div style="width: 500px; margin: 0 auto;"> | |
<h1>Storytlr Requirements Check</h1> | |
<?php | |
Check::PHP( "5.0" ); | |
Check::SettingValue( "magic_quotes_gpc", false ); | |
if( Check::CanInclude( 'Zend/Version.php', 'Zend Framework' ) ) | |
if( Zend_Version::compareVersion( '1.0.0' ) > 0 ) | |
warn( 'Zend Version 1.0.0 or newer is recommended' ); | |
Check::FunctionExists( 'mcrypt_module_open', 'mcrypt' ); | |
Check::FunctionExists( 'curl_init', 'cURL' ); | |
Check::ExtensionExists( 'PDO', 'PDO' ); | |
Check::ExtensionExists( 'tidy', 'Tidy'); | |
?> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment