clippings/freezable

Freeze values in objects

0.3.0 2020-02-11 10:33 UTC

This package is auto-updated.

Last update: 2020-07-21 21:06:34 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Latest Unstable Version Total Downloads License

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.