Skip to content

Commit 39b401d

Browse files
committed
Merge remote-tracking branch 'origin/1.x'
* origin/1.x: Added some documentation and LICENCE 1.0 versions of goaop/framework should be stable now
2 parents 23bb96f + 297df17 commit 39b401d

File tree

4 files changed

+185
-1
lines changed

4 files changed

+185
-1
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
GoAopBundle
2+
==============
3+
4+
[![Build Status](https://secure.travis-ci.org/goaop/goaop-symfony-bundle.png?branch=master)](https://travis-ci.org/goaop/goaop-symfony-bundle)
5+
[![GitHub release](https://img.shields.io/github/release/goaop/goaop-symfony-bundle.svg)](https://github.com/goaop/goaop-symfony-bundle/releases/latest)
6+
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.5-8892BF.svg)](https://php.net/)
7+
[![License](https://img.shields.io/packagist/l/goaop/goaop-symfony-bundle.svg)](https://packagist.org/packages/goaop/goaop-symfony-bundle)
8+
9+
The GoAopBundle adds support for Aspect-Oriented Programming via Go! AOP Framework for Symfony2 applications.
10+
11+
Installation
12+
------------
13+
14+
GoAopBundle can be easily installed with composer. Just ask a composer to download the bundle with dependencies by running the command:
15+
16+
```bash
17+
$ composer require goaop/goaop-symfony-bundle
18+
```
19+
20+
Versions 1.x are for Symfony >=2.0,<2.7
21+
Versions 2.x(master) are for Symfony >= 2.7 and 3.0
22+
23+
Documentation
24+
-------------
25+
26+
Documentation is available in the `Resources/doc` directory for the concrete version of bundle.
27+
28+
License
29+
-------
30+
31+
This bundle is under the MIT license. See the complete license in the bundle:
32+
33+
Resources/meta/LICENSE

Resources/doc/index.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
Overview
2+
--------
3+
4+
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.
5+
6+
AOP defines new instruments for developers, they are:
7+
8+
* Joinpoint - place in your code that can be used for interception, for example, execution of single public method or accessing of single object property.
9+
* 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.
10+
* 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.
11+
* 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.
12+
13+
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.
14+
15+
Installation
16+
------------
17+
Download the source code via composer
18+
19+
```bash
20+
$ composer require goaop/goaop-symfony-bundle
21+
```
22+
23+
Then enable the bundle in the kernel:
24+
```php
25+
// app/AppKernel.php
26+
27+
public function registerBundles()
28+
{
29+
$bundles = array(
30+
new Go\Symfony\GoAopBundle\GoAopBundle(),
31+
// ...
32+
);
33+
}
34+
```
35+
Make sure that bundle is the first item in this list. This is required for the AOP engine to work correctly.
36+
37+
Configuration
38+
-------------
39+
Configuration for bundle is required for additional tuning of AOP kernel and source code whitelistsing/blacklisting.
40+
41+
```yaml
42+
# app/config/config.yml
43+
go_aop:
44+
# This setting enables or disables an automatic AOP cache warming in the application.
45+
# By default, cache_warmer is enabled (true), disable it only if you have serious issues with
46+
# cache warming process.
47+
cache_warmer: true
48+
49+
# Additional settings for the Go! AOP kernel initialization
50+
options:
51+
# Debug mode for the AOP, enable it for debugging and switch off for production mode to have a
52+
# better runtime performance for your application
53+
debug: %kernel.debug%
54+
55+
# Application root directory, AOP will be applied ONLY to the files in this directory, by default it's
56+
# src/ directory of your application.
57+
app_dir: "%kernel.root_dir%/../src"
58+
59+
# AOP cache directory where all transformed files will be stored.
60+
cache_dir: %kernel.cache_dir%/aspect
61+
62+
# Whitelist is array of directories where AOP should be enabled, leave it empty to process all files
63+
include_paths: []
64+
65+
# Exclude list is array of directories where AOP should NOT be enabled, leave it empty to process all files
66+
exclude_paths: []
67+
68+
# AOP container class name can be used for extending AOP engine or services adjustment
69+
container_class: ~
70+
71+
# List of enabled features for AOP kernel, this allows to enable function interception, support for
72+
# read-only file systems, etc. Each item should be a name of constant from the `Go\Aop\Features` class.
73+
features: []
74+
75+
```
76+
77+
Defining new aspects
78+
----------------
79+
Aspects are services in the Symfony2 apllications and loaded into the AOP container with the help of compiler pass that collects all services tagged with `goaop.aspect` tag. Here is an example how to implement a logging aspect that will log information about public method invocations in the src/ directory.
80+
81+
82+
Definition of aspect class with pointuct and logging advice
83+
```php
84+
<?php
85+
86+
namespace App\Aspect;
87+
88+
use Go\Aop\Aspect;
89+
use Go\Aop\Intercept\MethodInvocation;
90+
use Go\Lang\Annotation\Before;
91+
use Psr\Log\LoggerInterface;
92+
93+
/**
94+
* Application logging aspect
95+
*/
96+
class LoggingAspect implements Aspect
97+
{
98+
/**
99+
* @var LoggerInterface
100+
*/
101+
private $logger;
102+
103+
public function __construct(LoggerInterface $logger)
104+
{
105+
$this->logger = $logger;
106+
}
107+
108+
/**
109+
* Writes a log info before method execution
110+
*
111+
* @param MethodInvocation $invocation
112+
* @Before("execution(public **->*(*))")
113+
*/
114+
public function beforeMethod(MethodInvocation $invocation)
115+
{
116+
$this->logger->info($invocation, $invocation->getArguments());
117+
}
118+
}
119+
```
120+
121+
Registration of aspect in the container:
122+
123+
```yaml
124+
services:
125+
logging.aspect:
126+
class: App\Aspect\LoggingAspect
127+
arguments: ["@logger"]
128+
tags:
129+
- { name: goaop.aspect }
130+
```
131+
132+
Thats it!

Resources/meta/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 Lisachenko Alexander <lisachenko.it@gmail.com>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Integration bridge for Go! AOP framework",
44
"type": "symfony-bundle",
55
"require": {
6-
"goaop/framework": "^1.0@dev|^2.0@dev"
6+
"goaop/framework": "^1.0|^2.0@dev"
77
},
88
"license": "MIT",
99
"authors": [

0 commit comments

Comments
 (0)