php-extended/php-ensurer-object

An implementation of the php-ensure-interface library

4.0.0 2022-05-31 08:10 UTC

README

An implementation of the php-ensure-interface library.

coverage build status

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-ensurer-object": "^3",
		...
	}

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

You may use this class the following way :


use PhpExtended\Ensurer\NotNullLooseEnsurer;

$ensurer = new LooseEnsurer(); // alternatively new StrictEnsurer();

$ensurer->asBoolean(1); // return true
$ensurer->asString(null); // returns ""
$ensurer->asObjectOf(new \DateTime(), \DateTime::class); // returns the object
$ensurer->asObjectOf(new \DateTime(), Foo::class); // throws \InvalidArgumentException

License

MIT (See license file).