You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+98-1Lines changed: 98 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,4 +25,101 @@ public function registerBundles()
25
25
}
26
26
```
27
27
28
-
## Configuration
28
+
## Usage
29
+
30
+
To use the PostProcessBundle, you must first create a class adhering to the `Task\TaskInterface` or `Plugins\PluginInterface`. A task is a process that will be executed on the Symfony terminate event (after the response is sent,) whereas a Plugin is a process that is run before the response is sent (allowing you to modify it.)
31
+
32
+
### Tasks
33
+
34
+
A task can be used to execute logic after the response has been sent to the user, allowing you to trigger long-running processes that need to complete, but the user does not need to wait for them.
35
+
36
+
Example:
37
+
38
+
```
39
+
use As3\PostProcessBundle\TaskInterface;
40
+
41
+
class SleepTestTask implements TaskInterface
42
+
{
43
+
/**
44
+
* {@inhericDoc}
45
+
*/
46
+
public function run()
47
+
{
48
+
// Some process that takes 5 minutes
49
+
sleep(300);
50
+
}
51
+
}
52
+
```
53
+
54
+
To register your task, call the `addTask` method against the task manager's service (`as3_post_process.task.manager`):
Tasks can have a `priority` set when they are added to the manager -- by default new tasks are added with a priority of `0`. Tasks are executed in ascending order by their priority.
61
+
62
+
You can also register a service by using the tag `as3_post_process.task` if your task should be run on every request.
63
+
64
+
```
65
+
# src\MyBundle\Resources\services.yml
66
+
services:
67
+
my_app.my_cool_task:
68
+
class: MyCoolTask
69
+
tags:
70
+
- { name: as3_post_process.task, priority: 5 }
71
+
```
72
+
73
+
### Plugins
74
+
75
+
A plugin can be used to modify the response before it is returned to the user.
76
+
77
+
Example:
78
+
79
+
```
80
+
use Symfony\Component\HttpFoundation\Response;
81
+
82
+
/**
83
+
* Integration with New Relic End User Monitoring services
84
+
*/
85
+
class NewRelicInjector extends PluginInterface
86
+
{
87
+
/**
88
+
* Handles injection of NREUM Javascript
89
+
*/
90
+
public function filterResponse(Response $response)
// If we modified the content, set it on the response.
108
+
if ($content !== $response->getContent()) {
109
+
$response->setContent($content);
110
+
}
111
+
112
+
return $response;
113
+
}
114
+
}
115
+
}
116
+
```
117
+
118
+
This plugin will disable automatic injection of NewRelic end user monitoring javascript. To enable this for all requests, add the following service definition:
0 commit comments