Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复自定义注解无法使用Aop切面编程的BUG #139

Merged

Conversation

limingxinleo
Copy link
Contributor

方便用户定义方法类型注解

namespace SwoftTest\Aop\Annotation;

use Swoft\Bean\Annotation\CustomMethod;

/**
 * Class DemoAnnotation
 * @Annotation
 * @Target("METHOD")
 * @package SwoftTest\Aop\Annotation
 */
class DemoAnnotation extends CustomMethod
{

}

以及对应的Parser

namespace SwoftTest\Aop\Parser;

use Swoft\Bean\Annotation\CustomMethod;
use Swoft\Bean\Parser\CustomMethodParser;

class DemoAnnotationParser extends CustomMethodParser
{

}

Aspect

use Swoft\Aop\ProceedingJoinPoint;
use Swoft\Bean\Annotation\Around;
use Swoft\Bean\Annotation\Aspect;
use Swoft\Bean\Annotation\PointAnnotation;
use Swoft\Bean\Annotation\Cacheable;
use Swoft\Bean\Annotation\CachePut;
use SwoftTest\Aop\Annotation\DemoAnnotation;

/**
 * @Aspect
 * @PointAnnotation(
 *     include={
 *         Cacheable::class,
 *         CachePut::class,
 *         DemoAnnotation::class
 *     }
 * )
 * @uses      AnnotationAspect
 * @version   2017年12月27日
 * @author    stelin <[email protected]>
 * @copyright Copyright 2010-2016 swoft software
 * @license   PHP Version 7.x {@link http://www.php.net/license/3_0.txt}
 */
class AnnotationAspect
{
    /**
     * @Around
     */
    public function around(ProceedingJoinPoint $proceedingJoinPoint)
    {
        $tag = ' around before ';
        $result = $proceedingJoinPoint->proceed();
        $tag .= ' around after ';
        return $result.$tag;
    }
}

调用下面方法时,就可以走Aop 切面了

namespace SwoftTest\Aop;

use Swoft\Bean\Annotation\Bean;
use Swoft\Bean\Annotation\Cacheable;
use Swoft\Bean\Annotation\CachePut;
use SwoftTest\Aop\Annotation\DemoAnnotation;

/**
 *
 * @Bean
 * @uses      AnnotationAop
 * @version   2017年12月27日
 * @author    stelin <[email protected]>
 * @copyright Copyright 2010-2016 swoft software
 * @license   PHP Version 7.x {@link http://www.php.net/license/3_0.txt}
 */
class AnnotationAop
{
    /**
     * @DemoAnnotation
     * @return string
     */
    public function demoAnnotation()
    {
        return 'demo';
    }
}

@limingxinleo limingxinleo changed the title Features/custom annotation for aop 修复自定义注解无法使用Aop切面编程的BUG Jul 18, 2018
@huangzhhui
Copy link
Contributor

感觉这样处理没必要,直接 BeanWrapper 里面对 Method 注解返回 true 是不是就好了

@huangzhhui
Copy link
Contributor

直接 isParseMethodAnnotations 返回 true

@limingxinleo
Copy link
Contributor Author

@huangzhhui 可以么?我看之前代码处理的,为了只多开一个小入口,害怕会有问题

@limingxinleo
Copy link
Contributor Author

如果可以直接返回true,那最好不过了

@huangzhhui
Copy link
Contributor

等等,注意到还有个 WrapperExtend 的机制,应该使用这个来解决 Wrapper 的问题

@limingxinleo
Copy link
Contributor Author

我找时间修改一下,如果有其他人改掉了这个问题,那这个pr就先关掉。。

如果没有其他人来处理,等我把redis一些常用的命令改掉,我就回来改这个

😄

@limingxinleo
Copy link
Contributor Author

我仔细考虑了下,我觉得Bean的方法注解应该允许全部解析。。额外增加一个CustormMethod注解,感觉有点丑

@huangzhhui huangzhhui merged commit 058918a into swoft-cloud:master Jul 24, 2018
huangzhhui pushed a commit to swoft-cloud/swoft-framework that referenced this pull request Jul 26, 2018
* 增加自定义Aop注解测试

* 增加自定义方法注解,支持PointAnnotation

* 完善单测

* 删除CustomMethod注解

* 通过自定义Parser收集注解测试

