D
D
dev4002016-05-15 01:42:09
PHP
dev400, 2016-05-15 01:42:09

Registry + Lazy Initialization?

If we (for example) put a bunch of our objects in LI, and as needed, the registry returns the LI object, through which we get the objects?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cold147, 2016-05-15
@cold147

The register contains code that can initialize the requested object at any time. after the first initialization, it will keep a reference to the object and return it on subsequent requests

class Registry() 
{
    public function get($serviceId)
    {
        return isset($this->services[$serviceId]) ? $this->services[$serviceId] : $this->initializeService($serviceId);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question