Go! Aspect-Oriented Framework

Aspect-Oriented Programming in PHP.

Fork me on GitHub

Caching Like a PRO

| Comments

As web applications become more large-scaled, the questions of performance optimization are more frequently considered in initial design. One of the optimization techniques used extensively is caching. Cache contains pre-processed data which is ready to be used without redoing the processing. This article shows the possible ways of doing caching in PHP, including aspect-oriented approach.

Caching is probably the most known technique in computer science, it appears everywhere: CPU, disk cache buffers, opcode cache, memcache, SQL cache, etc. Since it is contained everywhere, we can’t extract it into a single place to keep it under our control. So cache invalidation is one of the hardest things. There is a good quote:

There are only two hard things in Computer Science: cache invalidation and naming things.

Phil Karlton

Let’s have a look at caching in the PHP.

What Is New in Version 0.5.0

| Comments

New versions of frameworks are always exciting because they provide more features and can contain important fixes and changes. Go! AOP evolves too, so I prepared this article for users to underline most important changes.

Aspect-Oriented Programming With Yii

| Comments

Aspect-Oriented programming becomes more popular for PHP, but it requires good knowledge of OOP and can be very cumbersome for beginners. So it’s important to have a working examples and manuals to have a possibility to run it locally with favorite framework. Go! AOP provides all the necessary functionality for configuration of AOP into any frameworks, but integration process can be very tricky, so configuration is not so easy. In this article we will configure a working example for Yii framework.

Intercepting Execution of System Functions in PHP

| Comments

Intercepting an execution of methods is one of the most common tasks for AOP. In the Java world there are a lot of articles that has a detailed examples for transactional control, logging, authorization, etc. But all AOP stuff in Java is related only to the classes and objects, because functions are not first-class citizens in Java whereas PHP has a good support for functions. By using some tricks we can create a proxies for system functions and add our own interceptors with custom logic. This article will show you how to use AOP techniques with functions in PHP.

Implementing Logging Aspect With Doctrine Annotations

| Comments

Logging is probably the most mentioned sweet example of AOP. Probably because it is the simplest and most straightforward example most people can think of. So I want to show you the easiest ever way to implement logging in PHP with annotations. This article is the second part of my previous article about application-level logging with AOP in PHP and if you haven’t read it yet please do this before proceeding to this article.

Application-level Logging With AOP and Monolog

| Comments

So you got finished with your brand new website. It is completely PHP driven and looks very nice. But are you sure that everything works perfectly? Under every circumstances?

No. You can never be absolutely sure. That is why you need a log file to see if there where some errors. Well, if you are the kind of person that doesn’t care if some jerks who behaved wrong on you website get error messages, then you probably don’t need an error log file.

Implementing Reusable Fluent Interface Pattern in PHP With AOP

| Comments

During software development one of the most important goals is the readability of source code. There are special techniques and tips that help us to improve the readability of source code. One of the techniques of improving the source code readability is using of fluent interfaces. Let’s discuss it in this article.

Aspect-Oriented Framework for PHP

| Comments

Go! is a PHP 5.4 framework based on OOP and AOP paradigms and designed by Lisachenko Alexander. It allows developers to add support of AOP to every PHP application.

Go! doesn’t require any PECL-extentions, it neither uses any dark magic of Runkit nor evals, the library doesn’t use DI-containers. The code with weaved aspects is fully readable and native, it can be easily debugged with XDebug. You can debug either classes or aspects. The main advantage of Go! is that potentially it can be installed in every PHP-application, because you don’t have to change the application source code at all. As an example, with the help of 10-20 lines of code we can intercept all the public, protected and static methods in all the classes of application and display the name and the arguments of each method during its execution.

What is AOP?

AOP (Aspect-Oriented Programming) is an approach to cross-cutting concerns, where the concerns are designed and implemented in a “modular” way (that is, with appropriate encapsulation, lack of duplication, etc.), then integrated into all the relevant execution points in a succinct and robust way, e.g. through declarative or programmatic means.

In AOP terms, the execution points are called join points, a particular set of them is called a pointcut and the new behavior that is executed before, after, or “around” a join point is called advice. You can read more about AOP in Introduction section.

PHP traits can be used to implement some aspect-like functionality.