PHP Class YiiRequirementChecker, yii2

This class allows rendering of the check report for the web and console application interface. Example: php require_once('path/to/YiiRequirementChecker.php'); $requirementsChecker = new YiiRequirementChecker(); $requirements = array( array( 'name' => 'PHP Some Extension', 'mandatory' => true, 'condition' => extension_loaded('some_extension'), 'by' => 'Some application feature', 'memo' => 'PHP extension "some_extension" required', ), ); $requirementsChecker->checkYii()->check($requirements)->render(); If you wish to render the report with your own representation, use YiiRequirementChecker::getResult instead of YiiRequirementChecker::render Requirement condition could be in format "eval:PHP expression". In this case specified PHP expression will be evaluated in the context of this class instance. For example: php $requirements = array( array( 'name' => 'Upload max file size', 'condition' => 'eval:$this->checkUploadMaxFileSize("5M")', ), ); Note: this class definition does not match ordinary Yii style, because it should match PHP 4.3 and should not use features from newer PHP versions!
Since: 2.0
Author: Paul Klimov ([email protected])
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Methods

Method Description
check ( array | string $requirements ) Check the given requirements, collecting results into internal field.
checkPhpExtensionVersion ( string $extensionName, string $version, string $compare = '>=' ) : boolean Checks if the given PHP extension is available and its version matches the given one.
checkPhpIniOff ( string $name ) : boolean Checks if PHP configuration option (from php.ini) is off.
checkPhpIniOn ( string $name ) : boolean Checks if PHP configuration option (from php.ini) is on.
checkUploadMaxFileSize ( string | null $min = null, string | null $max = null ) : boolean Checks if upload max file size matches the given range.
checkYii ( ) : YiiRequirementChecker Performs the check for the Yii core requirements.
compareByteSize ( string $a, string $b, string $compare = '>=' ) : boolean Compare byte sizes of values given in the verbose representation, like '5M', '15K' etc.
evaluateExpression ( string $expression ) : mixed Evaluates a PHP expression under the context of this class.
getByteSize ( string $verboseSize ) : integer Gets the size in bytes from verbose size representation.
getNowDate ( ) : string Returns the now date if possible in string representation.
getResult ( ) : array | null Return the check results.
getServerInfo ( ) : string Returns the server information.
normalizeRequirement ( array $requirement, integer $requirementKey ) : array Normalizes requirement ensuring it has correct format.
render ( ) Renders the requirements check result.
renderViewFile ( string $_viewFile_, array $_data_ = null, boolean $_return_ = false ) : string Renders a view file.
usageError ( string $message ) Displays a usage error.

Method Details

check() public method

This method can be invoked several times checking different requirement sets. Use YiiRequirementChecker::getResult or YiiRequirementChecker::render to get the results.
public check ( array | string $requirements )
$requirements array | string requirements to be checked. If an array, it is treated as the set of requirements; If a string, it is treated as the path of the file, which contains the requirements;

checkPhpExtensionVersion() public method

Checks if the given PHP extension is available and its version matches the given one.
public checkPhpExtensionVersion ( string $extensionName, string $version, string $compare = '>=' ) : boolean
$extensionName string PHP extension name.
$version string required PHP extension version.
$compare string comparison operator, by default '>='
return boolean if PHP extension version matches.

checkPhpIniOff() public method

Checks if PHP configuration option (from php.ini) is off.
public checkPhpIniOff ( string $name ) : boolean
$name string configuration option name.
return boolean option is off.

checkPhpIniOn() public method

Checks if PHP configuration option (from php.ini) is on.
public checkPhpIniOn ( string $name ) : boolean
$name string configuration option name.
return boolean option is on.

checkUploadMaxFileSize() public method

Checks if upload max file size matches the given range.
public checkUploadMaxFileSize ( string | null $min = null, string | null $max = null ) : boolean
$min string | null verbose file size minimum required value, pass null to skip minimum check.
$max string | null verbose file size maximum required value, pass null to skip maximum check.
return boolean success.

checkYii() public method

Performs the check for the Yii core requirements.
public checkYii ( ) : YiiRequirementChecker
return YiiRequirementChecker self instance.

compareByteSize() public method

Compare byte sizes of values given in the verbose representation, like '5M', '15K' etc.
public compareByteSize ( string $a, string $b, string $compare = '>=' ) : boolean
$a string first value.
$b string second value.
$compare string comparison operator, by default '>='.
return boolean comparison result.

evaluateExpression() public method

Evaluates a PHP expression under the context of this class.
public evaluateExpression ( string $expression ) : mixed
$expression string a PHP expression to be evaluated.
return mixed the expression result.

getByteSize() public method

For example: '5K' => 5*1024
public getByteSize ( string $verboseSize ) : integer
$verboseSize string verbose size representation.
return integer actual size in bytes.

getNowDate() public method

Returns the now date if possible in string representation.
public getNowDate ( ) : string
return string now date.

getResult() public method

Return the check results.
public getResult ( ) : array | null
return array | null check results in format: ```php array( 'summary' => array( 'total' => total number of checks, 'errors' => number of errors, 'warnings' => number of warnings, ), 'requirements' => array( array( ... 'error' => is there an error, 'warning' => is there a warning, ), ... ), ) ```

getServerInfo() public method

Returns the server information.
public getServerInfo ( ) : string
return string server information.

normalizeRequirement() public method

Normalizes requirement ensuring it has correct format.
public normalizeRequirement ( array $requirement, integer $requirementKey ) : array
$requirement array raw requirement.
$requirementKey integer requirement key in the list.
return array normalized requirement.

render() public method

The output will vary depending is a script running from web or from console.
public render ( )

renderViewFile() public method

This method includes the view file as a PHP script and captures the display result if required.
public renderViewFile ( string $_viewFile_, array $_data_ = null, boolean $_return_ = false ) : string
$_viewFile_ string view file
$_data_ array data to be extracted and made available to the view file
$_return_ boolean whether the rendering result should be returned as a string
return string the rendering result. Null if the rendering result is not required.

usageError() public method

This method will then terminate the execution of the current application.
public usageError ( string $message )
$message string the error message