thephpleague / container

Small but powerful dependency injection container

Home Page:http://container.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Cached factory delegate container

adrianmiu opened this issue · comments

This feature has started from the idea of combining the ReflectionContainer functionality with the self-discoverable factories (see issue #202 ). This is how it should work

This "CacheReflectionContainer" delegate container would use autoreflection to find the dependencies of an auto-wired class and would generate a file on disk containing a "Factory" class which can be auto-loaded. The end result would be a file like so:

namespace League\Container\AutowiredFactories;

class Factory_{sha1_of_the_class_name} implements Factory
{
   public function __invoke(ContainerInterface $container) {
       return new class_name($container->get('param1'), $container->get('param2');
   }
}

I’m currently working on a tool to compile a container, but that’s with explicit definitions and not with reflection.

It would be hard to compile the container with reflection anyway (you would most likely find false positives)

I wouldn’t be against linking to something from the docs though that could do this.

You mean linking to a third-party/community package? If so, that would be an endorsement and it would be hard to track its development

Closing this as work is ongoing on a compiler