HumHub Documentation (unofficial)

YiiRequirementChecker
in package

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!

Tags
author

Paul Klimov klimov.paul@gmail.com

since
2.0

Table of Contents

Properties

$result  : array<string|int, mixed>|null
$result  : Check

Methods

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

Properties

$result

public array<string|int, mixed>|null $result

the check results, this property is for internal usage only.

Methods

check()

Check the given requirements, collecting results into internal field.

public check(array<string|int, mixed>|string $requirements) : $this

This method can be invoked several times checking different requirement sets. Use [[getResult()]] or [[render()]] to get the results.

Parameters
$requirements : array<string|int, mixed>|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 values
$this

self instance.

checkPhpExtensionVersion()

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

public checkPhpExtensionVersion(string $extensionName, string $version[, string $compare = '>=' ]) : bool
Parameters
$extensionName : string

PHP extension name.

$version : string

required PHP extension version.

$compare : string = '>='

comparison operator, by default '>='

Return values
bool

if PHP extension version matches.

checkPhpIniOff()

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

public checkPhpIniOff(string $name) : bool
Parameters
$name : string

configuration option name.

Return values
bool

option is off.

checkPhpIniOn()

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

public checkPhpIniOn(string $name) : bool
Parameters
$name : string

configuration option name.

Return values
bool

option is on.

checkUploadMaxFileSize()

Checks if upload max file size matches the given range.

public checkUploadMaxFileSize([string|null $min = null ][, string|null $max = null ]) : bool
Parameters
$min : string|null = null

verbose file size minimum required value, pass null to skip minimum check.

$max : string|null = null

verbose file size maximum required value, pass null to skip maximum check.

Return values
bool

success.

compareByteSize()

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

public compareByteSize(string $a, string $b[, string $compare = '>=' ]) : bool
Parameters
$a : string

first value.

$b : string

second value.

$compare : string = '>='

comparison operator, by default '>='.

Return values
bool

comparison result.

evaluateExpression()

Evaluates a PHP expression under the context of this class.

public evaluateExpression(string $expression) : mixed
Parameters
$expression : string

a PHP expression to be evaluated.

Return values
mixed

the expression result.

getByteSize()

Gets the size in bytes from verbose size representation.

public getByteSize(string $verboseSize) : int

For example: '5K' => 5*1024

Parameters
$verboseSize : string

verbose size representation.

Return values
int

actual size in bytes.

getNowDate()

Returns the now date if possible in string representation.

public getNowDate() : string
Return values
string

now date.

getResult()

Return the check results.

public getResult() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|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()

Returns the server information.

public getServerInfo() : string
Return values
string

server information.

normalizeRequirement()

Normalizes requirement ensuring it has correct format.

public normalizeRequirement(array<string|int, mixed> $requirement[, int $requirementKey = 0 ]) : array<string|int, mixed>
Parameters
$requirement : array<string|int, mixed>

raw requirement.

$requirementKey : int = 0

requirement key in the list.

Return values
array<string|int, mixed>

normalized requirement.

render()

Renders the requirements check result.

public render() : mixed

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

renderViewFile()

Renders a view file.

public renderViewFile(string $_viewFile_[, array<string|int, mixed>|null $_data_ = null ][, bool $_return_ = false ]) : string|null

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

Parameters
$_viewFile_ : string

view file

$_data_ : array<string|int, mixed>|null = null

data to be extracted and made available to the view file

$_return_ : bool = false

whether the rendering result should be returned as a string

Return values
string|null

the rendering result. Null if the rendering result is not required.

usageError()

Displays a usage error.

public usageError(string $message) : mixed

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

Parameters
$message : string

the error message


        
On this page

Search results