PHP Aspect Oriented Design

Posted by Devin Dixon on Programmers See other posts from Programmers or by Devin Dixon
Published on 2012-02-13T18:02:48Z Indexed on 2012/03/30 11:41 UTC
Read the original article Hit count: 260

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

//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:

© Programmers or respective owner

Related posts about php

Related posts about design-patterns