carlosv2 / communism
Little utility to easily extract and inject properties from objects
Installs: 3 326
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ~5.3 || ~7.0
Requires (Dev)
- phpspec/phpspec: ~2.5.5
This package is not auto-updated.
Last update: 2024-11-09 21:17:04 UTC
README
Little utility to easily extract and inject properties from objects.
Usage
If you want to extract any object property, use one of the following constructions:
$value = From($object)->property; // or $value = From($object)->extract('property');
If you want to inject any object property, use one of the following constructions:
To($object)->property = $value; // or To($object)->inject('property', $value);
If you want to replace any object property, use one of the following constructions:
// The `replace` method is avilable for both `From` and `To` From($object)->property(function ($value) { // `$value` will contain the current value for that property // Whatever is returned will be the new value of the property return $newValue; }); // or From($object)->replace('property', function ($value) { // `$value` will contain the current value for that property // Whatever is returned will be the new value of the property return $newValue; });
Both functions From
and To
instantiate a carlosV2\Communism\Communist
object which
allows the extraction and injection of properties.
Words of wisdom
This project is designed to be used for development environment only. If you find yourself using this project on production code, you should better reconsider your architecture.
Install
Open a command console, enter your project directory and execute the following command to download the latest stable version of this project:
$ composer require --dev carlosv2/communism
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.