goaop / goaop-laravel-bridge

Integration bridge for Go! AOP framework and Laravel
MIT License
95 stars 10 forks source link

Lumen - Registering Class in Service Provider #14

Open memoishin opened 6 years ago

memoishin commented 6 years ago

I am registering an Aspect class in the AopServiceProvider. However, it does not seem to work.

Here is my code:

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');
}

Now even if I have the code as this:

public function register()
{
     $this->app->singleton(LogsasasagingAspect::class, function (Application $app) {
        return new LoggingAspect($app->make(LoggesasarInterface::class));
    });

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

It still doesn't show any error.

This service provider has been registered as:

$app->register(App\Providers\AopServiceProvider::class); Is this normal or is there any fix for this?

SerafimArts commented 6 years ago

Registration of services in a DI Container is declarative and should not cause errors until the specified service is resolved.

In this case, errors will occur when u call: $app->make(LogsasasagingAspect::class).

But I did not understand the question. :D

memoishin commented 6 years ago

As you mentioned, "errors will occur when u call: $app->make(LogsasasagingAspect::class)", however, i do not receive any error message.

Also, the aop functionality does not work. I am using Lumen 5.6. Can this be the reason why it doesn't work?

SerafimArts commented 6 years ago

To be honest, I did not check the package works for Lumen at all. Here you need the experience of other developers who have adapted it.

Ping @lisachenko

lisachenko commented 6 years ago

I think @qrazi has an experience with Lumen, because he have contributed #11

memoishin commented 6 years ago

I have managed to make it work using some concepts from the slides by Chris Flynn and using the demo examples that was provided.

I believed making this change in bootstrap/app.php made it work:

use Go\Aop\Features; $applicationAspectKernel = App\lib\ApplicationAspectKernel::getInstance();

$applicationAspectKernel->init([ 'debug' => true, 'appDir' => DIR . '/../app/Http/Controllers/', 'cacheDir' => DIR . '/../cache',

'features' => Features::INTERCEPT_FUNCTIONS,

]);

qrazi commented 6 years ago

Right, so obviously I didn't finish testing after commit #11... 😖 Based on this issue testing the lumen integration and:

https://github.com/laravel/lumen-framework/pull/723/files should allow Lumen to have a more Laravel-like registration of ServiceProviders, i.e. the boot() of each provider will only be called after the register() of all providers has run.

I'll look more into this to get it into a proper solutions, leaving this issue open