php-extended/php-ensure

This package is abandoned and no longer maintained. The author suggests using the php-extended/php-ensurer-object package instead.

A library to safely convert pointers to the right data type

5.0.1 2020-02-20 22:53 UTC

This package is auto-updated.

Last update: 2020-08-18 06:55:38 UTC


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).