Class YiiRequirementChecker
| Inheritance | YiiRequirementChecker |
|---|---|
| Available since version | 2.0 |
| Source Code | https://github.com/yiisoft/yii2/blob/master/framework/equirementChecker.php |
YiiRequirementChecker allows checking, if current system meets the requirements for running the Yii application.
This class allows rendering of the check report for the web and console application interface.
Example:
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 getResult() instead of 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:
$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!
Public Methods
| Method | Description | Defined By |
|---|---|---|
| check() | Check the given requirements, collecting results into internal field. | YiiRequirementChecker |
| checkPhpExtensionVersion() | Checks if the given PHP extension is available and its version matches the given one. | YiiRequirementChecker |
| checkPhpIniOff() | Checks if PHP configuration option (from php.ini) is off. | YiiRequirementChecker |
| checkPhpIniOn() | Checks if PHP configuration option (from php.ini) is on. | YiiRequirementChecker |
| checkUploadMaxFileSize() | Checks if upload max file size matches the given range. | YiiRequirementChecker |
| checkYii() | Performs the check for the Yii core requirements. | YiiRequirementChecker |
| compareByteSize() | Compare byte sizes of values given in the verbose representation, like '5M', '15K' etc. | YiiRequirementChecker |
| evaluateExpression() | Evaluates a PHP expression under the context of this class. | YiiRequirementChecker |
| getByteSize() | Gets the size in bytes from verbose size representation. | YiiRequirementChecker |
| getNowDate() | Returns the now date if possible in string representation. | YiiRequirementChecker |
| getResult() | Return the check results. | YiiRequirementChecker |
| getServerInfo() | Returns the server information. | YiiRequirementChecker |
| normalizeRequirement() | Normalizes requirement ensuring it has correct format. | YiiRequirementChecker |
| render() | Renders the requirements check result. | YiiRequirementChecker |
| renderViewFile() | Renders a view file. | YiiRequirementChecker |
| usageError() | Displays a usage error. | YiiRequirementChecker |
Method Details
Check the given requirements, collecting results into internal field.
This method can be invoked several times checking different requirement sets. Use getResult() or render() to get the results.
| public $this check ( $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; |
| return | $this | Self instance. |
|---|---|---|
Checks if the given PHP extension is available and its version matches the given one.
| public boolean checkPhpExtensionVersion ( $extensionName, $version, $compare = '>=' ) | ||
| $extensionName | string | PHP extension name. |
| $version | string | Required PHP extension version. |
| $compare | string | Comparison operator, by default '>=' |
| return | boolean | If PHP extension version matches. |
|---|---|---|
Checks if PHP configuration option (from php.ini) is off.
| public boolean checkPhpIniOff ( $name ) | ||
| $name | string | Configuration option name. |
| return | boolean | Option is off. |
|---|---|---|
Checks if PHP configuration option (from php.ini) is on.
| public boolean checkPhpIniOn ( $name ) | ||
| $name | string | Configuration option name. |
| return | boolean | Option is on. |
|---|---|---|
Checks if upload max file size matches the given range.
| public boolean checkUploadMaxFileSize ( $min = null, $max = null ) | ||
| $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. |
|---|---|---|
Performs the check for the Yii core requirements.
| public YiiRequirementChecker checkYii ( ) | ||
| return | YiiRequirementChecker | Self instance. |
|---|---|---|
Compare byte sizes of values given in the verbose representation, like '5M', '15K' etc.
| public boolean compareByteSize ( $a, $b, $compare = '>=' ) | ||
| $a | string | First value. |
| $b | string | Second value. |
| $compare | string | Comparison operator, by default '>='. |
| return | boolean | Comparison result. |
|---|---|---|
Evaluates a PHP expression under the context of this class.
| public mixed evaluateExpression ( $expression ) | ||
| $expression | string | A PHP expression to be evaluated. |
| return | mixed | The expression result. |
|---|---|---|
Gets the size in bytes from verbose size representation.
For example: '5K' => 5*1024
| public integer getByteSize ( $verboseSize ) | ||
| $verboseSize | string | Verbose size representation. |
| return | integer | Actual size in bytes. |
|---|---|---|
Returns the now date if possible in string representation.
| public string getNowDate ( ) | ||
| return | string | Now date. |
|---|---|---|
Return the check results.
| public array|null getResult ( ) | ||
| return | array|null | Check results in format:
|
|---|---|---|
Returns the server information.
| public string getServerInfo ( ) | ||
| return | string | Server information. |
|---|---|---|
Normalizes requirement ensuring it has correct format.
| public array normalizeRequirement ( $requirement, $requirementKey = 0 ) | ||
| $requirement | array | Raw requirement. |
| $requirementKey | integer | Requirement key in the list. |
| return | array | Normalized requirement. |
|---|---|---|
Renders the requirements check result.
The output will vary depending is a script running from web or from console.
| public void render ( ) |
Renders a view file.
This method includes the view file as a PHP script and captures the display result if required.
| public string renderViewFile ( $_viewFile_, $_data_ = null, $_return_ = false ) | ||
| $_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. |
|---|---|---|
Displays a usage error.
This method will then terminate the execution of the current application.
| public void usageError ( $message ) | ||
| $message | string | The error message |