Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] Support getter-based dependency injection #20657

Copy link
Copy link
Closed
@nicolas-grekas

Description

@nicolas-grekas
Issue body actions

A concept well described in e.g. this thread:
http://www.theserverside.com/news/thread.tss?thread_id=26205
and also in #835

Basically, one could then be able override the getConnection method of such a class:

class foo {
// ...
    public/protected function getConnection()
    {
        return new FooDefaultConnection();
    }
}

with a generated proxy ($this->container auto-injected by some to-be-defined mean):

class extends foo {
    private $container;

    public/protected function getConnection()
    {
        return $this->container('connection_for_foo'):
    }
}

in XML, this could defined with something like e.g.:

<service id="foo" class="foo">
<getter name="getConnection" type="service" id="connection_for_foo" />
</service>

so that $container->get('foo') returns an instance of the generated class (and by this mean an instance of foo of course).

The benefits?

  • Lazyness made simple and almost free! I may give it a try;
  • immutability (if no corresponding setter exists of course)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DependencyInjectionRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.