PHPackages                             stvkoch/lazyresult - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. stvkoch/lazyresult

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stvkoch/lazyresult
==================

Proxy that Lazy call objects

027PHP

Since May 21Pushed 11y ago1 watchersCompare

[ Source](https://github.com/stvkoch/LazyResult)[ Packagist](https://packagist.org/packages/stvkoch/lazyresult)[ RSS](/packages/stvkoch-lazyresult/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

LazyResult
==========

[](#lazyresult)

LazyResult are proxy design that only call function of registered object when result expected interact with loop structures or when your code try access properties of result. Addicional you can configure before and after callbacks, for instance, to use cache manager results.

LazyResult can help your project in many ways, you can use LazyResult to manipulate caches, called to be late pre filters common action controllers.

\[[![Build Status LazyResult stvkoch by travis-ci](https://camo.githubusercontent.com/42189a585e144e442933847dc8b7fefccfa9040506a6b73c9d6b931a6673468f/68747470733a2f2f7472617669732d63692e6f72672f7374766b6f63682f4c617a79526573756c742e737667)](https://camo.githubusercontent.com/42189a585e144e442933847dc8b7fefccfa9040506a6b73c9d6b931a6673468f/68747470733a2f2f7472617669732d63692e6f72672f7374766b6f63682f4c617a79526573756c742e737667)\]

Example
-------

[](#example)

Proxy Lazy Call for one function or callback:

```
$lazyObject = new \Lazy\Result(array('Model', 'find'));
$lazyResult = $lazyObject(array('id'=>1)); //not run yeat
....
foreach($lazyResult as $value) { //in first interation find method is call!
    ....
}

```

Proxy Lazy Call object:

```
$lazyObject = new \Lazy\Result(array('Model'));
$lazyResult = $lazyObject->find(array('id'=>1)); //not run yeat
....
foreach($lazyResult as $value) { //in first interation find method is call!
    ....
}

```

Proxy Lazy Call object/or function with cache:

```
$lazyObject = new \Lazy\Result(array('Model'), array('Cache','get'), array('Cache','set'));
$lazyResult = $lazyObject->find(array('id'=>1)); //not run yeat
....
foreach($lazyResult as $value) { //in first interation find method is call! but before Cache::get is run, if Cache::get not return result 'find' method is run and after Cache::set with array('id'=>1) more $result
    ....
}

```

Way to access values from lazy result
=====================================

[](#way-to-access-values-from-lazy-result)

You can access the results from LazyResult object with interaction loop, with access properties of original result object or call result() method of LazyResult object.

```
class Model{
    static function words(){
        return 'LazyResult from model';
    }
    static function one($id){
        return (object) array('id'=>$id, 'name'=>'Steven Koch', 'country'=>'Portugal');
    }
    static function all(){
        return array(
            (object) array('id'=>'1', 'name'=>'Steven Koch', 'country'=>'Portugal'),
            (object) array('id'=>'2', 'name'=>'Joan Rodrigues', 'country'=>'France'),
            (object) array('id'=>'3', 'name'=>'Hans De Groot', 'country'=>'Netherlands')
        );
    }

}
//..
$lazyObject = new \Lazy\Result(array('Model'));
$lazyResult = $lazyObject->one(1); //not run yeat
echo $lazyResult->name; //now is call one on Model
//...
$lazyResult = $lazyObject->all(); //not run yeat
$arrayResult = $lazyResult->result(); //now is call one on Model
//or...
foreach($lazyResult as $item){
    echo $item->name;
}
//...
$lazyResult = $lazyObject->words(); //not run yeat
echo "".$lazyResult; //now is call one on Model and return result from __toString

```

Definition
==========

[](#definition)

```
[$object] new \Lazy\Result(array $callableLazy [, array $beforeCallableLazy] [, array $afterCallableLazy]);

```

$callableLazy
-------------

[](#callablelazy)

\\Lazy\\Result object registe $callableLazy to run when result() function is called. Inside of \\Lazy\\Result object result() public method run when initialize foreach loop structure.

$callableLazy receive parameters that you pass for you proxy object

Example:

```
$lazyFunc = function($param1, $param2){...};
$lazyObject = new \Lazy\Result($lazyFunc);
$lazyObject($param1, $param2);

```

$beforeCallableLazy
-------------------

[](#beforecallablelazy)

When definite, $beforeCallableLazy run before $callableLazy. This is useful if you like add cache manager for your results.

Interface that you need implemented for $beforeCallableLazy:

```
boolean $beforeCallableLazy(array $parameters, $callableLazy);

```

$afterCallableLazy
------------------

[](#aftercallablelazy)

When definite, $afterCallableLazy run after $callableLazy. This is useful if you like set your result on cache manager.

Interface that you need implemented for $afterCallableLazy:

```
boolean $afterCallableLazy(array $parameters, $callableLazy, array $resultByCallableLazy);

```

Functions
---------

[](#functions)

### result()

[](#result)

Result obejct function run callableLazy. When use resultLazy on loop structure, the loop structure run result funtion in first interation and receive values from callback. In some case you like call result() to receive lazy values from your callback or call callback withou loop structures.

Config global before and after callbacks
----------------------------------------

[](#config-global-before-and-after-callbacks)

Maybe you like configurate before and after callbacks to run each time the proxy call the lazy callback.

```
\Lazy\Result::$globalBeforeCallback = array('Cache', 'get');
\Lazy\Result::$globalAfterCallback = array('Cache', 'set');

```

Now all proxy create use this hooks callbacks.

Tests
=====

[](#tests)

phpunit .

Any question!

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a253d8327a33548a262e7a6a7cbe125f5828f123e5bb6c9799955ecfbd17c9fb?d=identicon)[stvkoch](/maintainers/stvkoch)

---

Top Contributors

[![stvkoch](https://avatars.githubusercontent.com/u/14454?v=4)](https://github.com/stvkoch "stvkoch (25 commits)")

### Embed Badge

![Health badge](/badges/stvkoch-lazyresult/health.svg)

```
[![Health](https://phpackages.com/badges/stvkoch-lazyresult/health.svg)](https://phpackages.com/packages/stvkoch-lazyresult)
```

###  Alternatives

[spiral/mcp-server

Spiral bridge for MCP server

541.1k2](/packages/spiral-mcp-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
