diff --git a/CHANGELOG.md b/CHANGELOG.md index 292ad6e76..1d8c60390 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ # Fixed - [#271](https://github.com/hyperf-cloud/hyperf/pull/271) Fixed aop only rewrite the first method in classes and method patten is not work. +- [#285](https://github.com/hyperf-cloud/hyperf/pull/285) Fixed anonymous class should not rewrite in proxy class. - [#286](https://github.com/hyperf-cloud/hyperf/pull/286) Fixed not auto rollback when forgotten to commit or rollback in multi transactions. # v1.0.7 - 2019-07-26 diff --git a/src/di/src/Aop/ProxyCallVistor.php b/src/di/src/Aop/ProxyCallVistor.php index f17597bbd..87e3f587e 100644 --- a/src/di/src/Aop/ProxyCallVistor.php +++ b/src/di/src/Aop/ProxyCallVistor.php @@ -92,7 +92,7 @@ class ProxyCallVistor extends NodeVisitorAbstract $usedNamespace[] = $classUse->name->toCodeString(); } break; - case $class instanceof Class_: + case $class instanceof Class_ && ! $class->isAnonymous(): $this->class = $class->name; if ($class->extends) { $this->extends = $class->extends; @@ -124,7 +124,7 @@ class ProxyCallVistor extends NodeVisitorAbstract // Rewrite the method to proxy call method. return $this->rewriteMethod($node); break; - case $node instanceof Class_: + case $node instanceof Class_ && ! $node->isAnonymous(): // Add use proxy traits. $stmts = $node->stmts; array_unshift($stmts, $this->buildProxyCallTraitUseStatement()); diff --git a/src/di/src/Aop/ProxyClassNameVistor.php b/src/di/src/Aop/ProxyClassNameVistor.php index 8e8674c9b..4d8ca5fa6 100644 --- a/src/di/src/Aop/ProxyClassNameVistor.php +++ b/src/di/src/Aop/ProxyClassNameVistor.php @@ -34,7 +34,7 @@ class ProxyClassNameVistor extends NodeVisitorAbstract public function leaveNode(Node $node) { // Rewirte the class name and extends the original class. - if ($node instanceof Node\Stmt\Class_) { + if ($node instanceof Node\Stmt\Class_ && ! $node->isAnonymous()) { $node->extends = $node->name; $node->name = new Node\Identifier($this->proxyClassName); return $node;