teknoo / immutable
Library to create PHP immutable object
Fund package maintenance!
Patreon
TeknooSoftware
Installs: 88 729
Dependents: 12
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
Requires (Dev)
- phploc/phploc: ^7.0.2
- phpstan/phpstan: ^1.4.6
- phpunit/phpunit: ^9.5.13
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^6.0.3
- squizlabs/php_codesniffer: ^3.6.2
This package is auto-updated.
Last update: 2022-04-24 12:37:48 UTC
README
This library helps you to create immutable object by prohibiting __set and __unset calls and several call to constructor
Quick Example
<?php
declare(strict_types=1);
include 'vendor/autoload.php';
$a = new class implements Teknoo\Immutable\ImmutableInterface {
use Teknoo\Immutable\ImmutableTrait;
private array $values = ['foo' => 123];
public function __get(string $name)
{
return $this->values[$name];
}
};
//Print 123
print $a->foo;
//Throws an Teknoo\Immutable\Exception\ImmutableException
$a->foo = 'bar';
//Throws an Teknoo\Immutable\Exception\ImmutableException;
unset($a->foo);
//Throws an Teknoo\Immutable\Exception\ImmutableException;
$a->__construct();
Support this project
This project is free and will remain free, but it is developed on my personal time. If you like it and help me maintain it and evolve it, don't hesitate to support me on Patreon. Thanks :) Richard.
Installation & Requirements
To install this library with composer, run this command :
composer require teknoo/immutable
This library requires :
* PHP 8.1+
News from Teknoo Immutable 3.0
This library requires PHP 8.1 or newer. Some changes cause bc breaks :
- Switch to readonly property to detect reconstructed object
News from Teknoo Immutable 2.0
This library requires PHP 7.4 or newer. Some changes cause bc breaks :
- PHP 7.4 is the minimum required
- Most methods have been updated to include type hints where applicable. Please check your extension points to make sure the function signatures are correct.
- Switch to typed properties _ All files use strict typing. Please make sure to not rely on type coercion.
- Remove some PHP useless DockBlocks
- Enable PHPStan in QA Tools and disable PHPMd
Credits
Richard Déloge - richarddeloge@gmail.com - Lead developer. Teknoo Software - http://teknoo.software
About Teknoo Software
Teknoo Software is a PHP software editor, founded by Richard Déloge. Teknoo Software's DNA is simple : Provide to our partners and to the community a set of high quality services or software, sharing knowledge and skills.
License
Immutable is licensed under the MIT License - see the licenses folder for details
Contribute :)
You are welcome to contribute to this project. Fork it on Github