Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Framework Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require goaop/framework
    

    Add the service provider to config/app.php:

    'providers' => [
        GoAOP\Framework\GoAOPServiceProvider::class,
    ],
    
  2. 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));
        }
    }
    
  3. 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
        }
    }
    
  4. Verify Call UserService::createUser() and check Laravel logs for the aspect output.


Implementation Patterns

Common Workflows

  1. Cross-Cutting Concerns

    • Authentication/Authorization
      #[Aspect(AuthAspect::class)]
      class AdminController {
          public function sensitiveAction() { ... }
      }
      
    • Caching
      #[CacheAspect('user_', 3600)]
      class UserRepository {
          public function getUser(int $id) { ... }
      }
      
  2. Pointcut Expressions Use advanced pointcuts to target specific methods:

    #[Aspect(LoggingAspect::class, pointcut = "@annotation(GoAOP\Framework\Annotations\API)")]
    class ApiController { ... }
    
  3. 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;
    }
    
  4. Integration with Laravel

    • Service Container Binding
      $this->app->bind('userService', function ($app) {
          return new UserService();
      });
      
    • Middleware-like Aspects Use aspects to replace middleware for specific routes:
      #[Aspect(ValidateRequestAspect::class)]
      class OrderController { ... }
      
  5. Testing Aspects Mock aspects in tests using GoAOP\Framework\Test\AspectTestCase:

    public function testLoggingAspect() {
        $this->mockAspect(LoggingAspect::class);
        // Test logic
    }
    

Gotchas and Tips

Pitfalls

  1. Performance Overhead

    • Aspects add reflection overhead. Benchmark critical paths.
    • Use @Aspect(..., priority = 1000) to control execution order.
  2. Annotation Parsing

    • Ensure goaop/framework is autoloaded (check composer dump-autoload).
    • Avoid circular dependencies in annotated classes.
  3. JoinPoint Limitations

    • JoinPoint::proceed() can only be called once per advice.
    • Private/protected methods may not be intercepted unless explicitly configured.
  4. Laravel Service Provider Conflicts

    • Register GoAOPServiceProvider after Laravel’s default providers.
    • Disable Laravel’s built-in method overriding if conflicts arise:
      $this->app->setUseAppCache(false); // Temporarily for debugging
      

Debugging Tips

  1. Enable Aspect Logging

    config(['goaop.debug' => true]);
    

    Logs all intercepted methods to storage/logs/goaop.log.

  2. Pointcut Debugging Use @Aspect(..., pointcut = "@annotation(YourAnnotation)") to isolate issues.

  3. Weaver Configuration Adjust weaver settings in config/goaop.php:

    'weaver' => [
        'enabled' => env('GOAOP_WEAVER_ENABLED', true),
        'cache' => storage_path('framework/cache/goaop'),
    ],
    

Extension Points

  1. Custom Advice Types Extend GoAOP\Framework\Advice\AbstractAdvice for new advice types (e.g., @Retry).

  2. Pointcut Languages Implement GoAOP\Framework\Pointcut\Pointcut for custom pointcut logic (e.g., regex-based).

  3. Aspect Compilation Override GoAOP\Framework\Weaver\WeaverInterface for custom weaving strategies.

  4. Laravel Events Integration Trigger Laravel events from aspects:

    event(new MethodCalled($joinPoint));
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle