dev-master
9999999-devSafe-conducts for your PHP. Kills up to 99.9% of bad arguments.
AGPLv3
The Requires
- php >=5.4
The Development Requires
guard conditions
Wallogit.com
2017 © Pedro Peláez
Safe-conducts for your PHP. Kills up to 99.9% of bad arguments.
Safe-conducts for your PHP. Kills up to 99.9% of bad arguments., (*2)
WIP., (*3)
function add($a, $b)
{
\Guard\Conditions::requires($a, 'a')->isNumeric();
\Guard\Conditions::requires($b, 'b')->isNumeric();
return $a + $b;
}
add(1, 2);
add('string', 2);
# => \Guard\Exception\ConditionEvaluationException(
# 'The condition "isNumeric" for argument "a" failed to evaluate.',
# \Guard\Exception\InvalidArgumentException(
# 'The value "\'string\'" is not numeric.'
# )
# )
# Run this in your terminal to get the latest Composer version:
$ curl -sS https://getcomposer.org/installer | php
# ...or if you don't have cURL:
$ php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
# Add Guard as a dependency:
$ php composer.phar require 'stan-angeloff/guard'
After installing, you need to require Composer's autoloader file:, (*4)
require 'vendor/autoload.php';
To enforce conditions on your arguments, use:, (*5)
\Guard\Conditions::requires($value, $argumentName)
->condition1()
->condition2('option, e.g., interface name');
where $value is the argument value and $argumentName is the argument name (see example above). Conditions can be chained., (*6)
instanceOf($className), (*7)
Throws an exception if the value is not an object or an instance of the expected $className., (*8)
isNotNull(), (*9)
Throws an exception if the value is NULL (empty values are allowed, e.g., an empty string '')., (*10)
isNumeric(), (*11)
Throws an exception if the value is not numeric., (*12)
typeOf($internalType), (*13)
Throws an exception if the type of the value is not the expected one., (*14)
See gettype for a full list of possible types., (*15)
LICENSE.AGPL-3.0, (*16)
Safe-conducts for your PHP. Kills up to 99.9% of bad arguments.
AGPLv3
guard conditions