Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbretter/stk-immutable
immutable data objects for php
https://github.com/mbretter/stk-immutable
immutable php
Last synced: about 1 month ago
JSON representation
immutable data objects for php
- Host: GitHub
- URL: https://github.com/mbretter/stk-immutable
- Owner: mbretter
- License: bsd-3-clause
- Created: 2019-05-22T12:43:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-09T12:19:59.000Z (7 months ago)
- Last Synced: 2024-09-17T01:40:45.711Z (3 months ago)
- Topics: immutable, php
- Language: PHP
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# immutable data objects for php
[![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![PHP 8](https://img.shields.io/badge/php-8-yellow.svg)](http://www.php.net)
![CI](https://github.com/mbretter/stk-immutable/actions/workflows/ci.yml/badge.svg)
[![codecov](https://codecov.io/github/mbretter/stk-immutable/branch/master/graph/badge.svg?token=R1hyQHWr1U)](https://codecov.io/github/mbretter/stk-immutable)
[![Latest Stable Version](https://img.shields.io/packagist/v/mbretter/stk-immutable.svg)](https://packagist.org/packages/mbretter/stk-immutable)
[![Total Downloads](https://img.shields.io/packagist/dt/mbretter/stk-immutable.svg)](https://packagist.org/packages/mbretter/stk-immutable)This library implements the immutable design pattern for objects holding some kind of data.
## Maps
Maps can hold objects (stdClass) and/or arrays, they can be nested, very useful when reading/writing from/to
noSQL databases like MongoDB.```php
use Stk\Immutable\Map;$a = new Map((object)['x' => 'foo', 'y' => 'bar']);
$b = $a->set('x', 'whatever');
```Calling the set method on the object $a does not modify it, a clone with the modifications is returned instead,
the original Map will never be modified.Comparing two Maps is easy, there is no need for writing complicated and resource consuming comparision functions,
simply use the identical operator:```php
if ($a === $b) {
...
}
```