goaop/framework
Go! AOP brings aspect-oriented programming to PHP without extensions or eval. Define aspects once to apply logging, caching, security and other cross-cutting concerns across your app automatically, keeping business code clean with static file weaving.
Installation
composer require goaop/framework
Add the service provider to config/app.php:
'providers' => [
GoAOP\Framework\GoAOPServiceProvider::class,
],
First Use Case: Logging Method Calls Define an aspect to log method invocations:
use GoAOP\Framework\Aspect;
use GoAOP\Framework\JoinPoint;
class LoggingAspect {
public function logMethodCall(JoinPoint $joinPoint) {
$class = $joinPoint->getTargetClass();
$method = $joinPoint->getMethodName();
$args = $joinPoint->getArgs();
\Log::info("Method called: {$class}::{$method} with args: " . json_encode($args));
}
}
Apply the Aspect
Use the @Aspect annotation on a class or method:
use GoAOP\Framework\Annotations\Aspect;
#[Aspect(LoggingAspect::class)]
class UserService {
public function createUser(array $data) {
// Your logic here
}
}
Verify
Call UserService::createUser() and check Laravel logs for the aspect output.
Cross-Cutting Concerns
#[Aspect(AuthAspect::class)]
class AdminController {
public function sensitiveAction() { ... }
}
#[CacheAspect('user_', 3600)]
class UserRepository {
public function getUser(int $id) { ... }
}
Pointcut Expressions Use advanced pointcuts to target specific methods:
#[Aspect(LoggingAspect::class, pointcut = "@annotation(GoAOP\Framework\Annotations\API)")]
class ApiController { ... }
Around Advice Modify method execution flow:
public function aroundMethod(JoinPoint $joinPoint) {
$start = microtime(true);
$result = $joinPoint->proceed();
$duration = microtime(true) - $start;
\Log::debug("Method took {$duration}s");
return $result;
}
Integration with Laravel
$this->app->bind('userService', function ($app) {
return new UserService();
});
#[Aspect(ValidateRequestAspect::class)]
class OrderController { ... }
Testing Aspects
Mock aspects in tests using GoAOP\Framework\Test\AspectTestCase:
public function testLoggingAspect() {
$this->mockAspect(LoggingAspect::class);
// Test logic
}
Performance Overhead
@Aspect(..., priority = 1000) to control execution order.Annotation Parsing
goaop/framework is autoloaded (check composer dump-autoload).JoinPoint Limitations
JoinPoint::proceed() can only be called once per advice.Laravel Service Provider Conflicts
GoAOPServiceProvider after Laravel’s default providers.$this->app->setUseAppCache(false); // Temporarily for debugging
Enable Aspect Logging
config(['goaop.debug' => true]);
Logs all intercepted methods to storage/logs/goaop.log.
Pointcut Debugging
Use @Aspect(..., pointcut = "@annotation(YourAnnotation)") to isolate issues.
Weaver Configuration
Adjust weaver settings in config/goaop.php:
'weaver' => [
'enabled' => env('GOAOP_WEAVER_ENABLED', true),
'cache' => storage_path('framework/cache/goaop'),
],
Custom Advice Types
Extend GoAOP\Framework\Advice\AbstractAdvice for new advice types (e.g., @Retry).
Pointcut Languages
Implement GoAOP\Framework\Pointcut\Pointcut for custom pointcut logic (e.g., regex-based).
Aspect Compilation
Override GoAOP\Framework\Weaver\WeaverInterface for custom weaving strategies.
Laravel Events Integration Trigger Laravel events from aspects:
event(new MethodCalled($joinPoint));
How can I help you explore Laravel packages today?