This simple library allows you to wrap any kind of PHP variable in a strict typed PHP object.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
spec/drupol/valuewrapper
src
.editorconfig
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE
README.md
apigen.yml
appveyor.yml
composer.json
grumphp.yml.dist
infection.json.dist
phpbench.json.dist
phpspec.yml.dist

README.md

Latest Stable Version Total Downloads Build Status Build status Scrutinizer Code Quality Code Coverage Mutation testing badge License

ValueWrapper

Description

This library allows you to wrap PHP variable in a strict typed PHP object.

Documentation

API documentation is automatically generated with APIGen and available at this address.

Requirements

  • PHP >= 7.1

Installation

composer require drupol/valuewrapper

Usage

$string = 'Hello world!';
$value = ValueWrapper::create($string); // This creates a StringType object.

$integer = 123;
$value = ValueWrapper::create($integer); // 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.

Code quality and tests

Every time changes are introduced into the library, Travis CI run the tests.

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.

Contributing

Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)