ray-di / Ray.Aop

An aspect-oriented framework for PHP

Home Page:https://packagist.org/packages/ray/aop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Organizing the generated AOP code

koriym opened this issue · comments

Current version:

class FakeMock_358616026 extends \Ray\Aop\FakeMock implements WeavedInterface
{
    public $bind;
    public $bindings = [];
    public $methodAnnotations = 'a:0:{}';
    public $classAnnotations = 'a:0:{}';
    public $isAspect = true;
    /**
     * doc comment of returnSame
     */
    public function returnSame($a)
    {
        if (!$this->isAspect) {
            $this->isAspect = true;
            return call_user_func_array([parent::class, __FUNCTION__], func_get_args());
        }
        $this->isAspect = false;
        $result = (new Invocation($this, __FUNCTION__, func_get_args(), $this->bindings[__FUNCTION__]))->proceed();
        $this->isAspect = true;
        return $result;
    }
}

Update version:

class FakeMock_358616026 extends \Ray\Aop\FakeMock implements WeavedInterface
{
    use AopTrait;

    /**
     * doc comment of returnSame
     */
    public function returnSame($a)
    {
        return $this->__aop(func_get_args(), __FUNCTION__);
    }
}
<?php

namespace Ray\Aop;

use Ray\Aop\ReflectiveMethodInvocation as Invocation;
use function call_user_func_array;
use function func_get_args;

trait AopTrait
{
    private $bind;
    private $bindings = [];
    public $methodAnnotations = 'a:0:{}';
    public $classAnnotations = 'a:0:{}';
    private $isAspect = true;

    private function __aop(array $args, string $func)
    {
        if (!$this->isAspect) {
            $this->isAspect = true;
            return call_user_func_array([parent::class, __FUNCTION__], func_get_args());
        }
        $this->isAspect = false;
        $result = (new Invocation($this, __FUNCTION__, func_get_args(), $this->bindings[__FUNCTION__]))->proceed();
        $this->isAspect = true;
        return $result;
    }
}

何が得られるか?

  • デバックトレースの時の読みやすさ、ステップ実行のしやすさ
  • レンダリング速度
    • php parserを使わなくてもいいかも? (依存を減らすことができるかもしれない)

Fixed with #194, #195