\QuickApps\Core\Package\RuleRuleChecker

Checks that the given set of rules are meet.

Summary

Methods
Properties
Constants
__construct()
check()
pass()
fail()
cache()
dropCache()
No public properties found
No constants found
_pass()
_fail()
$_rules
$_fail
$_pass
$_checked
$_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_rules

$_rules : array

List of rules to check.

Type

array

$_fail

$_fail : array

List of rules marked as FAIL.

Type

array

$_pass

$_pass : array

List of rules marked as PASS.

Type

array

$_checked

$_checked : boolean

Whether rules were checked using check() or not.

Type

boolean

$_cache

$_cache : array

Used internally.

Type

array

Methods

__construct()

__construct(array $rules)

Constructor.

Basic usage:

$rules = [
    'php' => '5.3.*',
    'quickapps/cms' => '2.*',
];

$checker = new RuleChecker($rules);

if ($checker->check()) {
    // all OK
} else {
    // ERROR, get failing rules:
    $checker->fail();
}

Without invoking check():

You can also use pass() or fail() methods before invoking check() as in the example below.

$checker = new RuleChecker($rules);
$pass = $checker->pass();
$fail = $checker->fail();

Providing packages as objects:

$rules = [
    new MyPackage('vendor/package', '/path/to/package') => '1.3.*',
    'quickapps/cms' => '2.*',
];
}

Parameters

array $rules

A list of rules given as package => constraints, where the left hand side (package) can be either a string representing a package (as "vendor/package") or an object extending \QuickApps\Core\Package\BasePackage

check()

check() : boolean

Checks all the rules of this class.

Returns

boolean —

True if all rules are meet

pass()

pass(boolean $asString) : array|string

Gets all rules marked as PASS.

Parameters

boolean $asString

True will returns a comma separated string of rules

Returns

array|string

fail()

fail(boolean $asString) : array|string

Gets all rules marked as FAIL.

Parameters

boolean $asString

True will returns a comma separated string of rules

Returns

array|string

cache()

cache(null|string $key, mixed $value) : mixed

Reads, writes or search internal class's cache.

Usages:

  • When reading if no cache key is found NULL will be returned. e.g. $null = static::cache('invalid-key');
  • When writing, this method return the value that was written. e.g. $value = static::cache('key', 'value');
  • Set both arguments to NULL to read the whole cache content at the moment. e.g. $allCache = static::cache()
  • Set key to null and value to anything to find the first key holding the given value. e.g. $key = static::cache(null, 'search key for this value'), if no key for the given value is found NULL will be returned.

Examples:

Writing cache:

static::cache('user_name', 'John');
// returns 'John'

static::cache('user_last', 'Locke');
// returns 'Locke'

Reading cache:

static::cache('user_name');
// returns: John

static::cache('unexisting_key');
// returns: null

static::cache();
// Reads the entire cache
// returns: ['user_name' => 'John', 'user_last' => 'Locke']

Searching keys:

static::cache(null, 'Locke');
// returns: user_last

static::cache(null, 'Unexisting Value');
// returns: null

Parameters

null|string $key

Cache key to read or write, set both $key and $value to get the whole cache information

mixed $value

Values to write into the given $key, or null indicates reading from cache

Returns

mixed

dropCache()

dropCache(string|null $key) : void

Drops the entire cache or a specific key.

Usage:

static::dropCache('user_cache'); // removes "user_cache" only
static::dropCache(); // removes every key

Parameters

string|null $key

Cache key to clear, if NULL the entire cache will be erased.