PHPackages                             golossus/php-lazy-proxy-loading - 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. golossus/php-lazy-proxy-loading

ActiveLibrary

golossus/php-lazy-proxy-loading
===============================

Provides a proxy class factory to load services in a lazy and seamless way

v1.0.2(5y ago)44.3k[1 issues](https://github.com/golossus/php-lazy-proxy-loading/issues)MITPHPPHP &gt;=7.1

Since Jan 8Pushed 5y ago2 watchersCompare

[ Source](https://github.com/golossus/php-lazy-proxy-loading)[ Packagist](https://packagist.org/packages/golossus/php-lazy-proxy-loading)[ RSS](/packages/golossus-php-lazy-proxy-loading/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/b8e31ee3361b023b90db8cdc047fba6e647ea1a901a4ad9e2233383683b961c2/68747470733a2f2f6170692e7472617669732d63692e6f72672f676f6c6f737375732f7068702d6c617a792d70726f78792d6c6f6164696e672e7376673f6272616e63683d6d61696e)](https://api.travis-ci.org/golossus/php-lazy-proxy-loading)[![codecov](https://camo.githubusercontent.com/416c5c7a3c135f57200fb7c9733cf6c2e594cf0fa2ac1c16c913b4996b469c1e/68747470733a2f2f636f6465636f762e696f2f67682f676f6c6f737375732f7068702d6c617a792d70726f78792d6c6f6164696e672f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d365a464a444e504c3453)](https://codecov.io/gh/golossus/php-lazy-proxy-loading)[![Version](https://camo.githubusercontent.com/4fbaad61487e09f1047e9e9e545d4cdb1d63bffcc655b7d356d1858bfd9c4d89/68747470733a2f2f706f7365722e707567782e6f72672f676f6c6f737375732f7068702d6c617a792d70726f78792d6c6f6164696e672f76657273696f6e)](//packagist.org/packages/golossus/php-lazy-proxy-loading)[![Total Downloads](https://camo.githubusercontent.com/48ca947dcacad4e431c989a5282cee037ddaea52eaa44a16e6a46aec3583243f/68747470733a2f2f706f7365722e707567782e6f72672f676f6c6f737375732f7068702d6c617a792d70726f78792d6c6f6164696e672f646f776e6c6f616473)](//packagist.org/packages/golossus/php-lazy-proxy-loading)[![License](https://camo.githubusercontent.com/2d0cbca383e02b47ce3eb18055268331d2fa9ca7f5e1a677506a711970586c5d/68747470733a2f2f706f7365722e707567782e6f72672f676f6c6f737375732f7068702d6c617a792d70726f78792d6c6f6164696e672f6c6963656e7365)](//packagist.org/packages/golossus/php-lazy-proxy-loading)

 [ ![](https://avatars2.githubusercontent.com/u/58183018) ](https://www.golossus.com)

[php-lazy-proxy-loading](https://github.com/golossus/php-lazy-proxy-loading) is a package which tries to ease in the process of loading PHP classes (or services) by using a lazy strategy. This comes in handy when working with Dependency Injection containers which are in charge of building the services of many applications.

This package does so by providing a [Proxy Class Factory](./lib/ProxyClassFactory.php) which can create a Proxy Class for any PHP Class or service. Real service is only built when the service is really needed, that is at first call of its public methods.

It is specially interesting to combine this library with Laravel framework, given the fact that currently there's no a bult-in strategy in this framework to provide lazy-loading of services. We started this library in order to solve Dependency Injection issues we had using Laravel that could be solver very easily by lazy-loading some services.

Installation
------------

[](#installation)

```
composer require golossus/php-lazy-proxy-loading
```

Usage
-----

[](#usage)

Basic usage example:

```
use Golossus\LazyProxyLoading\ProxyClassFactory;
...
$myClassProxy = ProxyClassFactory::create(\MyClass::class, function () {
    return new \MyClass(/* dependencies */);
});
```

It's worth noting in the above example `$myClassProxy` extends `MyClass` type, and it serves as an adapter behaving as the underlying service, so it can be injected seamlessly as the real service. Final service will be built once we call any of its public methods by using the callback function passed as second argument of the `ProxyClassFactory::create`method.

```
echo $myProxyClass->myClassPrublicMethod(); // MyClass service is created at this point
echo $myProxyClass->myClassPrublicMethod(); // MyClass service is already created at this point, so it's not re-built
```

### Laravel

[](#laravel)

For Laravel framework, this package provides a special [trait](./lib/LaravelLazyLoadingTrait.php) to seamlessly use the proxy factory with its Dependency Injection container. You can `use` the trait in any Laravel service provider and define any service as `lazy`:

```
..
use Illuminate\Support\ServiceProvider;
use Golossus\LazyProxyLoading\LazyLoadingTrait;
..

class MainProvider extends ServiceProvider
{
    use LazyLoadingTrait;

    public function register()
    {
        // common laravel service registration, not lazy
        $this->app->singleton(CustomMailingService::class, function () {
                $mailer = $this->app->make(Mailer::class);
                return new CustomMailingService($mailer);
            }
        );

        // or same service registration but lazy loaded
        $this->app->singleton(...$this->lazy(CustomMailingService::class, function () {
                $mailer = $this->app->make(Mailer::class);

                return new CustomMailingService($mailer);
            }
        ));
    }
}
```

Community
---------

[](#community)

- Join our [Slack](https://join.slack.com/t/golossus/shared_invite/zt-db4brnes-M8q1Lw2ouFT5X~gQg69NQQ) to meet the community and get support.
- Follow us on [GitHub](https://github.com/golossus).
- Read our [Code of Conduct](./CODE_OF_CONDUCT.md).

Contributing
------------

[](#contributing)

This is an Open Source project. The Golossus team wants to enable it to be community-driven and open to [contributors](./CONTRIBUTORS.md). Take a look at [contributing documentation](./CONTRIBUTING.md).

Security Issues
---------------

[](#security-issues)

If you discover a security vulnerability, please follow our [disclosure procedure](./CONTRIBUTING.md#reporting-a-security-issue).

About Us
--------

[](#about-us)

This package development is led by the Golossus Team [Leaders](./CONTRIBUTING.md#leaders) and supported by [contributors](./CONTRIBUTORS.md).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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.

###  Release Activity

Cadence

Every ~5 days

Total

3

Last Release

1945d ago

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/4212c7a4080bc9bfbda7b7aaa58d48b3f77011c65b9237c21e3194a230a1927a?d=identicon)[jorbriib](/maintainers/jorbriib)

---

Top Contributors

[![jorbriib](https://avatars.githubusercontent.com/u/2605839?v=4)](https://github.com/jorbriib "jorbriib (4 commits)")[![sangarbe](https://avatars.githubusercontent.com/u/10627477?v=4)](https://github.com/sangarbe "sangarbe (4 commits)")

---

Tags

laravellazy-loadingphpproxyphplaravelproxylazyloading

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/golossus-php-lazy-proxy-loading/health.svg)

```
[![Health](https://phpackages.com/badges/golossus-php-lazy-proxy-loading/health.svg)](https://phpackages.com/packages/golossus-php-lazy-proxy-loading)
```

###  Alternatives

[octw/aramex

A Library to integrate with Aramex APIs

2925.2k](/packages/octw-aramex)[behamin/service-proxy

for proxy or sending requests to other services with useful utilities

102.2k](/packages/behamin-service-proxy)

PHPackages © 2026

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