adamwathan/faktory

View on GitHub
src/Factory/FactoryProxy.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php namespace AdamWathan\Faktory\Factory;

class FactoryProxy
{
    protected $factory_loader;
    protected $instance;

    public function __construct($factory_loader)
    {
        $this->factory_loader = $factory_loader;
    }

    protected function getInstance()
    {
        if (! isset($this->instance)) {
            $this->instance = $this->factory_loader->__invoke();
        }
        return $this->instance;
    }

    public function __call($method, $parameters)
    {
        $instance = $this->getInstance();
        return call_user_func_array([$instance, $method], $parameters);
    }
}