An open API service indexing awesome lists of open source software.

https://github.com/xtompie/aop


https://github.com/xtompie/aop

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

# Aop - Aspect-Orientend Programing for PHP

This library require changes in the original source code.

In simplified and generalized term AOP is Publish/Subscribe system with Middlewares.

## Requiments

PHP >= 8.0

## Installation

Using [composer](https://getcomposer.org/)

```
composer require xtompie/aop
```

## Docs

### 1. Creating Aspect

Aspect is a class implementing `Aspect` interface.

```php
$invocation->joinpoint(),
'args' => $invocation->args(),
'result' => $result,
]);
return $result;
}
}
```

Pointcut is a pattern that can match Joinpoint.
Pointcut can have a `*` character that describes any character in any number of occurrences.
If Pointcut dont have `*` it is equal to Joinpoint.

There is only one type of Advice - around. Before and after can be achive manualy or using `GenericAspect`.

### 2. Create AOP system

```php
__invoke($joinpoint, $args, $main);
}
```

### 3. Create joinpoint in service

```php
withArgs([$invocation->args()[0] + 5]);
return $invocation();
}
}
```

### 5. Changing aspect orders

The higher the order, the closer it is to the main invocation.

```php
args()[0] - 10;
}
}
```