Skip to content

Commit 1e7a93e

Browse files
committed
Merge remote-tracking branch 'origin/1.x'
* origin/1.x: Move all docs to the main README.md file
2 parents 39b401d + 7232be2 commit 1e7a93e

File tree

2 files changed

+122
-134
lines changed

2 files changed

+122
-134
lines changed

README.md

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ GoAopBundle
88

99
The GoAopBundle adds support for Aspect-Oriented Programming via Go! AOP Framework for Symfony2 applications.
1010

11+
Overview
12+
--------
13+
14+
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.
15+
16+
AOP defines new instruments for developers, they are:
17+
18+
* Joinpoint - place in your code that can be used for interception, for example, execution of single public method or accessing of single object property.
19+
* 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.
20+
* 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.
21+
* 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.
22+
23+
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.
24+
1125
Installation
1226
------------
1327

@@ -20,10 +34,116 @@ $ composer require goaop/goaop-symfony-bundle
2034
Versions 1.x are for Symfony >=2.0,<2.7
2135
Versions 2.x(master) are for Symfony >= 2.7 and 3.0
2236

23-
Documentation
37+
Then enable the bundle in the kernel:
38+
```php
39+
// app/AppKernel.php
40+
41+
public function registerBundles()
42+
{
43+
$bundles = array(
44+
new Go\Symfony\GoAopBundle\GoAopBundle(),
45+
// ...
46+
);
47+
}
48+
```
49+
Make sure that bundle is the first item in this list. This is required for the AOP engine to work correctly.
50+
51+
Configuration
2452
-------------
2553

26-
Documentation is available in the `Resources/doc` directory for the concrete version of bundle.
54+
Configuration for bundle is required for additional tuning of AOP kernel and source code whitelistsing/blacklisting.
55+
56+
```yaml
57+
# app/config/config.yml
58+
go_aop:
59+
# This setting enables or disables an automatic AOP cache warming in the application.
60+
# By default, cache_warmer is enabled (true), disable it only if you have serious issues with
61+
# cache warming process.
62+
cache_warmer: true
63+
64+
# Additional settings for the Go! AOP kernel initialization
65+
options:
66+
# Debug mode for the AOP, enable it for debugging and switch off for production mode to have a
67+
# better runtime performance for your application
68+
debug: %kernel.debug%
69+
70+
# Application root directory, AOP will be applied ONLY to the files in this directory, by default it's
71+
# src/ directory of your application.
72+
app_dir: "%kernel.root_dir%/../src"
73+
74+
# AOP cache directory where all transformed files will be stored.
75+
cache_dir: %kernel.cache_dir%/aspect
76+
77+
# Whitelist is array of directories where AOP should be enabled, leave it empty to process all files
78+
include_paths: []
79+
80+
# Exclude list is array of directories where AOP should NOT be enabled, leave it empty to process all files
81+
exclude_paths: []
82+
83+
# AOP container class name can be used for extending AOP engine or services adjustment
84+
container_class: ~
85+
86+
# List of enabled features for AOP kernel, this allows to enable function interception, support for
87+
# read-only file systems, etc. Each item should be a name of constant from the `Go\Aop\Features` class.
88+
features: []
89+
90+
```
91+
92+
Defining new aspects
93+
--------------------
94+
95+
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.
96+
97+
98+
Definition of aspect class with pointuct and logging advice
99+
```php
100+
<?php
101+
102+
namespace App\Aspect;
103+
104+
use Go\Aop\Aspect;
105+
use Go\Aop\Intercept\MethodInvocation;
106+
use Go\Lang\Annotation\Before;
107+
use Psr\Log\LoggerInterface;
108+
109+
/**
110+
* Application logging aspect
111+
*/
112+
class LoggingAspect implements Aspect
113+
{
114+
/**
115+
* @var LoggerInterface
116+
*/
117+
private $logger;
118+
119+
public function __construct(LoggerInterface $logger)
120+
{
121+
$this->logger = $logger;
122+
}
123+
124+
/**
125+
* Writes a log info before method execution
126+
*
127+
* @param MethodInvocation $invocation
128+
* @Before("execution(public **->*(*))")
129+
*/
130+
public function beforeMethod(MethodInvocation $invocation)
131+
{
132+
$this->logger->info($invocation, $invocation->getArguments());
133+
}
134+
}
135+
```
136+
137+
Registration of aspect in the container:
138+
139+
```yaml
140+
services:
141+
logging.aspect:
142+
class: App\Aspect\LoggingAspect
143+
arguments: ["@logger"]
144+
tags:
145+
- { name: goaop.aspect }
146+
```
27147
28148
License
29149
-------

Resources/doc/index.md

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)