zendframework / zend-servicemanager

ServiceManager component from Zend Framework
BSD 3-Clause "New" or "Revised" License
188 stars 89 forks source link

Warmup lazy services #278

Open snapshotpl opened 5 years ago

snapshotpl commented 5 years ago

Hi there!

I would like to generate all proxies before app deployment (like doctrine has orm:generate-proxies). Some host services (like Heroku) require to do this during "compile" process. Sure, generate on-demain works, but there is many cases when cache is purge.

Ocramius commented 5 years ago

This is only currently possible by running through the instantiation of all services once, in a warmup script.

snapshotpl commented 5 years ago

So I need to write this script or it exists somewhere?

Ocramius commented 5 years ago

You'll need to write a script, yup.

I think its contents would be something like array_walk([$serviceManager, 'get'], $serviceManager->getDefinedServices()) or similar

On Thu, 14 Feb 2019, 09:55 Witold Wasiczko <notifications@github.com wrote:

So I need to write this script or it exists somewhere?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zendframework/zend-servicemanager/issues/278#issuecomment-463545608, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakJdt0x1GZA58nvHJgPTLHbTvdJoWks5vNSSSgaJpZM4a7FkL .

snapshotpl commented 5 years ago

Or:

    public function warmup(): void
    {
        foreach ($this->services as $service) {
            $this->container->get($service);
        }
    }

where services is lazy_services.class_map keys.

Anyway ready script in package will be nice addon

Ocramius commented 5 years ago

Don't think we should expand the API for an edge case, and adding a script also requires knowing which instance of the ServiceManager you are referring to.

In a zendframework/zend-mvc context, that may be any of the plugin containers, for example.

On Thu, 14 Feb 2019, 10:06 Witold Wasiczko <notifications@github.com wrote:

Or:

public function warmup(): void    {        foreach ($this->services as $service) {            $this->container->get($service);        }    }

where services' is lazy_services.class_map` keys.

Anyway ready script in package will be nice addon

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zendframework/zend-servicemanager/issues/278#issuecomment-463548685, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakCtLHTLTFvUbctEJEk7djF75cLz_ks5vNSb7gaJpZM4a7FkL .

snapshotpl commented 5 years ago

Or zf module ;)

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-servicemanager; a new issue has been opened at https://github.com/laminas/laminas-servicemanager/issues/5.