PHPackages                             lisachenko/go-aop-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. lisachenko/go-aop-php

Abandoned → [goaop/framework](/?search=goaop%2Fframework)Library[Framework](/categories/framework)

lisachenko/go-aop-php
=====================

Framework for aspect-oriented programming in PHP.

3.0.0(5y ago)1.7k180.5k—0%164[4 issues](https://github.com/lisachenko/go-aop-php/issues)[1 PRs](https://github.com/lisachenko/go-aop-php/pulls)3MITPHPPHP ^7.4.0CI passing

Since Jan 8Pushed 1mo ago83 watchersCompare

[ Source](https://github.com/lisachenko/go-aop-php)[ Packagist](https://packagist.org/packages/lisachenko/go-aop-php)[ Docs](http://go.aopphp.com/)[ GitHub Sponsors](https://github.com/lisachenko)[ RSS](/packages/lisachenko-go-aop-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (43)Used By (3)

Go! Aspect-Oriented Framework for PHP
-------------------------------------

[](#go-aspect-oriented-framework-for-php)

This framework brings **Aspect-Oriented Programming** to PHP — a powerful paradigm for handling cross-cutting concerns that don't fit neatly into traditional OOP like logging, caching, and security checks across hundreds of methods. **Go! AOP** solves this problem elegantly—define such behaviors as aspect classes **once**, and **apply them automatically everywhere** when needed. Your business logic stays clean, your infrastructure code stays organized.

[![GitHub Workflow Status](https://camo.githubusercontent.com/8c0af4a202f601860f6f8d0fd03761a641d19ac3139076f06dc68e894e6d16f5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f676f616f702f6672616d65776f726b2f706870756e69742e796d6c3f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/8c0af4a202f601860f6f8d0fd03761a641d19ac3139076f06dc68e894e6d16f5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f676f616f702f6672616d65776f726b2f706870756e69742e796d6c3f6272616e63683d6d6173746572)[![PHPStan Badge](https://camo.githubusercontent.com/3a6d38fc5ef50cf5af3f711e5e857a2ce964a35205fd11bbfacc1add9559a748/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e2e7376673f7374796c653d666c6174266c696e6b3d68747470732533412532462532467068707374616e2e6f7267253246757365722d677569646525324672756c652d6c6576656c73)](https://camo.githubusercontent.com/3a6d38fc5ef50cf5af3f711e5e857a2ce964a35205fd11bbfacc1add9559a748/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e2e7376673f7374796c653d666c6174266c696e6b3d68747470732533412532462532467068707374616e2e6f7267253246757365722d677569646525324672756c652d6c6576656c73)[![GitHub release](https://camo.githubusercontent.com/f646581a91ee9a6d44b7bcb6f0bcea7b2fada2e0c72ad966d1a8308321499daa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f676f616f702f6672616d65776f726b2e737667)](https://github.com/goaop/framework/releases/latest)[![Total Downloads](https://camo.githubusercontent.com/c12cdf1ed5de9d3579a8d088d6336eab98d44811c87d606343e6470713b29346/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f616f702f6672616d65776f726b2e737667)](https://packagist.org/packages/goaop/framework)[![Daily Downloads](https://camo.githubusercontent.com/7e9e094a37fe6dd3cb91c20f0099415dc19f175de55d354c5519e6fb4798b660/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f676f616f702f6672616d65776f726b2e737667)](https://packagist.org/packages/goaop/framework)[![Minimum PHP Version](https://camo.githubusercontent.com/30bbb243688cbc50d4ea30e2e11f2d98338a2c08b067d019a09ecc7e66a18cc4/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e342d3838393242462e737667)](https://www.php.net/supported-versions.php)[![License](https://camo.githubusercontent.com/92aa701707799aee9ecf06d197f7acb9a230f22609dba3aec7e9d59602ce7c03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f676f616f702f6672616d65776f726b2e737667)](https://packagist.org/packages/goaop/framework)[![Sponsor](https://camo.githubusercontent.com/bb12d9dc1322843f286cc097e773f46484771b3a0c3980fa8aebed6cb736e447/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d2545322539442541342545462542382538462d6c69676874677261793f7374796c653d666c6174266c6f676f3d676974687562)](https://github.com/sponsors/lisachenko)

✨ Features
----------

[](#-features)

### 🔌 Zero Dependencies, Pure PHP

[](#-zero-dependencies-pure-php)

- **No PECL/PIE extensions required** — Forget about `php-aop`, `runkit`, `uopz`, or any other low-level extensions. Go! AOP is written in **100% pure PHP** — just `composer require` and you're ready. No compilation, no system dependencies, no deployment headaches.
- **Zero `eval()` calls** — Your architecture team will love this. Framework never uses `eval()`, `create_function()` constructions for dynamic code execution. All transformations produce **static PHP files** that can be reviewed, scanned by security tools, and audited. No hidden code generation at runtime.
- **PHPStan Level 10** — The entire codebase passes **PHPStan's strictest analysis level** — maximum type safety, no mixed types escaping, full type-aware support. This means fewer bugs, better IDE autocompletion, and confidence that the framework won't introduce type errors into your application.

### 🎯 Powerful Core Interception Capabilities

[](#-powerful-core-interception-capabilities)

The framework provides powerful core interception capabilities that can be used to hook into any method in your application:

FeatureSupportInterception of public &amp; protected methods✅Interception of static and final methods✅Interception of private methods✅Interception of methods in `final` classes✅Interception of trait methods✅Interception of enum methods (PHP 8.1+)✅Before, After and Around type of hooks✅### 🛠️ Developer Experience

[](#️-developer-experience)

- **Rich pointcut syntax** — Express complex matching rules with an intuitive, readable grammar. Target methods by visibility, name patterns, annotations, class hierarchy, and more — all in a single expression like `execution(public **->save*(*))`.
- **Full XDebug support** — Unlike other AOP solutions that generate unreadable proxy code, the framework produces clean, debuggable PHP. Set breakpoints directly in your aspects or original classes — step through code naturally, inspect variables, and debug as if AOP wasn't there.
- **Readable weaved code** — No magic methods, no `__call()` indirection or runtime proxies. The transformed source is plain PHP that you can read, understand, and audit. What you see in the cache is what gets executed.
- **Framework-agnostic** — integrates with popular frameworks and vanilla PHP. Works equally well in legacy applications or greenfield projects — no architectural changes required.

### ⚡ Production Ready

[](#-production-ready)

- **Lightning fast** — Quick start in just **few ms**. Aspects are initialized once and cached, so subsequent requests have virtually zero initialization overhead.
- **Opcode cache friendly** — First-class support for **OPcache**. Transformed files and classes are stored as plain PHP files, fully optimized by your opcode cache just like regular code.
- **Smart caching** — Lazy loading of advice and aspects — only what's needed gets loaded. Joinpoints are resolved at compile-time and cached, eliminating runtime reflection costs.
- **No runtime overhead** — Zero runtime annotation parsing, no slow `__call` methods, no proxy objects wrapping your instances. Method interception happens through direct, inlined PHP code — as fast as handwritten cross-cutting code. **Zero** overhead for non-intercepted methods.

What is AOP?
------------

[](#what-is-aop)

[Aspect-Oriented Programming (AOP)](http://en.wikipedia.org/wiki/Aspect-oriented_programming) is a programming paradigm that complements Object-Oriented Programming by solving a fundamental problem: **cross-cutting concerns**.

### The Problem with Traditional OOP

[](#the-problem-with-traditional-oop)

In OOP, we organize code into classes with clear responsibilities. But some behaviors refuse to fit neatly into this model — they cut *across* many classes:

- **Logging** — you need it in dozens of methods across your application
- **Caching** — scattered throughout services and repositories
- **Security checks** — repeated before every sensitive operation
- **Transaction management** — wrapping multiple database operations
- **Performance monitoring** — measuring execution time everywhere

With pure OOP, you end up copying the same code into hundreds of places. When requirements change, you hunt through the entire codebase. This is called **code scattering** and **code tangling** — and it violates the DRY and DDD principle at scale.

### The AOP Solution

[](#the-aop-solution)

AOP introduces a simple but powerful idea: **define cross-cutting behavior once, apply it automatically wherever needed**.

Think of it like life advice. Your mentor doesn't follow you around repeating "check your inputs before every decision." Instead, they give you one piece of advice that you apply in many situations. AOP works the same way — you write the advice once, and the framework applies it at the right moments.

### Core Concepts

[](#core-concepts)

ConceptWhat It MeansReal-World Analogy**Aspect**A module containing cross-cutting logic (logging, caching, etc.)A chapter in a guidebook covering the document signing process**Join Point**A specific moment in code execution — method call, property access, object creationA decision point in your day where advice could apply**Advice**The actual code that runs at a join pointThe specific guidance: "Before signing the document, read everything"**Pointcut**A pattern that selects which join points to targetThe rule for *when* advice applies: "Before signing *any* contract"**Weaving**The process of applying aspects to your codeThe mentor's words becoming part of your thinking### Types of Advice

[](#types-of-advice)

Just like life advice can be applied at different moments, AOP advice has different timing:

Advice TypeWhen It RunsExample Use Case**Before**Right before the method executesValidate input, check permissions**After (Finally)**Always, regardless of outcomeRelease resources, stop timers**Around**Wraps the entire executionCaching, transactions, retry logic**After Throwing**When an exception is thrownLog errors, send alerts**Around advice** is the most powerful — it controls **whether the original method runs at all**, can modify arguments, change return values, or handle exceptions.

### Advanced: Introductions

[](#advanced-introductions)

Go! AOP can do more than intercept behavior — it can **add entirely new capabilities** to existing classes. This is called an **Introduction** (or inter-type declaration).

Want all your DTOs to implement `Serializable`? Instead of modifying every class, declare it once in an aspect — Go! AOP adds the interface and implementation automatically. No inheritance hierarchies, no code duplication.

### How Go! AOP Works

[](#how-go-aop-works)

Unlike frameworks requiring special compilation steps, Go! AOP performs **runtime weaving** — it transforms your classes when they're loaded into PHP. No build process, no generated files to commit. Your original source code stays untouched, and the framework handles everything transparently.

Installation
------------

[](#installation)

Go! AOP framework can be installed with composer. Installation is quite easy:

1. Download the framework using composer
2. Create an application aspect kernel
3. Configure the aspect kernel in the front controller
4. Create an aspect
5. Register the aspect in the aspect kernel

### Step 0 (optional): Try demo examples in the framework

[](#step-0-optional-try-demo-examples-in-the-framework)

Ask composer to create a new project in empty directory:

```
composer create-project goaop/framework
```

After that configure your web server to `demos/` folder and open it in your browser. Then you can look at some demo examples before going deeper into installing it in your project.

### Step 1: Download the library using composer

[](#step-1-download-the-library-using-composer)

Ask composer to download the latest version of Go! AOP framework with its dependencies by running the command:

```
composer require goaop/framework
```

Composer will install the framework to your project's `vendor/goaop/framework` directory.

### Step 2: Create an application aspect kernel

[](#step-2-create-an-application-aspect-kernel)

The aim of this framework is to provide easy AOP integration for your application. You have to first create the `AspectKernel` class for your application. This class will manage all aspects of your application in one place.

The framework provides base class to make it easier to create your own kernel. To create your application kernel, extend the abstract class `Go\Core\AspectKernel`

```
