-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from koriym/template
Clean template with performance
- Loading branch information
Showing
11 changed files
with
123 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
parameters: | ||
excludes_analyse: | ||
- %currentWorkingDirectory%/tests/tmp/* | ||
ignoreErrors: | ||
- '#Access to an undefined property PhpParser\\Node\\Expr::\$args#' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of the Ray.Aop package. | ||
* | ||
* @license http://opensource.org/licenses/MIT MIT | ||
*/ | ||
namespace Ray\Aop; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr\ArrayItem; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use PhpParser\Node\Expr\StaticCall; | ||
use PhpParser\Node\Expr\Variable; | ||
|
||
final class AopTemplateConverter extends \PhpParser\NodeVisitorAbstract | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $method; | ||
|
||
/** | ||
* @var Arg[] | ||
*/ | ||
private $args = []; | ||
|
||
private $proceedArg; | ||
|
||
public function __construct(\ReflectionMethod $method) | ||
{ | ||
$this->method = $method->name; | ||
$proceedArg = []; | ||
foreach ($method->getParameters() as $parameter) { | ||
$this->args[] = new Arg(new Variable($parameter->name)); | ||
$proceedArg[] = new ArrayItem(new Variable($parameter->name)); | ||
} | ||
$this->proceedArg = new Arg(new Node\Expr\Array_($proceedArg)); | ||
} | ||
|
||
public function enterNode(Node $node) | ||
{ | ||
if ($node instanceof StaticCall && $node->name === 'templateMethod') { | ||
$node->name = $this->method; | ||
$node->args = $this->args; | ||
|
||
return $node; | ||
} | ||
|
||
return $this->updateReflectiveMethodInvocation2ndParam($node); | ||
} | ||
|
||
private function updateReflectiveMethodInvocation2ndParam(Node $node) : Node | ||
{ | ||
if ($node instanceof MethodCall && $node->name === 'proceed') { | ||
$node->var->args[2] = $this->proceedArg; | ||
|
||
return $node; | ||
} | ||
|
||
return $node; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
namespace Ray\Aop; | ||
|
||
class FakeChangeArgsInterceptor implements MethodInterceptor | ||
{ | ||
public function invoke(MethodInvocation $invocation) | ||
{ | ||
$args = $invocation->getArguments(); | ||
$args[0] = 'changed'; | ||
|
||
return $invocation->proceed(); | ||
} | ||
} |
This file contains 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
This file contains 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