djthossi / ensure
Some PHP Traits for ensuring values
1.2.0
2017-01-25 13:43 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ~5.7
This package is auto-updated.
Last update: 2026-03-01 00:22:52 UTC
README
Some PHP Traits for ensuring values
How it works
The provided Ensure Traits will test if provided $valueToTest has expected value.
- If
$valueToTestis valid nothing happens - If
$valueToTestis invalidInvalidValueExceptionis thrown
Available Ensure Traits
- EnsureIsBooleanTrait
- EnsureIsGreaterThanTrait
- EnsureIsIntegerTrait
- EnsureIsLowerThanTrait
- EnsureIsNotEmptyTrait
- EnsureIsStringTrait
- EnsureIsUrlTrait
How to install
You have several options to install this package
Composer
composer require djthossi/ensure
Git
git clone https://github.com/DjThossi/Ensure.git
Download
https://github.com/DjThossi/Ensure/archive/master.zip
Example
class Message { use EnsureIsStringTrait; const MESSAGE_IS_NOT_A_STRING = 1; /** * @param string $message */ public function __construct($message) { $this->ensureIsString('Message', $message, self::MESSAGE_IS_NOT_A_STRING); } }