goaop/goaop-laravel-bridge

LoggingAspect beforeMethod

aftabnaveed opened this issue · 7 comments

I am following the example given in README and I see the LoggingAspect gets registered through AopServiceProvider, and but beforeMethod never get's executed therefore nothing get's logged for public methods.
I tried to follow the instructions, but I may be missing something here?

<?php

namespace App\Providers;

use App\Aspect\LoggingAspect;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Psr\Log\LoggerInterface;

class AopServiceProvider extends ServiceProvider
{

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {

        $this->app->singleton(LoggingAspect::class, function (Application $app) {

            return new LoggingAspect($app->make(LoggerInterface::class));
        });

        $this->app->tag([LoggingAspect::class], 'goaop.aspect');
    }
}

LoggingAspect

<?php

namespace App\Aspect;

use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
use Illuminate\Support\Facades\Log;
use Psr\Log\LoggerInterface;

/**
 * Application logging aspect
 */
class LoggingAspect implements Aspect
{
    /**
     * @var LoggerInterface
     */
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        Log::info('Logger interface....');
        $this->logger = $logger;
    }

    /**
     * Writes a log info before method execution
     *
     * @param MethodInvocation $invocation
     * @Before("execution(public **->*(*))")
     */
    public function beforeMethod(MethodInvocation $invocation)
    {
        $this->logger->info($invocation, $invocation->getArguments());
    }
}

And then in config/app.php I have the providers registered as follows

 'providers' => [

        /**
         * AOP Provider (This needs to be the first item here to AOP engine to work properly
         */
        Go\Laravel\GoAopBridge\GoAopServiceProvider::class,
        App\Providers\AopServiceProvider::class,

Looks like the issue is related to #4 I had commented out $file = FilterInjectorTransformer::rewrite($file); does some magic here 🈂️

Hi! What is your configuration for the go_aop module? Which version of goaop do you use?

Ping! Is this issue still actual for you?

Yes it is, this probably has to be fixed by Facebook.

Just noticed, that you've added a line about Facebook, so I can guess that this issue is related to the HHVM, right? Unfortunately, HHVM can't run some of tricky code from the AOP engine, so nothing happens.

For reference, see goaop/framework#143

Unfortunately, HHVM support isn't expected any more, only 0,36% of projects are using HHVM in production nowadays (there are unfixed issues in HHVM). So, I want to drop HHVM.

Feel free to reopen if needed