PHPackages                             ray/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. [Framework](/categories/framework)
4. /
5. ray/aop

ActiveLibrary[Framework](/categories/framework)

ray/aop
=======

An aspect oriented framework

2.19.1(3mo ago)1042.3M↓12.1%3020MITPHPPHP ^8.2CI passing

Since Mar 31Pushed 3mo ago11 watchersCompare

[ Source](https://github.com/ray-di/Ray.Aop)[ Packagist](https://packagist.org/packages/ray/aop)[ GitHub Sponsors](https://github.com/koriym)[ Fund](https://tidelift.com/funding/github/packagist/ray/aop)[ RSS](/packages/ray-aop/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (94)Used By (20)

Ray.Aop
=======

[](#rayaop)

Aspect Oriented Framework
-------------------------

[](#aspect-oriented-framework)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1f8e69fe272e074ae08d2a9d00442dec091a21c52bd558ffb430cc2bf5e0a93c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7261792d64692f5261792e416f702f6261646765732f7175616c6974792d73636f72652e706e673f623d322e78)](https://scrutinizer-ci.com/g/Ray-Di/Ray.Aop/?branch=2.x)[![codecov](https://camo.githubusercontent.com/d8d16dc17bdeaa8a4c2b7b77386add2be97c0fd7015df73018404fcdcaa88981/68747470733a2f2f636f6465636f762e696f2f67682f7261792d64692f5261792e416f702f6272616e63682f322e782f67726170682f62616467652e7376673f746f6b656e3d4b435158747530317a63)](https://codecov.io/gh/ray-di/Ray.Aop)[![Type Coverage](https://camo.githubusercontent.com/23ecb29ac4ac1c9437fb30445fae2b190589ef09ec0604c280b8d3f526ee1ead/68747470733a2f2f73686570686572642e6465762f6769746875622f7261792d64692f5261792e416f702f636f7665726167652e737667)](https://shepherd.dev/github/ray-di/Ray.Aop)[![Continuous Integration](https://github.com/ray-di/Ray.Aop/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/ray-di/Ray.Aop/actions/workflows/continuous-integration.yml)[![Total Downloads](https://camo.githubusercontent.com/52f989904e5d49423733a1aa1014128258d964acfd41dd6422930f4459d7f29c/68747470733a2f2f706f7365722e707567782e6f72672f7261792f616f702f646f776e6c6f616473)](https://packagist.org/packages/ray/aop)

[![ray-di logo](https://camo.githubusercontent.com/a826cc4c0b7c71415633f338c0b5a2ec4d121f1b7f6d0b86fe9d3aa265f8ec0a/68747470733a2f2f7261792d64692e6769746875622e696f2f696d616765732f6c6f676f2e737667)](https://camo.githubusercontent.com/a826cc4c0b7c71415633f338c0b5a2ec4d121f1b7f6d0b86fe9d3aa265f8ec0a/68747470733a2f2f7261792d64692e6769746875622e696f2f696d616765732f6c6f676f2e737667)

[\[Japanese\]](https://github.com/ray-di/Ray.Aop/blob/2.x/README.ja.md)

**Ray.Aop** package provides method interception. This feature enables you to write code that is executed each time a matching method is invoked. It's suited for cross cutting concerns ("aspects"), such as transactions, security and logging. Because interceptors divide a problem into aspects rather than objects, their use is called Aspect Oriented Programming (AOP).

A [Matcher](https://github.com/ray-di/Ray.Aop/blob/2.x/src/MatcherInterface.php) is a simple interface that either accepts or rejects a value. For Ray.AOP, you need two matchers: one that defines which classes participate, and another for the methods of those classes. To make this easy, there's factory class to satisfy the common scenarios.

[MethodInterceptors](https://github.com/ray-di/Ray.Aop/blob/2.x/src/MethodInterceptor.php) are executed whenever a matching method is invoked. They have the opportunity to inspect the call: the method, its arguments, and the receiving instance. They can perform their cross-cutting logic and then delegate to the underlying method. Finally, they may inspect the return value or exception and return. Since interceptors may be applied to many methods and will receive many calls, their implementation should be efficient and unintrusive.

Example: Forbidding method calls on weekends
--------------------------------------------

[](#example-forbidding-method-calls-on-weekends)

To illustrate how method interceptors work with Ray.Aop, we'll forbid calls to our pizza billing system on weekends. The delivery guys only work Monday thru Friday so we'll prevent pizza from being ordered when it can't be delivered! This example is structurally similar to use of AOP for authorization.

To mark select methods as weekdays-only, we define an attribute.

```
