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
AopBundle is a Symfony bundle that implements Aspect-Oriented Programming (AOP) using PHP 8's Attribute features. It enables adding cross-cutting concerns (like logging, caching, transactions) to your code without modifying the core logic.
28
+
AopBundle is a Symfony bundle that implements Aspect-Oriented Programming (AOP) using PHP 8's
Use the built-in Stopwatch attribute for performance monitoring:
103
238
104
239
```php
105
240
use Tourze\Symfony\Aop\Attribute\Stopwatch;
@@ -116,32 +251,41 @@ class UserService
116
251
117
252
## Best Practices
118
253
119
-
1.**Keep aspects focused**
120
-
- Each aspect should have a single responsibility
121
-
- Avoid heavy operations in advice methods
254
+
### Keep Aspects Focused
255
+
256
+
- Each aspect should have a single responsibility
257
+
- Avoid heavy operations in advice methods
258
+
- Use meaningful names for aspects and advice methods
259
+
260
+
### Advice Execution Order
261
+
262
+
- Before advice is executed in declaration order
263
+
- After/AfterReturning/AfterThrowing advice is executed in reverse order
264
+
- Consider the execution order when defining multiple aspects
265
+
266
+
### Performance Considerations
122
267
123
-
2.**Advice execution order**
124
-
- Before advice is executed in declaration order
125
-
- After/AfterReturning/AfterThrowing advice is executed in reverse order
268
+
- Use AOP only when necessary
269
+
- Consider the performance impact in production
270
+
- Use Stopwatch to monitor method execution time
271
+
- Avoid complex pointcut expressions in hot paths
126
272
127
-
3.**Performance considerations**
128
-
- Use AOP only when necessary
129
-
- Consider the performance impact in production
130
-
- Use Stopwatch to monitor method execution time
273
+
### Exception Handling
131
274
132
-
4.**Exception handling**
133
-
- Be careful with exception handling in advice
134
-
- Consider using AfterThrowing for exception logging
135
-
- Use CatchException for controlled exception handling
275
+
- Be careful with exception handling in advice
276
+
- Consider using AfterThrowing for exception logging
277
+
- Use CatchException for controlled exception handling
278
+
- Test exception scenarios thoroughly
136
279
137
280
## Configuration
138
281
139
-
No additional configuration is required. The bundle automatically detects services with the `#[Aspect]` attribute and applies advice to matching services.
282
+
No additional configuration is required. The bundle automatically detects services with the
283
+
`#[Aspect]`attribute and applies advice to matching services.
140
284
141
285
## Contributing
142
286
143
287
Contributions are welcome. Please feel free to submit a Pull Request.
144
288
145
289
## License
146
290
147
-
This bundle is available under the MIT license. See the [LICENSE](LICENSE) file for more information.
291
+
This bundle is available under the MIT license. See the [LICENSE](LICENSE) file for more information.
0 commit comments