/goaop:aspect-oriented-developmentfrom goaop
Writes and reviews Go! AOP aspects, pointcuts, and advices in PHP. Helps integrate AOP into Symfony, Laravel, or Yii3, set up AspectKernel, manage AOP cache, and debug non-running advices.
Ships in goaop. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Go! AOP weaves aspects into PHP classes while they are loaded. It needs no PHP extension and never calls eval():
the woven code is plain PHP in a cache directory.
Version. This skill describes the attribute-based API (Go\Lang\Attribute\*, addLazyService()), which starts
with 4.0. The required PHP version is in the composer.json of the package. Older projects (3.x: registerAspect(),
protected advices, dynamic() pointcuts) use another API: do not apply this skill to them, and follow
UPGRADE-4.0.md of the package when the user wants to migrate.
Documentation of the framework. The skill is self-contained, and the documentation of the framework goes deeper.
Where a reference file names docs/<file>.md, find it here:
vendor/goaop/framework/docs/. It matches the installed version,
so it wins when it disagrees with this skill;docs/ in the root of that repository;| Term | Meaning in Go! AOP |
|---|---|
| Aspect | A class that implements Go\Aop\Aspect and holds advices. One aspect per concern. |
| Joinpoint | A point the framework can intercept: a method execution, a property read or write, a function call, object creation, the first load of a class. |
| Pointcut | A string expression that selects joinpoints, e.g. execution(public App\Service\*->save*(*)). |
| Advice | A public method of an aspect with #[Before], #[After], #[AfterThrowing] or #[Around]. It receives the joinpoint. The woven code refers to it as a first-class callable on the aspect, The::aspect(LoggingAspect::class)->logCall(...), so at runtime an advice is a Closure of that method. |
| Weaving | Rewriting a class so that the selected joinpoints call the advices. |
| Introduction | #[DeclareParents]: adds an interface and a trait that implements it to the matching classes. |
When Composer loads a class below the include paths, the framework moves the class body into a trait
<Class>OriginalTrait and generates a class with the original name that uses the trait. Every advised method is
re-declared there and calls the interceptor chain, then the original body through a private alias. The class keeps its
name, parent and interfaces; no object is wrapped.
Four consequences decide most questions:
$this->helper(), private, static and final methods and methods of final classes
are intercepted too, because the method itself is replaced. There is no "self-invocation" problem as with proxy
objects in other AOP tools.appDir and inside includePaths. A class loaded earlier, an internal PHP class or a
class outside these paths is never changed, and nothing reports it.debug off) the woven classes are served from the cache: an edited
source file, aspect or pointcut has no effect until the cache is rebuilt. This is the most common reason for "my
change does nothing". Develop in debug mode.An aspect fits a concern that is the same in many places and independent of the business logic around it: logging, metrics, caching, transactions, retries, circuit breakers, rate limits, authorization checks, audit trails.
Prefer plain code when the behaviour belongs to one or two methods, when the callers must be able to see it, or when it
is business logic. An aspect acts at a distance: someone reading OrderService::place() does not see it. Three habits
keep that manageable:
#[Transactional], #[Cacheable(ttl: 60)]) and an @execution(...)
pointcut where possible. The method then shows that something applies to it, and the attribute carries the
per-method settings.Look at composer.json before anything else. Most applications run on a framework, and for those the integration is
a ready-made package that initializes the kernel at the right moment, takes aspects from the service container, adds
console commands and builds the cache with the usual deployment commands. Doing this by hand repeats problems the
bridges already solved.
| Application | Use | Then read |
|---|---|---|
| Symfony | goaop/goaop-symfony-bundle | references/frameworks.md |
| Laravel | goaop/goaop-laravel-bridge | references/frameworks.md |
| Yii3 | goaop/goaop-yii3-bridge | references/frameworks.md |
| Another framework | Propose a reusable bridge first, see "A framework without a bridge" in references/frameworks.md | references/frameworks.md, references/setup.md |
| Plain PHP, a legacy application, a library | An AspectKernel of your own | references/setup.md |
If the bridge of the framework is not installed yet, install it instead of writing a kernel.
Write the pointcut. Read references/pointcuts.md when you need more than a simple execution(...):
wildcards, | and + have rules that are easy to get wrong.
Write the aspect: a class implementing Go\Aop\Aspect, one public method per advice.
references/advices.md has the joinpoint API and the execution order; references/recipes.md has complete,
tested aspects for the usual concerns.
Register it. With a bridge, the way the bridge discovers aspects (references/frameworks.md); otherwise in
configureAop() of the kernel. An aspect that is not registered is silently ignored.
Verify that it matches. Do not assume: a pointcut that matches nothing is not an error. The debug:advisor
command lists every member an advisor matches; the advisor id is <aspect class>-><advice method>.
| Integration | Command |
|---|---|
| Symfony | bin/console debug:advisor --advisor='App\Aspect\LoggingAspect->log' |
| Laravel | no such command: read the woven class, see below |
| Yii3 | ./yii aop:debug:advisor --advisor='App\Aspect\LoggingAspect->log' |
| Own kernel | vendor/bin/aspect debug:advisor public/index.php --advisor='App\Aspect\LoggingAspect->log' |
Inside a framework the command runs on the kernel the application initialized. Only vendor/bin/aspect takes
the file that initializes the kernel as its first argument, and it needs symfony/console. Where no such
command is available, run the code once in debug mode and read the woven class:
references/troubleshooting.md, "Looking at the woven code".
Run the code and check the behaviour. In production mode, rebuild the cache first.
<?php
declare(strict_types=1);
namespace App\Aspect;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Attribute\Around;
use Psr\Log\LoggerInterface;
final class TimingAspect implements Aspect
{
public function __construct(
private readonly LoggerInterface $logger,
) {}
#[Around('execution(public App\Service\**->*(*)) && !execution(public **->__construct(*))')]
public function measure(MethodInvocation $invocation): mixed
{
$start = hrtime(true);
try {
return $invocation->proceed();
} finally {
$this->logger->debug('{method} took {ms} ms', [
'method' => (string) $invocation,
'ms' => (hrtime(true) - $start) / 1e6,
]);
}
}
}
With a bridge the aspect is an ordinary service of the application: the container injects the logger. With a kernel
of your own it is registered in configureAop():
$container->addLazyService(
TimingAspect::class,
static fn(AspectContainer $c): TimingAspect => new TimingAspect($c->getService(LoggerInterface::class)),
);
These come from the framework, each with its reason. Breaking one either throws while weaving or, worse, does nothing.
public. The generated code calls them as first-class callables on the aspect instance.
A protected or private advice throws AspectException. Methods that only carry #[Pointcut] may have any
visibility.AspectException. Write two methods that share a named
pointcut.(*). Arguments are not matched; ->save() and ->save(int) are
syntax errors.* stays inside one namespace level, ** crosses levels. App\*->*(*) matches classes directly in App
only; App\**->*(*) matches every class below it.$this->name is not interpolated.#[Around] advice returns the result. Return $invocation->proceed() unless you replace the result on
purpose. Without the return the caller gets null, or PHP throws a TypeError ("none returned") when the
advice declares a return type.#[After] and #[Before] cannot change the result. #[After] runs like finally, also after an exception.
#[AfterThrowing] gets the exception as the second parameter and cannot swallow it. To change a result or to
handle an exception, use #[Around].#[Before] advice skips everything else, the #[After] and #[AfterThrowing]
advices of the same joinpoint included.AspectCircularReferenceException.access(...) works for instance properties. Static, readonly and already hooked properties are
not intercepted, and a pointcut that only matches those does nothing.init() call right after
vendor/autoload.php. An entry point without it runs the application without aspects.Aspects cost nothing where they do not apply: a method or property without advice in a woven class runs at full
speed. An intercepted call costs about a third of a microsecond plus the advice itself, and booting the kernel in
production about 0.15 ms per request, measured by the framework's benchmark. Production speed depends on running in
production mode with a prebuilt cache and OPcache. Before answering a performance question or tuning a deployment,
read references/performance.md: it has the measured numbers, their conditions and the checklist.
| Read | When |
|---|---|
references/frameworks.md | The application runs on Symfony, Laravel, Yii3 or another framework: installing the bridge, registering aspects, commands, deployment |
references/setup.md | Plain PHP or no bridge: the kernel and its options, entry points, dependencies of aspects, tests, deployment, console commands |
references/pointcuts.md | Writing or reviewing any pointcut that is not trivial |
references/advices.md | Joinpoint methods, execution order, changing arguments and results, properties, functions, new, introductions, PHPStan generics |
references/recipes.md | A complete aspect for logging, caching, transactions, retry, authorization, metrics, circuit breaker or rate limiting |
references/performance.md | What aspects cost, production checklist, OPcache, preloading, containers, writing fast aspects |
references/troubleshooting.md | An advice does not run, an exception while weaving, stale cache, limitations |
references/advices.md (opens in a new tab)references/frameworks.md (opens in a new tab)references/performance.md (opens in a new tab)references/pointcuts.md (opens in a new tab)references/recipes.md (opens in a new tab)references/setup.md (opens in a new tab)references/troubleshooting.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
2 skills in this plugin
npx claudepluginhub goaop/framework --plugin goaopOther plugins' skills for the same job