Feature #43819

Support lazy dependency injection of properties

Added by Christopher Hlubek almost 7 years ago. Updated over 6 years ago.

Status:
Resolved
Priority:
Should have
Category:
-
Target version:
-
Start date:
2012-12-09
Due date:
% Done:

100%

PHP Version:
Has patch:
No
Complexity:

Description


<?php
namespace Test;

class SomeDependency {

    public function __construct() {
        echo "Construct SomeDependency\n";
    }

    public function foo() {
        echo "Foo called\n";
    }

}

class LazyProxy_Original {

    //
    // /**
    //  * @Flow\Inject(lazy=true)
    //  * @var \Test\SomeDependency
    //  */
    // protected $someProperty;

    public function doSomething() {
        for ($i = 0; $i < 4; $i++) {
            $this->someDependency->foo();
        }
        // $this->fooBar->unknown();
    }

}

class LazyProxy extends LazyProxy_Original {

    public function __construct() {
        echo "Construct LazyProxy\n";
    }

    function __get($name) {
        echo "LazyProxy get($name)\n";
        switch ($name) {
            case 'someDependency':
                $object = new SomeDependency();
                break;
            default:
                trigger_error(
                    'Undefined property via __get(): ' . $name,
                    E_USER_NOTICE);
                return NULL;
        }
        $this->{$name} = $object;
        return $object;
    }

}

$lazy = new LazyProxy();
$lazy->doSomething();

?>

Related issues

Related to TYPO3 Core - Feature #48960: Extbase: Backport lazy dependency injection Rejected 2013-06-08

Associated revisions

Revision ff8608f1 (diff)
Added by Robert Lemke over 6 years ago

[!!!][FEATURE] Lazy Dependency Injection

This introduces lazy dependency injection for dependencies injected
through Property Injection. Instead of loading the respective class
and instantiating the dependency right away, a proxy object is
injected which automatically replaces itself with the real dependency
once a method is called on it.

The @Inject annotation now accepts an optional argument "lazy" which
allows for turning off lazy dependency injection in specific cases.

Please read the new section in the Object Management chapter of
the Flow manual, included in this change set.

Change-Id: Ia61e40708cdb3d00210df9a5630e64aa8f89b82a
Resolves: #43819
Releases: master, 2.0

Revision 7e03bb9e (diff)
Added by Robert Lemke over 6 years ago

[!!!][FEATURE] Lazy Dependency Injection

This introduces lazy dependency injection for dependencies injected
through Property Injection. Instead of loading the respective class
and instantiating the dependency right away, a proxy object is
injected which automatically replaces itself with the real dependency
once a method is called on it.

The @Inject annotation now accepts an optional argument "lazy" which
allows for turning off lazy dependency injection in specific cases.

Please read the new section in the Object Management chapter of
the Flow manual, included in this change set.

Change-Id: Ia61e40708cdb3d00210df9a5630e64aa8f89b82a
Resolves: #43819
Releases: master, 2.0

Revision e2b1413a (diff)
Added by Robert Lemke over 6 years ago

[!!!][FEATURE] Lazy Dependency Injection

This introduces lazy dependency injection for dependencies injected
through Property Injection. Instead of loading the respective class
and instantiating the dependency right away, a proxy object is
injected which automatically replaces itself with the real dependency
once a method is called on it.

The @Inject annotation now accepts an optional argument "lazy" which
allows for turning off lazy dependency injection in specific cases.

Please read the new section in the Object Management chapter of
the Flow manual, included in this change set.

Change-Id: Ia61e40708cdb3d00210df9a5630e64aa8f89b82a
Resolves: #43819
Releases: master, 2.0

History

#1 Updated by Gerrit Code Review over 6 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#2 Updated by Gerrit Code Review over 6 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#3 Updated by Gerrit Code Review over 6 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#4 Updated by Gerrit Code Review over 6 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#5 Updated by Gerrit Code Review over 6 years ago

Patch set 5 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#6 Updated by Gerrit Code Review over 6 years ago

Patch set 6 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#7 Updated by Gerrit Code Review over 6 years ago

Patch set 7 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#8 Updated by Gerrit Code Review over 6 years ago

Patch set 8 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#9 Updated by Gerrit Code Review over 6 years ago

Patch set 9 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#10 Updated by Gerrit Code Review over 6 years ago

Patch set 10 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/18917

#11 Updated by Anonymous over 6 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#12 Updated by Gerrit Code Review over 6 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch 2.0 has been pushed to the review server.
It is available at https://review.typo3.org/19099

#13 Updated by Gerrit Code Review over 6 years ago

Patch set 1 for branch composer has been pushed to the review server.
It is available at https://review.typo3.org/19362

#14 Updated by Anonymous over 6 years ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF