YiiRequirementChecker
API reference › Global namespace › YiiRequirementChecker
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 intentionally keeps a conservative standalone style for compatibility with requirement-check bootstrap environments.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$result | array| | The check results, this property is for internal usage only. Default: null. | YiiRequirementChecker |
Methods
Section titled “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
Section titled “Method details”check()
Section titled “check() ”public function check(array|string $requirements): $thisCheck 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.
Parameters
| Parameter | Type | Description |
|---|---|---|
$requirements | array| | 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; |
Returns
$this: Self instance.
checkPhpExtensionVersion()
Section titled “checkPhpExtensionVersion() ”public function checkPhpExtensionVersion(string $extensionName, string $version, string $compare = '>='): boolChecks if the given PHP extension is available and its version matches the given one.
Parameters
| Parameter | Type | Description |
|---|---|---|
$extensionName | string | PHP extension name. |
$version | string | Required PHP extension version. |
$compare | string | Comparison operator, by default ’>=’ |
Returns
bool: If PHP extension version matches.
checkPhpIniOff()
Section titled “checkPhpIniOff() ”public function checkPhpIniOff(string $name): boolChecks if PHP configuration option (from php.ini) is off.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Configuration option name. |
Returns
bool: Option is off.
checkPhpIniOn()
Section titled “checkPhpIniOn() ”public function checkPhpIniOn(string $name): boolChecks if PHP configuration option (from php.ini) is on.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Configuration option name. |
Returns
bool: Option is on.
checkUploadMaxFileSize()
Section titled “checkUploadMaxFileSize() ”public function checkUploadMaxFileSize(string|null $min = \null, string|null $max = \null): boolChecks if upload max file size matches the given range.
Parameters
| Parameter | Type | Description |
|---|---|---|
$min | string| | Verbose file size minimum required value, pass null to skip minimum check. |
$max | string| | Verbose file size maximum required value, pass null to skip maximum check. |
Returns
bool: Success.
checkYii()
Section titled “checkYii() ”public function checkYii(): YiiRequirementCheckerPerforms the check for the Yii core requirements.
Returns
YiiRequirementChecker: Self instance.
compareByteSize()
Section titled “compareByteSize() ”public function compareByteSize(string $a, string $b, string $compare = '>='): boolCompare byte sizes of values given in the verbose representation, like ‘5M’, ‘15K’ etc.
Parameters
| Parameter | Type | Description |
|---|---|---|
$a | string | First value. |
$b | string | Second value. |
$compare | string | Comparison operator, by default ’>=’. |
Returns
bool: Comparison result.
evaluateExpression()
Section titled “evaluateExpression() ”public function evaluateExpression(string $expression): mixedEvaluates a PHP expression under the context of this class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$expression | string | A PHP expression to be evaluated. |
Returns
mixed: The expression result.
getByteSize()
Section titled “getByteSize() ”public function getByteSize(string $verboseSize): intGets the size in bytes from verbose size representation.
For example: ‘5K’ => 5*1024
Parameters
| Parameter | Type | Description |
|---|---|---|
$verboseSize | string | Verbose size representation. |
Returns
int: Actual size in bytes.
getNowDate()
Section titled “getNowDate() ”public function getNowDate(): stringReturns the now date if possible in string representation.
Returns
string: Now date.
getResult()
Section titled “getResult() ”public function getResult(): array|nullReturn the check results.
Returns
array|null: Check results in format: 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()
Section titled “getServerInfo() ”public function getServerInfo(): stringReturns the server information.
Returns
string: Server information.
normalizeRequirement()
Section titled “normalizeRequirement() ”public function normalizeRequirement(array $requirement, int $requirementKey = 0): arrayNormalizes requirement ensuring it has correct format.
Parameters
| Parameter | Type | Description |
|---|---|---|
$requirement | array | Raw requirement. |
$requirementKey | int | Requirement key in the list. |
Returns
array: Normalized requirement.
render()
Section titled “render() ”public function render(): mixedRenders the requirements check result.
The output will vary depending is a script running from web or from console.
Returns
mixed
renderViewFile()
Section titled “renderViewFile() ”public function renderViewFile(string $_viewFile_, array|null $_data_ = \null, bool $_return_ = \false): string|nullRenders a view file.
This method includes the view file as a PHP script and captures the display result if required.
Parameters
| Parameter | Type | Description |
|---|---|---|
$_viewFile_ | string | View file |
$_data_ | array| | Data to be extracted and made available to the view file |
$_return_ | bool | Whether the rendering result should be returned as a string |
Returns
string|null: The rendering result. Null if the rendering result is not required.
usageError()
Section titled “usageError() ”public function usageError(string $message): mixedDisplays a usage error.
This method will then terminate the execution of the current application.
Parameters
| Parameter | Type | Description |
|---|---|---|
$message | string | The error message |
Returns
mixed