Conversation
Owner
|
@reallovelei 这个问题一直存在的,你可以看我的文档我是怎么解决的。为什么会出现这个问题,是因为@task注解使用的是代理方式,代理方式无法获取到继承类的属性,也就是无法获取到子类的collectionName,所以会默认拿父类(MongoDb.php)的collectionName,父类的conllectionName是null,所以会出现这个问题。你这个方法也可以,不过要给每个方法上都添加这个参数.你fork一份出来,自己发布,目前php的项目我基本不动了,等我缓过一段时间,再重新梳理一下 |
Author
|
那就是说已经有解决方案了?
——
?php declare(strict_types=1); namespace TmgAddon\WebQySession\Model; use Hyperf\Task\Annotation\Task; use Phper666\MongoDb\MongoDb; class Test extends MongoDb { public $collectionName = 'test'; public static function collectionName() { return 'test'; } /** * @task(timeout=20) * @return array */ public function getMethod($method, ...$params) { return $this-{$method}(...$params); } } // 调用,实际跟原有的findOne调用的参数是一致的,只不过第一个参数时申明要调用申明方法 $data = make(Test::class)-getMethod('findOne', ['name' = '1'], ['projection' = ['name' = 1]]);
这是第一种解决方案吗?
原始邮件
发件人:phper666notifications@github.com
收件人:phper666/mongo-dbmongo-db@noreply.github.com
抄送:Ben83212019@qq.com; Mentionmention@noreply.github.com
发送时间:2021年2月22日(周一) 22:37
主题:Re: [phper666/mongo-db] add collectionName (#10)
@reallovelei 这个问题一直存在的,你可以看我的文档我是怎么解决的。为什么会出现这个问题,是因为@task注解使用的是代理方式,代理方式无法获取到继承类的属性,也就是无法获取到子类的collectionName,所以会默认拿父类(MongoDb.php)的collectionName,父类的conllectionName是null,所以会出现这个问题。你这个方法也可以,不过要给每个方法上都添加这个参数.你fork一份出来,自己发布,目前php的项目我基本不动了,等我缓过一段时间,再重新梳理一下
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Owner
|
可以直接使用mongo.php这个类,有用到mongo的,在自己的方法上什么task注解,或者使用第一种方式,两个方式也可以一起用。还有个问题,在你自己的方法那里声明task注解会有限制,你的方法里面如果用到协程的方法,那是无法投递到task进程处理的,会报错。解决方法:1,如果你的方法有用到mongo,并且没有用到协程的一些方法,就直接在你的方法申明task注解即可。2,如果你的方法有用到mongo,并且有用到协程的一些方法,那你就用方式一解决
发自我的iPhone
…------------------ Original ------------------
From: Ben <notifications@github.com>
Date: Mon,Feb 22,2021 10:43 PM
To: phper666/mongo-db <mongo-db@noreply.github.com>
Cc: phper666 <562405704@qq.com>, Comment <comment@noreply.github.com>
Subject: Re: [phper666/mongo-db] add collectionName (#10)
那就是说已经有解决方案了?
——
?php declare(strict_types=1); namespace TmgAddon\WebQySession\Model; use Hyperf\Task\Annotation\Task; use Phper666\MongoDb\MongoDb; class Test extends MongoDb { public $collectionName = 'test'; public static function collectionName() { return 'test'; } /** * @task(timeout=20) * @return array */ public function getMethod($method, ...$params) { return $this-{$method}(...$params); } } // 调用,实际跟原有的findOne调用的参数是一致的,只不过第一个参数时申明要调用申明方法 $data = make(Test::class)-getMethod('findOne', ['name' = '1'], ['projection' = ['name' = 1]]);
这是第一种解决方案吗?
原始邮件
发件人:phper666notifications@github.com
收件人:phper666/mongo-dbmongo-db@noreply.github.com
抄送:Ben83212019@qq.com; Mentionmention@noreply.github.com
发送时间:2021年2月22日(周一) 22:37
主题:Re: [phper666/mongo-db] add collectionName (#10)
@reallovelei 这个问题一直存在的,你可以看我的文档我是怎么解决的。为什么会出现这个问题,是因为@task注解使用的是代理方式,代理方式无法获取到继承类的属性,也就是无法获取到子类的collectionName,所以会默认拿父类(MongoDb.php)的collectionName,父类的conllectionName是null,所以会出现这个问题。你这个方法也可以,不过要给每个方法上都添加这个参数.你fork一份出来,自己发布,目前php的项目我基本不动了,等我缓过一段时间,再重新梳理一下
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
因为使用了注解@task
所以会在启动的时候 在runtime里生成runtime/container/proxy/Phper666_MongoDb_MongoDb.proxy.php
__proxyCall 上面的部分 第一次执行是有值的。但是在__proxyCall再次调用本身的时候 $this->collectionName就没有值了。
这种情况只有在config/autoload/crontab.php 里调用的时候 才会出现。
如果直接在命令行执行,是直接调用的vendor里的MongoDb.php 这时候就不会发生。我也比较纳闷。
线上问题 希望可以合并,这样我就不用自己打包发布了。