2017 © Pedro Peláez
 

yii2-extension yii2-lazy

implementation pattern design 'lazy load' for components of yii2

image

iluhansk/yii2-lazy

implementation pattern design 'lazy load' for components of yii2

  • Sunday, April 30, 2017
  • by iluhansk
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii2-lazy

implementation pattern design "lazy load" for components of yii2, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist iluhansk/yii2-lazy "*"

or add, (*4)

"iluhansk/yii2-lazy": "*"

to the require section of your composer.json file., (*5)

Usage

Add LazyBehavior to target class and define methods corresponding lazy properties:, (*6)

namespace common\components;

use \yii\base\Component;
use iluhansk\renderer\LazyBehavior;

/**
 * @property int $passengersCount Count of passengers in the car
 */
class Car extends Component {

    public function behaviors() {
        return [
            'lazy' => [
                'class' => LazyBehavior::className()
            ],
        ];
    }

    public function lazy_passengersCount() {
        //some logic here, for example:
        return rand(1,4);
    }

}

And use lazy property in any place:, (*7)

use common\components\Car;

echo "PassengersCount first call: $o->passengersCount
"; //first use lazy property will call lazy_passengersCount method of object echo "PassengersCount second call: $o->passengersCount
"; //this will return stored value (and not call lazy_passengersCount method again)

The Versions

30/04 2017

dev-master

9999999-dev

implementation pattern design 'lazy load' for components of yii2

  Sources   Download

GPL-3.0+

The Requires

 

by Ilya Perfilyev

extension yii2 property properties lazy lazyload lazy load lazy property lazy properties

30/04 2017

v1.0.0

1.0.0.0

implementation pattern design 'lazy load' for components of yii2

  Sources   Download

GPL-3.0+

The Requires

 

by Ilya Perfilyev

extension yii2 property properties lazy lazyload lazy load lazy property lazy properties