This simple library allows you to wrap any kind of PHP variable in a strict typed PHP object.
- PHP >= 7.1
composer require drupol/valuewrapper
$string = 'Hello world!';
$value = ValueWrapper::create($string); // This creates a StringType object.
$integer = 123;
$value = ValueWrapper::create($string); // This creates an IntegerType object.
$closure = function (string $who) {return 'Hello ' . $who;};
$value = ValueWrapper::create($closure); // This creates a ClosureObject object.
$value('world'); // Return 'Hello world'.
$value->hash(); // Return '513c4a7d0c1e07fa75e40c842880c82cffa69c5d'.
$anotherClosure = function () {return 'Hello world';};
$anotherValue = ValueWrapper::create($anotherClosure);
$value->equals($anotherValue); // Return false.
$sameClosure = function (string $who) {return 'Hello ' . $who;};
$sameValue = ValueWrapper::create($sameClosure);
$value->equals($sameValue); // Return true.
Every time changes are introduced into the library, Travis CI run the tests and the benchmarks.
The library has tests written with PHPSpec.
Feel free to check them out in the spec
directory. Run composer phpspec
to trigger the tests.
PHPInfection is used to ensure that your code is properly tested, run composer infection
to test your code.
Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)