clippings / freezable
Freeze values in objects
Installs: 98 953
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 28
Forks: 0
Open Issues: 0
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-11-22 06:50:41 UTC
README
Freeze values in objects
Requires PHP 5.4 or above.
Usage
<?php use Clippings\Freezable\FreezableTrait; class Item { use FreezableTrait; private $value = NULL; public function performFreeze() { $this->value = $this->computeValue(); } public function performUnfreeze() { $this->value = NULL; } private function computeValue() { // computation from external sources, database, other objects etc. return pi() * pi(); } public function getValue() { return $this->isFrozen() ? $this->value : $this->computeValue(); } }
License
Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin & Haralan Dobrev
Under BSD-3-Clause license, read LICENSE file.