hyperf / hyperf

🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
https://www.hyperf.io
MIT License
6.26k stars 1.22k forks source link

[BUG] 继承关系中,子类的注解无效 #1989

Closed bob-yangpf closed 4 years ago

bob-yangpf commented 4 years ago

Execute the command and paste the result below.

Command: uname -a && php -v && composer info | grep hyperf && php --ri swoole

Linux promote.cache-dns.local 3.10.0-1062.4.3.el7.x86_64 #1 SMP Wed Nov 13 23:58:53 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
PHP 7.3.5 (cli) (built: May  6 2019 11:38:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
Do not run Composer as root/super user! See https://getcomposer.org/root for details
hyperf/cache                         v2.0.0   A cache component for hyperf.
hyperf/command                       v2.0.0   Command for hyperf
hyperf/config                        v2.0.0   An independent component that provides configuration container.
hyperf/contract                      v2.0.0   The contracts of Hyperf.
hyperf/database                      v2.0.0   A flexible database library.
hyperf/db-connection                 v2.0.0   A hyperf db connection handler for hyperf/database.
hyperf/devtool                       v2.0.0   A Devtool for Hyperf.
hyperf/di                            v2.0.0   A DI for Hyperf.
hyperf/dispatcher                    v2.0.0   A HTTP Server for Hyperf.
hyperf/event                         v2.0.0   an event manager that implements PSR-14.
hyperf/exception-handler             v2.0.0   Exception handler for hyperf
hyperf/framework                     v2.0.0   A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle                        v2.0.0   Swoole coroutine handler for guzzle
hyperf/http-message                  v2.0.0   microservice framework base on swoole
hyperf/http-server                   v2.0.0   A HTTP Server for Hyperf.
hyperf/logger                        v2.0.0   A logger component for hyperf.
hyperf/memory                        v2.0.0   An independent component that use to operate and manage memory.
hyperf/model-listener                v2.0.0   A model listener for Hyperf.
hyperf/paginator                     v2.0.0   A paginator component for hyperf.
hyperf/pool                          v2.0.0   An independent universal connection pool component.
hyperf/process                       v2.0.0   A process component for hyperf.
hyperf/redis                         v2.0.0   A redis component for hyperf.
hyperf/server                        v2.0.0   A base server library for Hyperf.
hyperf/testing                       v2.0.0   Testing for hyperf
hyperf/utils                         v2.0.0   A tools package that could help developer solved the problem quickly.

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.5.2
Built => Jun 26 2020 10:32:15
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
http2 => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

Description:

父类中 有一个变量 $tool 子类继承之后,使用了Inject注解 ,然后获取时候,子类中获取到的$tool 是空的

同理 @Value注解,在这种情况下也是获取不到配置的

Steps To Reproduce:

默认环境hyperf-skeleton 新建一个三个类: Base Foo Tool,在命名空间App\Test下,三个的关系是 Foo 继承与Base ,Tool是依赖入住的对象,代码如下:

}

- Tool 被依赖注入的类

<?php namespace App\Test; class Tool { protected $name = 'tool';

/**
 * @return mixed
 */
public function getName()
{
    return $this->name;
}

}

- Foo 子类

<?php namespace App\Test; use Hyperf\Config\Annotation\Value; use Hyperf\Di\Annotation\Inject;

/ / class Foo extends Base { /

}


修改indexController index方法内容为:

... public function index() { $foo = make(Foo::class); return [$foo->query()]; } ...

然后启动服务,请求,默认控制器

curl 127.0.0.1:9501



就能看到 无论是`config`还是 `tool`都是获取不到的
但是如果是 父类中直接 使用依赖注入,是可以获取到的。
1.x版本是正常的。
limingxinleo commented 4 years ago

等有空我改改

bob-yangpf commented 4 years ago

等有空我改改

大佬,我改了下,提交了一个PR(#1990 )。麻烦看下ok不。

bob-yangpf commented 4 years ago

此问题已经被@limingxinleo大佬解决,详情见 #1992