injector icon indicating copy to clipboard operation
injector copied to clipboard

Support PHP 8.4 lazy objects

Open roxblnfk opened this issue 11 months ago • 0 comments

I think it will be useful to have an ability to create lazy objects.

It might look like:

  1. New methods:

    class Injector {
        // ...
    
        public function makeGhost(string $class, array $arguments = []): object {}
    
        public function makeProxy(string $class, array $arguments = []): object {}
    }
    
  2. A new parameter of the make method

    enum Laziness {
        case Regular; // or Disable
        case Proxy;
        case Ghost;
    }
    
    class Injector {
        // ...
    
        public function make(string $class, array $arguments = [], Laziness $laziness = Laziness::Disable): object
    }
    
  3. A new option:

    $injector
        ->withLaziness(Laziness::Proxy)
        ->make(...)
    

    But in this case the option won't affect $injector->invoke() (does make sense?)

roxblnfk avatar Jan 22 '25 14:01 roxblnfk