PHPackages                             okapi/aop - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. okapi/aop

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

okapi/aop
=========

PHP AOP is a PHP library that provides a powerful Aspect Oriented Programming (AOP) implementation for PHP.

1.2.16(1y ago)3812.0k↓29.2%3[30 issues](https://github.com/okapi-web/php-aop/issues)MITPHPPHP &gt;=8.1CI passing

Since Jun 5Pushed 1y ago6 watchersCompare

[ Source](https://github.com/okapi-web/php-aop)[ Packagist](https://packagist.org/packages/okapi/aop)[ Docs](https://github.com/okapi-web/php-aop)[ RSS](/packages/okapi-aop/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (22)Used By (0)

PHP AOP
=======

[](#php-aop)

 [ ![License: MIT](https://camo.githubusercontent.com/18265ffa710f93b46bd4f74b3de525cb270501a5e50987f0846adcb14f16d144/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d3943303030302e7376673f6c6162656c436f6c6f723d656264626232267374796c653d666c6174266c6f676f3d646174613a696d6167652f7376672b786d6c3b6261736536342c50484e325a79423462577875637a30696148523063446f764c336433647935334d793576636d63764d6a41774d43397a646d6369494864705a48526f505349784e434967614756705a326830505349784e43492b5048426864476767646d566a644739794c57566d5a6d566a64443069626d39754c584e6a59577870626d6374633352796232746c4969426b50534a4e4d4341794c6a6b354e5767784c6a4934646a67754d4446494d48704e4d6934314e43417a614445754d6a68324e53347a4e4567794c6a5530656d30794c6a55314c5334774d44566f4d5334794f4859344c6a4178534455754d446c36625449754e5451754d444133614445754d6a68324d53347a4d7a5a494e7934324d336f6949475a706247773949694d35597a41774d4441694c7a343863474630614342325a574e30623349745a575a6d5a574e3050534a756232347463324e6862476c755a79317a64484a766132556949475139496b30334c6a597a494455754e6a5a6f4d5334794f4659784d5567334c6a597a656949675a6d6c7362443069497a646a4e3251335a534976506a78775958526f49485a6c593352766369316c5a6d5a6c59335139496d35766269317a593246736157356e4c584e30636d39725a5349675a443069545445774c6a45334e79417a4c6a41774d6d677a4c6a67794e6e59784c6a4d7a4e6d67744d7934344d6a5a36625334774d444d674d6934324e54686f4d5334794f4659784d5767744d5334794f486f6949475a706247773949694d35597a41774d4441694c7a34384c334e325a7a343d) ](https://opensource.org/licenses/MIT) [ ![Twitter: @WalterWoshid](https://camo.githubusercontent.com/f13714295371522a87e6ccf86f7237671551e94e4d84d78b2c2202a1364f3a98/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4057616c746572576f736869642d547769747465723f6c6162656c436f6c6f723d656264626232267374796c653d666c6174266c6f676f3d74776974746572266c6f676f436f6c6f723d34353835383826636f6c6f723d343538353838266c6162656c3d54776974746572) ](https://twitter.com/WalterWoshid) [ ![PHP: >=8.1](https://camo.githubusercontent.com/3d23282673d805b43b73597a18573b828980c60b3b44645f95480365a0722307/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d3e3d382e312d3443353738392e7376673f6c6162656c436f6c6f723d656264626232267374796c653d666c6174266c6f676f3d706870266c6f676f436f6c6f723d344335373839) ](https://www.php.net) [ ![Packagist](https://camo.githubusercontent.com/ed82804cc244279a9a50a25bc770152d1294db4c674dd2c1065eb4962e9a8b03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6b6170692f616f703f6c6162656c3d5061636b6167697374266c6162656c436f6c6f723d656264626232267374796c653d666c617426636f6c6f723d666538303139266c6f676f3d7061636b6167697374) ](https://packagist.org/packages/okapi/aop) [ ![Build](https://camo.githubusercontent.com/347175b1559edcfab3d91cd25eb55353b161d0f8f44c106ce3b83c94ca0c26d3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f6b6170692d7765622f7068702d616f702f74657374732e796d6c3f6c6162656c3d4275696c64266c6162656c436f6c6f723d656264626232267374796c653d666c6174266c6f676f3d646174613a696d6167652f7376672b786d6c3b6261736536342c50484e325a79423462577875637a30696148523063446f764c336433647935334d793576636d63764d6a41774d43397a646d6369494864705a48526f505349784e694967646d6c6c64304a76654430694d434177494455784d6941314d5449694947686c6157646f644430694d545969506a78775958526f49475a706247773949694d32595746694d6a416949475139496b307a4d7934354d5451674e44457a4c6a59784d6d67784e446b754e5456324d6a63754e546b31534449334c6a51354e474d744d6a59754d7a5134494441744d7a51754d544d324c54457a4c6a45354e4330794d5334334d6a6b744d7a51754d7a464d4d544d334c6a6b78494445344e7934334e544e574e6a45754f546331614330794e6934774e7a566a4c5445354c6a55774e4341774c5445354c6a55774e4330794e7934314f5455674d4330794e7934314f54566f4d5467354c6a6b7a597a45354c6a55774e534177494445354c6a55774e5341794e7934314f5455674d4341794e7934314f5456494d6a63314c6a5935646a457a4d6934344d6a686f4c5449334c6a6b324d3159324d5334354e7a566f4c5467784c6a67314e4859784d7a49754f44493454444d7a4c6a6b784e4341304d544d754e6a4579656d30784d7a55754e6930784e6a6b754d546733544467304c6a59354d69417a4f4459754e546330614463774c6a59774d5777784d4451754d7a63314c5445784d6934354d4463744d5455754e5467794c5449354c6a49304d6d67744e7a51754e546436625445304e5334354f5459674f5334334f444e4d4d6a41354c6a55674d7a59334c6a55774e6d77784d4459754d4445674d5445774c6a49344e69417a4d7934314d7a67744d7a4d754e544d344c5467774c6a59314c5463324c6a63304f4341344d4334324e5330334f5334334e69307a4d7934314d7a67744d7a4d754e544d34656d30314e6934354e444d674d7a4d754e544d33494467774c6a5931494463354c6a63324c5467774c6a5931494463324c6a633149444d7a4c6a557a4f43417a4d7934314d7a644d4e54457949444d324e7934314d4459674e4441314c6a6b35494449314e4334794d4468734c544d7a4c6a557a4e79417a4d7934314d7a64364969382b5043397a646d632b) ](../../actions/workflows/tests.yml)

 [ ![Coverage - PHP 8.1](https://camo.githubusercontent.com/749b45205571575c35a55ba2b2ba6b1dffc4c5579e545f90a16286f70378f933/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6f6b6170692d7765622f7068702d616f703f666c61673d6f732d7562756e74752d6c61746573745f7068702d382e31266c6162656c3d436f766572616765202d2050485020382e31266c6162656c436f6c6f723d656264626232267374796c653d666c6174266c6f676f3d636f6465636f76266c6f676f436f6c6f723d46464331303726636f6c6f723d464643313037) ](https://app.codecov.io/gh/okapi-web/php-aop/flags) [ ![Coverage - PHP 8.2](https://camo.githubusercontent.com/d9e70be2e8d14954c14081241f2453edbf346eb4acca646fc82e9aa444a72d84/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6f6b6170692d7765622f7068702d616f703f666c61673d6f732d7562756e74752d6c61746573745f7068702d382e32266c6162656c3d436f766572616765202d2050485020382e32266c6162656c436f6c6f723d656264626232267374796c653d666c6174266c6f676f3d636f6465636f76266c6f676f436f6c6f723d46464331303726636f6c6f723d464643313037) ](https://app.codecov.io/gh/okapi-web/php-aop/flags)

 PHP AOP is a PHP library that provides a powerful Aspect Oriented Programming (AOP) implementation for PHP.
-------------------------------------------------------------------------------------------------------------

[](#--php-aop-is-a-php-library-that-provides-a-powerful-aspect-oriented-programming---aop-implementation-for-php)

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

[](#installation)

```
composer require okapi/aop
```

Usage
=====

[](#usage)

📖 List of contents
------------------

[](#-list-of-contents)

- [Terminology](#terminology)
- [Implicit Aspects](#implicit-aspects)
    - [Create a Kernel](#create-a-kernel)
    - [Create an Aspect](#create-an-aspect)
    - [Target Classes](#target-classes)
    - [Initialize the Kernel](#initialize-the-kernel)
    - [Result](#result)
- [Class-Level Explicit Aspects](#class-level-explicit-aspects)
    - [Create an Aspect](#create-an-aspect-1)
    - [Target Classes](#target-classes-1)
    - [Initialize the Kernel](#initialize-the-kernel-1)
    - [Result](#result-1)
- [Method-Level Explicit Aspects](#method-level-explicit-aspects)
    - [Create an Aspect](#create-an-aspect-2)
    - [Target Classes](#target-classes-2)
    - [Initialize the Kernel](#initialize-the-kernel-2)
    - [Result](#result-2)
- [Features](#features)
- [Limitations](#limitations)
- [How it works](#how-it-works)
- [Testing](#testing)
- [Contributing](#contributing)

Terminology
-----------

[](#terminology)

- **AOP**: Aspect Oriented Programming - A programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.
- **Aspect**: A class that implements the logic that you want to apply to your target classes. Aspects must be annotated with the `#[Aspect]` attribute.
- **Advice**: The logic that you want to apply to your target classes. Advice methods must be annotated with the `#[Before]`, `#[Around]` or `#[After]`attributes.
- **Join Point**: A point in the execution of your target classes where you can apply your advice. Join points are defined by the `#[Before]`, `#[Around]` or `#[After]` attributes.
- **Pointcut**: A set of join points where you can apply your advice. Pointcuts are defined by the `#[Pointcut]` attribute.
- **Weaving**: The process of applying your advice to your target classes.
- **Implicit Aspects**: The aspects are applied without any modification to the target classes. The aspect itself specifies the classes or methods it applies to.
- **Class-Level Explicit Aspects**: The aspects are applied by modifying the target classes, typically by adding the aspect as an attribute to the target class.
- **Method-Level Explicit Aspects**: The aspects are applied by modifying the target classes, typically by adding the aspect as an attribute to the target method.

Implicit Aspects
----------------

[](#implicit-aspects)

Click to expand### Create a Kernel

[](#create-a-kernel)

```
