PHPackages                             goaop/goaop-zend-expressive-middleware - 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. goaop/goaop-zend-expressive-middleware

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

goaop/goaop-zend-expressive-middleware
======================================

An Zend Expressive middleware for loading goaop aspects.

3.0.0(8y ago)33691[2 issues](https://github.com/goaop/goaop-zend-expressive-middleware/issues)[2 PRs](https://github.com/goaop/goaop-zend-expressive-middleware/pulls)MITPHPPHP &gt;=7.1CI failing

Since Nov 26Pushed 5y ago2 watchersCompare

[ Source](https://github.com/goaop/goaop-zend-expressive-middleware)[ Packagist](https://packagist.org/packages/goaop/goaop-zend-expressive-middleware)[ RSS](/packages/goaop-goaop-zend-expressive-middleware/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (8)Versions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/8ecec80b2f582f1d760b83b565afef8af00f289326334384006be1212a367d75/68747470733a2f2f7472617669732d63692e6f72672f676f616f702f676f616f702d7a656e642d657870726573736976652d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/reinfi/goaop-zend-expressive-middleware)

GoAop Expressive Middleware
===========================

[](#goaop-expressive-middleware)

The GoAop middleware adds support for Aspect-Oriented Programming via Go! AOP Framework for Zend Expressive applications.

Overview
--------

[](#overview)

Aspect-Oriented Paradigm allows to extend the standard Object-Oriented Paradigm with special instruments for effective solving of cross-cutting concerns in your application. This code is typically present everywhere in your application (for example, logging, caching, monitoring, etc) and there is no easy way to fix this without AOP.

AOP defines new instruments for developers, they are:

- Joinpoint - place in your code that can be used for interception, for example, execution of single public method or accessing of single object property.
- Pointcut is a list of joinpoints defined with a special regexp-like expression for your source code, for example, all public and protected methods in the concrete class or namespace.
- Advice is an additional callback that will be called before, after or around concrete joinpoint. For PHP each advice is represented as a `\Closure` instance, wrapped into the interceptor object.
- Aspect is a special class that combines pointcuts and advices together, each pointcut is defined as an annotation and each advice is a method inside this aspect.

You can read more about AOP in different sources, there are good articles for Java language and they can be applied for PHP too, because it's general paradigm.

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

[](#installation)

GoAopModule can be easily installed with composer. Just ask a composer to download the bundle with dependencies by running the command:

```
$ composer require goaop/goaop-zend-expressive-middleware
```

Add the `\Go\Zend\Expressive\Middleware\AspectMiddleware` to your list of middleswares in the config/pipeline.php:

```
$app->pipe(AspectMiddleware::class);
```

It is the best to add the middleware as early as possible, so that the AOP engine can take actions before any other middleware is applied.

Configuration
-------------

[](#configuration)

The default configuration in the `config/module.config.php` file. Copy this file to your own config directory to modify the values.

Configuration can be used for additional tuning of AOP kernel and source code whitelistsing/blacklisting.

```
// config/module.config.php

$moduleConfig = [
    /*
     |--------------------------------------------------------------------------
     | AOP Debug Mode
     |--------------------------------------------------------------------------
     |
     | When AOP is in debug mode, then breakpoints in the original source code
     | will work. Also engine will refresh cache files if the original files were
     | changed.
     | For production mode, no extra filemtime checks and better integration with opcache
     |
     */
    'debug' => false,

    /*
     |--------------------------------------------------------------------------
     | Application root directory
     |--------------------------------------------------------------------------
     |
     | AOP will be applied only to the files in this directory, change it if needed
     */
    'appDir' => $basicDirectory,

    /*
     |--------------------------------------------------------------------------
     | AOP cache directory
     |--------------------------------------------------------------------------
     |
     | AOP engine will put all transformed files and caches in that directory
     */
    'cacheDir' => $basicDirectory . '/data/cache/aspect',

    /*
     |--------------------------------------------------------------------------
     | Cache file mode
     |--------------------------------------------------------------------------
     |
     | If configured then will be used as cache file mode for chmod
     */
    'cacheFileMode' => 0770 & ~umask(),

    /*
     |--------------------------------------------------------------------------
     | Controls miscellaneous features of AOP engine
     |--------------------------------------------------------------------------
     |
     | See \Go\Aop\Features enumeration for bit mask
     */
    'features' => 0,

    /*
     |--------------------------------------------------------------------------
     | White list of directories
     |--------------------------------------------------------------------------
     |
     | AOP will check this list to apply an AOP to selected directories only,
     | leave it empty if you want AOP to be applied to all files in the appDir
     */
    'includePaths' => [
        $basicDirectory . '/module'
    ],

    /*
     |--------------------------------------------------------------------------
     | Black list of directories
     |--------------------------------------------------------------------------
     |
     | AOP will check this list to disable AOP for selected directories
     */
    'excludePaths' => [],

    /**
     |--------------------------------------------------------------------------
     | AOP container class
     |--------------------------------------------------------------------------
     |
     | This option can be useful for extension and fine-tuning of services
     */
    'containerClass' => GoAspectContainer::class,
];
```

Defining new aspects
--------------------

[](#defining-new-aspects)

Aspects are services in the ZF2 application and loaded into the AOP container by the integration module after putting them into the `goaop_aspect` section in the `application.config.php file`. Here is an example how to implement a logging aspect that will log information about public method invocations in the module/ directory.

Definition of aspect class with pointcut and logging advice

```
