php-extended / php-ensure
A library to safely convert pointers to the right data type
Requires
- php: >=7.0
- php-extended/php-inspect: ^2
README
A library to safely convert pointers to the right data type
Installation
The installation of this library is made via composer.
Download composer.phar
from their website.
Then add to your composer.json :
"require": {
...
"php-extended/php-ensure": "^5",
...
}
Then run php composer.phar update
to install this library.
The autoloading of all classes of this library is made through composer's autoloader.
Basic Usage
This class provides multiple methods isSomething
to ensure that the given
data is with the right type. Those methods checks whether the given variable is
the right type and return true or false in silent mode. On normal mode, they
will throw an exception if the value is not the right type.
This class also provides multiple methods toSomething
to ensure that the
given data is convertible to the right type. Those method, on silent mode will
try to convert the give value to the appropriate type, and if they cannot,
throw an exception. On normal mode, they will throw an exception if the value
is not convertible.
Note that those methods allow null as any type, unless the toSomethingNotNull
methods are called.
This class does not provides method for asserting if something is true, only methods that provides the right type of object as much as possible.
License
MIT (See license file).