Feature #43819

Support lazy dependency injection of properties

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

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

100%

Estimated time:
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 injectionRejectedMarc Bastian Heinrichs2013-06-08

Actions
#1

Updated by Gerrit Code Review over 7 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 7 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 7 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 7 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 7 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 7 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 7 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 7 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 7 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 7 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 7 years ago

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

Updated by Gerrit Code Review over 7 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 7 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 7 years ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF