PHP Aspect Oriented Design
- by Devin Dixon
This is a continuation of this Code Review question.
What was taken away from that post, and other aspect oriented design is it is hard to debug. To counter that, I implemented the ability to turn tracing of the design patterns on. Turning trace on works like:
//This can be added anywhere in the code
Run::setAdapterTrace(true);
Run::setFilterTrace(true);
Run::setObserverTrace(true);
//Execute the functon
echo Run::goForARun(8);
In the actual log with the trace turned on, it outputs like so:
adapter 2012-02-12 21:46:19 {"type":"closure","object":"static","call_class":"\/public_html\/examples\/design\/ClosureDesigns.php","class":"Run","method":"goForARun","call_method":"goForARun","trace":"Run::goForARun","start_line":68,"end_line":70}
filter 2012-02-12 22:05:15 {"type":"closure","event":"return","object":"static","class":"run_filter","method":"\/home\/prodigyview\/public_html\/examples\/design\/ClosureDesigns.php","trace":"Run::goForARun","start_line":51,"end_line":58}
observer 2012-02-12 22:05:15 {"type":"closure","object":"static","class":"run_observer","method":"\/home\/prodigyview\/public_html\/public\/examples\/design\/ClosureDesigns.php","trace":"Run::goForARun","start_line":61,"end_line":63}
When the information is broken down, the data translates to:
Called by an adapter or filter or observer
The function called was a closure
The location of the closure
Class:method the adapter was implemented on
The Trace of where the method was called from
Start Line and End Line
The code has been proven to work in production environments and features various examples of to implement, so the proof of concept is there. It is not DI and accomplishes things that DI cannot. I wouldn't call the code boilerplate but I would call it bloated. In summary, the weaknesses are bloated code and a learning curve in exchange for aspect oriented functionality.
Beyond the normal fear of something new and different, what are other weakness in this implementation of aspect oriented design, if any?
PS: More examples of AOP here: https://github.com/ProdigyView/ProdigyView/tree/master/examples/design