Feature #43819
Support lazy dependency injection of properties
Status: | Resolved | Start date: | 2012-12-09 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Christopher Hlubek | % Done: | 100% |
|
Category: | - | |||
Target version: | - | |||
PHP Version: | Complexity: | |||
Has patch: | No |
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
Associated revisions
[!!!][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
[!!!][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
[!!!][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 2 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 2 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 2 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 2 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 2 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 2 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 2 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 2 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 2 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 2 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 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset ff8608f1c296d7cfe8865e629f6d0cdf07a67e61.
#12 Updated by Gerrit Code Review over 2 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 2 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 2 years ago
- Status changed from Under Review to Resolved
Applied in changeset e2b1413afaa02c35d0b65965e2d64ab9cfcdd8cb.