
ステップ実行できない魔法はありません。
生成されたコードだからといって、振る舞いが隠れているわけではありません。フレームワークが生成するのは読みやすい PHP で、いつものツールで確認、diff、デバッグ、ステップ実行ができます。
あなたのコードと PHP のあいだに、隠れたものはない
実行されるのは、読めて、ステップ実行できて、中身を問い合わせられる素の PHP です。
あなたのクラスと、実際に動くもの
キャッシュの振る舞いを持つレポートサービスと、フレームワークがそのために書き出す 2 つのファイルです。どちらも、下でステップ実行できるセッションの実際のファイルです。
あなたのソース
キャッシュの振る舞いが #[Cacheable] で付いています。開いて読み、ブレークポイントを置くのはこのファイルです。
<?php
declare(strict_types=1);
namespace App\Report;
use App\Attribute\Cacheable;
class ReportService
{
public function __construct(private OrderRepository $orders) {}
#[Cacheable(ttl: 300)]
キャッシュの振る舞いを付与
public function monthlyRevenue(string $month): int
{
$total = 0;
ここで止まる
foreach ($this->orders->forMonth($month) as $order) {
$total += $order->cents;
}
return $total;
}
}
ウィービング後のソース
クラスの本体がトレイトになります。変わるのは宣言の行だけなので、行番号はすべてそのままです。デバッグモードでは PHP がこれを元のパスで読み込むので、デバッガーは src/Report/ReportService.php で止まります。
<?php
declare(strict_types=1);
namespace App\Report;
use App\Attribute\Cacheable;
trait ReportServiceOriginalTrait
元:class ReportService
{
public function __construct(private OrderRepository $orders) {}
#[Cacheable(ttl: 300)]
public function monthlyRevenue(string $month): int
{
$total = 0;
foreach ($this->orders->forMonth($month) as $order) {
$total += $order->cents;
}
return $total;
}
}
include_once AOP_CACHE_DIR . '/Report/ReportService.php';
プロキシクラス
PHP が読み込むクラスです。クラス名は同じなので、スタックトレースには ReportService と表示されます。ミドルウェアは読みやすい 1 つのメソッドで、ジョインポイントを一度だけ組み立て、それを実行します。
<?php
declare(strict_types=1);
namespace App\Report;
use Go\Aop\Framework\InterceptorInjector;
use Go\Aop\Framework\Interceptor;
use Go\Aop\Framework\The;
use App\Aspect\CachingAspect;
use Go\Aop\Intercept\DynamicMethodInvocation;
use App\Attribute\Cacheable as Cacheable;
class ReportService implements \Go\Aop\Proxy
同じクラス名
{
use ReportServiceOriginalTrait {
クラスの本体
ReportServiceOriginalTrait::monthlyRevenue as private monthlyRevenueOriginalAlias;
}
#[\App\Attribute\Cacheable(ttl: 300)]
public function monthlyRevenue(string $month): int
{
/** @var DynamicMethodInvocation<self, int> $__joinPoint */
static $__joinPoint = InterceptorInjector::forMethod(
初回の呼び出しで一度だけ生成
self::class,
'monthlyRevenue',
[
Interceptor::around(The::aspect(CachingAspect::class)->cache(...)),
Ctrl+クリックで CachingAspect::cache() へ
],
$this->monthlyRevenueOriginalAlias(...),
元のメソッド
);
return $__joinPoint->__invoke($this, [$month]);
ミドルウェアを実行
}
}
自分で書いたコードと同じようにデバッグ
同じクラスの実際のデバッグセッションを記録し、ブラウザーで再生します。呼び出しにステップインし、ガターにブレークポイントを置き、どのフレームでも開けます。各ステップで何が起きるかは、ガイドが説明します。
Frames
Variables
Console timed under the debugger
何をしたのか、ウィーバーに聞く
フレームワークに付属するコンソールは、カーネルについての質問に答えます。どの振る舞いクラスがあり、それぞれが何に届くのか。キャッシュを事前にウィービングすることもできます。コマンドを順にスクロールしてください。ターミナルには、上のアプリに対する実際の出力が表示されます。
Run the app
php bin/report.phpThe same app, without the debugger. The first call runs the slow query; the second comes from the caching behavior in a hundredth of a millisecond.
List the behavior classes
vendor/bin/aspect debug:aspect bootstrap.phpEvery behavior class (an aspect, in the API) your kernel registers, the file it is defined in, and the advisors it declares. The loader file only boots the kernel; it must not handle a request.
List the advisors
vendor/bin/aspect debug:advisor bootstrap.phpEach advisor with its pointcut. Here there is one:
cache(), for every method marked#[Cacheable].See what an advisor reaches
vendor/bin/aspect debug:advisor bootstrap.php --advisor='App\Aspect\CachingAspect->cache'Analyzes every file below the include paths and lists the members the advisor matches:
monthlyRevenue(), and nothing else.Weave ahead of time
vendor/bin/aspect cache:warmup:aop bootstrap.phpWeaves every file at deploy time, so production serves the prebuilt cache. It fails when a file can’t be woven;
--workers=8weaves in parallel.
2026-10: 21199 cents in 156.16 ms 2026-10: 21199 cents in 0.01 ms
Aspect debug information ======================== App\AppKernel has following enabled aspects: App\Aspect\CachingAspect ------------------------ Defined in: /app/src/Aspect/CachingAspect.php Pointcuts and advices --------- --------------------------------- Type Identifier --------- --------------------------------- Advisor App\Aspect\CachingAspect->cache --------- ---------------------------------
Advisor debug information ========================= List of registered advisors in the container --------------------------------- ------------------------------------- Id Expression --------------------------------- ------------------------------------- App\Aspect\CachingAspect->cache @execution(App\Attribute\Cacheable) --------------------------------- ------------------------------------- If you want to query an information about concrete advisor, then just query it by adding --advisor="Advisor\Name" to the command
Advisor debug information ========================= Total 6 files to analyze. -> matching method App\Report\ReportService->monthlyRevenue
Total 6 files to process. [DONE]: Total processed 6, 0 errors in 5 ms.
振る舞いを作る。すべてデバッグできるまま。
多くのフレームワークは、魔法を信じるよう求めます。ここでは、実行されるすべての行を開いて、確認して、ステップ実行できます。