mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Fixed bug that the private property which injected by parent class does not exists in class.
This commit is contained in:
parent
d3690a58d7
commit
4f1134890f
@ -8,6 +8,7 @@
|
||||
|
||||
- [#3380](https://github.com/hyperf/hyperf/pull/3380) Fixed bug that super globals does not work when request don't persist to context.
|
||||
- [#3394](https://github.com/hyperf/hyperf/pull/3394) Fixed bug that the injected property will be replaced by injected property defined in trait.
|
||||
- [#3395](https://github.com/hyperf/hyperf/pull/3395) Fixed bug that the private property which injected by parent class does not exists in class.
|
||||
|
||||
# v2.1.10 - 2021-03-15
|
||||
|
||||
|
@ -54,7 +54,7 @@ trait PropertyHandlerTrait
|
||||
$parentReflectionClass = $reflectionClass;
|
||||
while ($parentReflectionClass = $parentReflectionClass->getParentClass()) {
|
||||
$parentClassProperties = ReflectionManager::reflectPropertyNames($parentReflectionClass->getName());
|
||||
$parentClassProperties = array_filter($parentClassProperties, static function($property) use ($reflectionClass){
|
||||
$parentClassProperties = array_filter($parentClassProperties, static function ($property) use ($reflectionClass) {
|
||||
return $reflectionClass->hasProperty($property);
|
||||
});
|
||||
$parentClassProperties = array_diff($parentClassProperties, $handled);
|
||||
|
@ -36,9 +36,11 @@ use HyperfTest\Di\Stub\Inject\Origin2Class;
|
||||
use HyperfTest\Di\Stub\Inject\Origin3Class;
|
||||
use HyperfTest\Di\Stub\Inject\Origin4Class;
|
||||
use HyperfTest\Di\Stub\Inject\Origin5Class;
|
||||
use HyperfTest\Di\Stub\Inject\Origin6Class;
|
||||
use HyperfTest\Di\Stub\Inject\OriginClass;
|
||||
use HyperfTest\Di\Stub\Inject\Parent2Class;
|
||||
use HyperfTest\Di\Stub\Inject\Parent3Class;
|
||||
use HyperfTest\Di\Stub\Inject\Parent4Class;
|
||||
use HyperfTest\Di\Stub\Inject\ParentClass;
|
||||
use HyperfTest\Di\Stub\Inject\Tar;
|
||||
use Mockery;
|
||||
@ -222,6 +224,31 @@ class InjectTest extends TestCase
|
||||
$this->assertInstanceOf(Foo::class, $origin->getFoo());
|
||||
}
|
||||
|
||||
public function testInjectParentPrivateProperty()
|
||||
{
|
||||
$this->getContainer();
|
||||
$ast = new Ast();
|
||||
$classes = [
|
||||
Parent4Class::class,
|
||||
Origin6Class::class,
|
||||
];
|
||||
|
||||
if (! is_dir($dir = BASE_PATH . '/runtime/container/proxy/')) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$code = $ast->proxy($class);
|
||||
$id = md5($class);
|
||||
file_put_contents($file = $dir . $id . '.proxy.php', $code);
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
$origin = new Origin6Class();
|
||||
$this->assertInstanceOf(Foo::class, $origin->getFoo());
|
||||
$this->assertInstanceOf(Bar::class, $origin->getBar());
|
||||
}
|
||||
|
||||
public function testInjectException()
|
||||
{
|
||||
$this->getContainer();
|
||||
@ -283,6 +310,8 @@ class InjectTest extends TestCase
|
||||
Origin5Class::class,
|
||||
Parent2Class::class,
|
||||
Parent3Class::class,
|
||||
Parent4Class::class,
|
||||
Origin6Class::class,
|
||||
];
|
||||
|
||||
foreach ($classes as $class) {
|
||||
|
28
src/di/tests/Stub/Inject/Origin6Class.php
Normal file
28
src/di/tests/Stub/Inject/Origin6Class.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
namespace HyperfTest\Di\Stub\Inject;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class Origin6Class extends Parent4Class
|
||||
{
|
||||
/**
|
||||
* @Inject
|
||||
* @var Bar
|
||||
*/
|
||||
private $bar;
|
||||
|
||||
public function getBar()
|
||||
{
|
||||
return $this->bar;
|
||||
}
|
||||
}
|
28
src/di/tests/Stub/Inject/Parent4Class.php
Normal file
28
src/di/tests/Stub/Inject/Parent4Class.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
namespace HyperfTest\Di\Stub\Inject;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class Parent4Class
|
||||
{
|
||||
/**
|
||||
* @Inject
|
||||
* @var Foo
|
||||
*/
|
||||
private $foo;
|
||||
|
||||
public function getFoo()
|
||||
{
|
||||
return $this->foo;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user