何でもインターセプトポイントカットのプレイグラウンド

ルールを書けば、マッチが見える。

名前、可視性、戻り値の型、属性でコードを狙えます。ポイントカットと PHP のソースを編集すると、マッチしたものがすべてコード上で直接ハイライトされます。

Selects 12 joinpoints · 2 can’t be intercepted

Start with an example. Make it your own.

Playground.phpeditable

Selected joinpoints

This matcher runs in your browser and reads one file, following the documented grammar. The weaver itself reflects your real classes, their parents and traits.

ポイントカット早見表

プレイグラウンドが理解する書き方で、フレームワークのポイントカットリファレンスに基づいています。引数はマッチングに使われず、引数リストは常に (*) です。

ポイントカット

execution(public App\Service->save(*))
インスタンスメソッドの呼び出し
execution(public App\Service::create(*))
static メソッドの呼び出し
execution(App\Service\file_get_contents(*))
その名前空間のコードからの PHP 関数の呼び出し
access(public App\Entity\User->email)
プロパティの読み書き
within(App\Model\*)
マッチしたクラスのすべてのメソッドとプロパティ
initialization(App\Model\Order)
new によるオブジェクトの生成
staticinitialization(App\Model\*)
マッチしたクラスの最初の読み込み
@execution(App\Attribute\Logged)
その属性を持つメソッド
@access(App\Attribute\Audited)
その属性を持つプロパティ
@within(App\Attribute\Monitored)
その属性を持つクラスのすべてのメンバー

パターンと演算子

*
名前の 1 区切り内の任意の文字。\ をまたがない
**
任意の深さの名前空間:App\** は App 配下のすべてのクラス
get*|is*
名前の 1 区切り内での選択肢
Foo+
Foo、そのサブクラスと実装クラス、トレイト Foo を使うクラス
public|protected
修飾子の選択肢。final、readonly、private(set) も可
: App\Entity|null
宣言された戻り値の型で絞り込む
&& || ! ( )
ポイントカットの組み合わせ、否定、グループ化
matchInherited()
継承したメンバー、またはトレイトから取り込んだメンバーのみ
ポイントカットの完全なリファレンス
属性ドリブン

独自の振る舞い属性を定義する。

独自の PHP 属性を作り、そこに振る舞いを結びつけ、必要なメソッドにだけ付けます。アプリケーションのコードはフレームワークに依存しないままです。

IDEA プラグインを使うと、属性の中でポイントカットの構文ハイライトと自動補完が使えます。

src/Attribute/Transactional.phpあなたのコード
#[\Attribute(\Attribute::TARGET_METHOD)]final class Transactional {}
src/Aspect/TransactionAspect.phpトランザクション
final class TransactionAspect implements Aspect{    #[Around('@execution(App\Attribute\Transactional) && !within(App\Legacy\**)')]    public function inTransaction(MethodInvocation $invocation): mixed    {        return $this->db->transactional(            fn () => $invocation->proceed()        );    }}
src/Order/OrderService.phpドメイン
#[Transactional]public function placeOrder(Cart $cart): Order{    return $this->orders->create($cart);}