goaop / framework

:gem: Go! AOP PHP - modern aspect-oriented framework for the new level of software development
go.aopphp.com
MIT License
1.66k stars 163 forks source link

AOP in laravel and php pure classes #456

Closed 4myr closed 2 years ago

4myr commented 3 years ago

hi

i'm using laravel framework with another pure php inside public directory. but beforeMethodExecution not working for php pure classes in public directory! . i configured go aop in php pure autoload:

ApplicationAspectKernel::getInstance()->init([
    'appDir' => $rootdir,
    'cacheDir' => $rootdir . 'aop/cache',
    'includePaths' => [
        $rootdir . 'public/ogp/classes/',
    ],
    'debug' => true
]);

$rootdir is laravel directory

and i have a class in public/ogp/classes directory

<?php
// public/ogp/classes/SampleClass.php
namespace ogp\classes;

class SampleClass {
    static public function testCondition($test = "test") {
        echo "Test condition working fine\n";
    }
}

also i have psr-4 autoload in composer.json laravel

"autoload": {
        "psr-4": {
            "App\\": "app/",
            "ogp\\": "public/ogp/"
        },
},

my ApplicationAspectKernel.php:

<?php
// public/ogp/AOP/ApplicationAspectKernel.php
namespace ogp\AOP;

use \ogp\AOP\Aspect\MonitorAspect;
use Go\Core\AspectKernel;
use Go\Core\AspectContainer;

/**
 * Application Aspect Kernel
 */
class ApplicationAspectKernel extends AspectKernel
{

    /**
     * Configure an AspectContainer with advisors, aspects and pointcuts
     *
     * @param AspectContainer $container
     *
     * @return void
     */
    protected function configureAop(AspectContainer $container)
    {
        $container->registerAspect(new MonitorAspect());
    }
}

and MonitorAspect.php:

<?php
// public/ogp/AOP/Aspect/MonitorAspect.php
namespace ogp\AOP\Aspect;

use Go\Aop\Aspect;
use Go\Aop\Intercept\FieldAccess;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\Around;
use Go\Lang\Annotation\Pointcut;

/**
 * Monitor aspect
 */
class MonitorAspect implements Aspect
{

    /**
     * @param MethodInvocation $invocation Invocation
     * @Before("execution(public|private|protected *\**->*(*))")
     */
    public function beforeMethodExecution(MethodInvocation $invocation)
    {
        echo "Before method\n";
    }
}

when i make a class in laravel app directory, beforeMethodExecution works. but classes in public directory not working.

lisachenko commented 2 years ago

Sorry, closing this as it is too old. Please ensure that configuration was done properly and you haven't included/loaded files first.