* 删除CustomMethod注解
@limingxinleo limingxinleo deleted the features/custom-annotation-for-aop branch July 31, 2018 14:36
huangzhhui added a commit that referenced this pull request Aug 7, 2018
ba1657b8 Upstream travis ci config (#160)
ffdb60e5 修复Json Validator会失效的BUG (#153)
4d788e9a 修复自定义注解无法使用Aop切面编程的BUG (#139)
405a83e3 Optimize  (#143)
b72e04ce 修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134)
a30bf589 修改`ComposerHelper::getDirByNamespace`匹配有误的BUG (#137)
43088e60 Update PoolHelper.php (#131)
82aadc28 Scan bean according to Composer settings (#115)
5e55e722 Add psysh for debug (#109)
93c3ec76 Parse namespace to dir path according to composer settings (#103)

git-subtree-dir: src/framework
git-subtree-split: ba1657b85d5d5f1e846333e8f5ad03e499b76db8
swoft-bot pushed a commit to swoft-cloud/swoft-framework that referenced this pull request Nov 21, 2018
* 增加自定义Aop注解测试

* 增加自定义方法注解,支持PointAnnotation

* 完善单测

* 删除CustomMethod注解

* 通过自定义Parser收集注解测试

* 删除CustomMethod注解
swoft-bot added a commit that referenced this pull request Jan 15, 2019
f9910dc Merge commit 'b4f8d0a17a1c9a99274d0e250f6179d14a8728a8'
036d98b Merge branch 'master' of github.com:swoft-cloud/swoft-component
0d9ccbe Update Aop.php (#222)
cacd775 修复Number验证器最大和最小的template没有生效的问题 (#218)
7ebaf5f 修复Number验证器最大和最小的template没有生效的问题 (#218)
ed18988 fix error on trigger event handler (#196)
bf188ad fix a bug when warnings appear in the high version of swoole (#195)
4ec3be6 自定义组件支持别名配置 (#181)
609dd83 修复restart不能正常使用的BUG (#180)
0bcd9bc 修改连接池配置的timeout字段为float (#177)
0044361 修改自定义组件只能扫描Aop、Command、Bootstrap三个文件的BUG (#169)
99916fc 兼容swoole 4.0.3版本 (#166)
a1d6ace 增加用户自定义组件配置 (#150)
d0f7f88 Upstream travis ci config (#160)
afb115f 修复Json Validator会失效的BUG (#153)
5fdf6c7 修复自定义注解无法使用Aop切面编程的BUG (#139)
3c147d1 Optimize  (#143)
c98825b 修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134)
940f76f 修改`ComposerHelper::getDirByNamespace`匹配有误的BUG (#137)
427dcb6 Update PoolHelper.php (#131)
fc38546 Scan bean according to Composer settings (#115)
851f3f0 Add psysh for debug (#109)
e55fae5 Parse namespace to dir path according to composer settings (#103)
290a2f4 fix swoft-cloud/swoft#277 (#96)
0d2dade  fix logWriter (#95)
1f1af6c Uniform log path format (#94)
148daeb [fixed]eval error with void method (#92)
a22481a [fixed] logger->messages init error (#91)
69975cd  add coWrite(); use swoft/swoole-ide-helper (#83)
7f66cef change fix
410b028 fix index err

git-subtree-dir: src/framework
git-subtree-split: f9910dc9266e9f87c158d89286a2f07dc67f2a18
swoft-bot pushed a commit to swoft-cloud/swoft-view that referenced this pull request Jan 25, 2019
* 增加自定义Aop注解测试

* 增加自定义方法注解,支持PointAnnotation

* 完善单测

* 删除CustomMethod注解

* 通过自定义Parser收集注解测试

* 删除CustomMethod注解
swoft-bot pushed a commit to swoft-cloud/swoft-view that referenced this pull request Jan 25, 2019
* 增加自定义Aop注解测试

* 增加自定义方法注解,支持PointAnnotation

* 完善单测

* 删除CustomMethod注解

* 通过自定义Parser收集注解测试

* 删除CustomMethod注解
swoft-bot added a commit to swoft-cloud/swoft-view that referenced this pull request Jan 25, 2019
b3a45be fix error on trigger event handler (swoft-cloud/swoft-component#196)
b1a48cd fix a bug when warnings appear in the high version of swoole (swoft-cloud/swoft-component#195)
9c4da9f 自定义组件支持别名配置 (swoft-cloud/swoft-component#181)
bccf7a6 修复restart不能正常使用的BUG (swoft-cloud/swoft-component#180)
97bfe2e 修改连接池配置的timeout字段为float (swoft-cloud/swoft-component#177)
525097b 修改自定义组件只能扫描Aop、Command、Bootstrap三个文件的BUG (swoft-cloud/swoft-component#169)
0b5f320 兼容swoole 4.0.3版本 (swoft-cloud/swoft-component#166)
1d11b56 增加用户自定义组件配置 (swoft-cloud/swoft-component#150)
ba1657b Upstream travis ci config (swoft-cloud/swoft-component#160)
ffdb60e 修复Json Validator会失效的BUG (swoft-cloud/swoft-component#153)
4d788e9 修复自定义注解无法使用Aop切面编程的BUG (swoft-cloud/swoft-component#139)
405a83e Optimize  (swoft-cloud/swoft-component#143)
b72e04c 修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134)
a30bf58 修改`ComposerHelper::getDirByNamespace`匹配有误的BUG (swoft-cloud/swoft-component#137)
43088e6 Update PoolHelper.php (swoft-cloud/swoft-component#131)
82aadc2 Scan bean according to Composer settings (#115)
5e55e72 Add psysh for debug (swoft-cloud/swoft-component#109)
93c3ec7 Parse namespace to dir path according to composer settings (swoft-cloud/swoft-component#103)
2da84a5 fix swoft-cloud/swoft#277 (#96)
fc8e1b3 Merge commit 'ab0f47838db6f3739146d53c3b48d3fb11c7675e'
33faf07  fix logWriter (#95)
f3075d8 Uniform log path format (swoft-cloud/swoft-component#94)
7003d92 Merge commit '30a1120da2a33a98360ee4da4e4586ad3412b5f2'
e8da860 [fixed]eval error with void method (#92)
5cf5896 [fixed] logger->messages init error (#91)
52bbec6 Merge pull request #114 from aprchen/patch-1
847f23b fix spanid
c559c93  add coWrite(); use swoft/swoole-ide-helper (#83)
21d268b change fix
e88a03f fix index err
620394d Merge commit '1643eb132396c22e6c9be8c90d123a31487455dd'
0d8bb66 add some cosnt, add global func config()
REVERT: 7ebaf5f 修复Number验证器最大和最小的template没有生效的问题 (#218)
REVERT: ed18988 fix error on trigger event handler (swoft-cloud/swoft-component#196)
REVERT: bf188ad fix a bug when warnings appear in the high version of swoole (swoft-cloud/swoft-component#195)
REVERT: 4ec3be6 自定义组件支持别名配置 (swoft-cloud/swoft-component#181)
REVERT: 609dd83 修复restart不能正常使用的BUG (swoft-cloud/swoft-component#180)
REVERT: 0bcd9bc 修改连接池配置的timeout字段为float (swoft-cloud/swoft-component#177)
REVERT: 0044361 修改自定义组件只能扫描Aop、Command、Bootstrap三个文件的BUG (swoft-cloud/swoft-component#169)
REVERT: 99916fc 兼容swoole 4.0.3版本 (swoft-cloud/swoft-component#166)
REVERT: a1d6ace 增加用户自定义组件配置 (swoft-cloud/swoft-component#150)
REVERT: d0f7f88 Upstream travis ci config (swoft-cloud/swoft-component#160)
REVERT: afb115f 修复Json Validator会失效的BUG (swoft-cloud/swoft-component#153)
REVERT: 5fdf6c7 修复自定义注解无法使用Aop切面编程的BUG (swoft-cloud/swoft-component#139)
REVERT: 3c147d1 Optimize  (swoft-cloud/swoft-component#143)
REVERT: c98825b 修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134)
REVERT: 940f76f 修改`ComposerHelper::getDirByNamespace`匹配有误的BUG (swoft-cloud/swoft-component#137)
REVERT: 427dcb6 Update PoolHelper.php (swoft-cloud/swoft-component#131)
REVERT: fc38546 Scan bean according to Composer settings (#115)
REVERT: 851f3f0 Add psysh for debug (swoft-cloud/swoft-component#109)
REVERT: e55fae5 Parse namespace to dir path according to composer settings (swoft-cloud/swoft-component#103)
REVERT: 290a2f4 fix swoft-cloud/swoft#277 (#96)
REVERT: 0d2dade  fix logWriter (#95)
REVERT: 1f1af6c Uniform log path format (swoft-cloud/swoft-component#94)
REVERT: 148daeb [fixed]eval error with void method (#92)
REVERT: a22481a [fixed] logger->messages init error (#91)
REVERT: 69975cd  add coWrite(); use swoft/swoole-ide-helper (#83)
REVERT: 7f66cef change fix
REVERT: 410b028 fix index err

git-subtree-dir: src/framework
git-subtree-split: b3a45be705c9cb53cb357925e228e4f60e6d76d5
stelin pushed a commit to swoft-cloud/swoft-framework that referenced this pull request May 28, 2019
* 增加自定义Aop注解测试

* 增加自定义方法注解,支持PointAnnotation

* 完善单测

* 删除CustomMethod注解

* 通过自定义Parser收集注解测试

* 删除CustomMethod注解
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants