Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carlosv2/communism
communism
https://github.com/carlosv2/communism
Last synced: 2 months ago
JSON representation
communism
- Host: GitHub
- URL: https://github.com/carlosv2/communism
- Owner: carlosV2
- License: mit
- Created: 2016-12-12T00:30:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-13T19:13:10.000Z (almost 8 years ago)
- Last Synced: 2024-11-13T22:24:17.878Z (2 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Communism
Little utility to easily extract and inject properties from objects.
[![License](https://poser.pugx.org/carlosv2/communism/license)](https://packagist.org/packages/carlosv2/communism)
[![Build Status](https://travis-ci.org/carlosV2/Communism.svg?branch=master)](https://travis-ci.org/carlosV2/Communism)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/21d88d25-be98-4e8c-86bd-8762b4ebb039/mini.png)](https://insight.sensiolabs.com/projects/21d88d25-be98-4e8c-86bd-8762b4ebb039)## Usage
If you want to extract any object property, use one of the following constructions:
```php
$value = From($object)->property;
// or
$value = From($object)->extract('property');
```If you want to inject any object property, use one of the following constructions:
```php
To($object)->property = $value;
// or
To($object)->inject('property', $value);
```If you want to replace any object property, use one of the following constructions:
```php
// 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:```bash
$ composer require --dev carlosv2/communism
```This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.