Skip to content
PHP Ecosystem
Explore

YiiRequirementChecker

API reference › Global namespace › YiiRequirementChecker

classYiiRequirementChecker
Since2.0
Sourceframework/requirements/YiiRequirementChecker.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 intentionally keeps a conservative standalone style for compatibility with requirement-check bootstrap environments.

PropertyTypeDescriptionDefined by
$resultarray|nullThe check results, this property is for internal usage only. Default: null.YiiRequirementChecker
MethodDescriptionDefined 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
public function check(array|string $requirements): $this

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.

Parameters

ParameterTypeDescription
$requirementsarray|stringRequirements 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.

public function checkPhpExtensionVersion(string $extensionName, string $version, string $compare = '>='): bool

Checks if the given PHP extension is available and its version matches the given one.

Parameters

ParameterTypeDescription
$extensionNamestringPHP extension name.
$versionstringRequired PHP extension version.
$comparestringComparison operator, by default ’>=’

Returns

bool: If PHP extension version matches.

public function checkPhpIniOff(string $name): bool

Checks if PHP configuration option (from php.ini) is off.

Parameters

ParameterTypeDescription
$namestringConfiguration option name.

Returns

bool: Option is off.

public function checkPhpIniOn(string $name): bool

Checks if PHP configuration option (from php.ini) is on.

Parameters

ParameterTypeDescription
$namestringConfiguration option name.

Returns

bool: Option is on.

public function checkUploadMaxFileSize(string|null $min = \null, string|null $max = \null): bool

Checks if upload max file size matches the given range.

Parameters

ParameterTypeDescription
$minstring|nullVerbose file size minimum required value, pass null to skip minimum check.
$maxstring|nullVerbose file size maximum required value, pass null to skip maximum check.

Returns

bool: Success.

public function checkYii(): YiiRequirementChecker

Performs the check for the Yii core requirements.

Returns

YiiRequirementChecker: Self instance.

public function compareByteSize(string $a, string $b, string $compare = '>='): bool

Compare byte sizes of values given in the verbose representation, like ‘5M’, ‘15K’ etc.

Parameters

ParameterTypeDescription
$astringFirst value.
$bstringSecond value.
$comparestringComparison operator, by default ’>=’.

Returns

bool: Comparison result.

public function evaluateExpression(string $expression): mixed

Evaluates a PHP expression under the context of this class.

Parameters

ParameterTypeDescription
$expressionstringA PHP expression to be evaluated.

Returns

mixed: The expression result.

public function getByteSize(string $verboseSize): int

Gets the size in bytes from verbose size representation.

For example: ‘5K’ => 5*1024

Parameters

ParameterTypeDescription
$verboseSizestringVerbose size representation.

Returns

int: Actual size in bytes.

public function getNowDate(): string

Returns the now date if possible in string representation.

Returns

string: Now date.

public function getResult(): array|null

Return 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, ), … ), )

public function getServerInfo(): string

Returns the server information.

Returns

string: Server information.

public function normalizeRequirement(array $requirement, int $requirementKey = 0): array

Normalizes requirement ensuring it has correct format.

Parameters

ParameterTypeDescription
$requirementarrayRaw requirement.
$requirementKeyintRequirement key in the list.

Returns

array: Normalized requirement.

public function render(): mixed

Renders the requirements check result.

The output will vary depending is a script running from web or from console.

Returns

mixed

public function renderViewFile(string $_viewFile_, array|null $_data_ = \null, bool $_return_ = \false): string|null

Renders a view file.

This method includes the view file as a PHP script and captures the display result if required.

Parameters

ParameterTypeDescription
$_viewFile_stringView file
$_data_array|nullData to be extracted and made available to the view file
$_return_boolWhether the rendering result should be returned as a string

Returns

string|null: The rendering result. Null if the rendering result is not required.

public function usageError(string $message): mixed

Displays a usage error.

This method will then terminate the execution of the current application.

Parameters

ParameterTypeDescription
$messagestringThe error message

Returns

mixed