The State of Aspect-Oriented Programming for PHP

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    5 Favorites & 1 Group

    The State of Aspect-Oriented Programming for PHP - Presentation Transcript

    1. AOP @ PHP The State of Aspect-Oriented Programming for PHP Sebastian Bergmann September, 14 th 2006
    2. Warning
      • It is (at least in my opinion) impossible to discuss „AOP for PHP“ without introducing AOP first.
      • So, I will try to give a short introduction into AOP before I get into „AOP for PHP“.
        • I hope I found a balance between theory and practical examples to not make this boring.
      • There will be no Java / AspectJ examples in this presentation ;-)
    3. Who I Am
      • Sebastian Bergmann.
      • Born 1978.
      • System Developer at eZ systems AS.
      • Committer: PHP, PEAR, Gentoo Linux, ...
      • Creator of Open Source PHP projects such as PHPUnit.
      • Author on PHP and related topics.
    4. Who Are You?
      • What is your background?
        • OOP?
        • PHP 5?
        • AOP?
    5. Overview
      • Goals of OOP
        • Make code look like the design.
        • Improve the modularity of code and design.
    6. Overview
      • Goals of AOP
        • Make code look like the design.
        • Improve the modularity of code and design.
        • Deal with cross-cutting concerns.
      • AOP for PHP
        • How can AOP for PHP be implemented?
        • What implementations of AOP for PHP exist?
        • My own implementation of AOP for PHP, GAP: Generic Aspects for PHP.
    7. Something To Think About
    8. Programming Languages
      • Programming languages are about writing a structure of statements that a compilation or interpretation process will elaborate as a series of primitive directions.
      This slide uses material by Robert E. Filman .
      • With the first programming languages, each statement was both unitary and local .
        • Unitary in that it ended up having effect in precisely one place in the program.
        • Local in that it was almost always proximate to its neighboring statements.
    9. Programming Languages
      • The history (of this part) of programming languages has been about moving away from purely local and unitary languages.
        • Provide mechanisms that let the programmer separate concepts pragmatically, instead of being tied to saying things just where they happen.
      This slide uses material by Robert E. Filman .
    10. Programming Languages
      • The first exceptions to locality were subprograms.
        • They enabled the abstracting out of some behavior to someplace else.
        • Still unitary: direct correspondence between one statement written and one sequence of machine instructions executed.
      This slide uses material by Robert E. Filman .
    11. Object-Oriented Programming
      • 1961
        • Ole-Johan Dahl and Kristen Nygaard presented Simula , a syntactical superset of Algol 60 that added features such as objects, classes, subclasses, virtual methods, coroutines, garbage collection, and discrete event simulation.
        • First object-oriented programming language and predecessor of all class-based object-oriented languages.
        • Goal: Make the code look like the model.
      • 1967
        • The term object-oriented programming is coined.
    12. Object-Oriented Programming
      • A way of thinking
        • Objects and Classification Hierarchies
      • that allows us to
        • make code look like the design
        • and improve the modularity of code and design
      • and is supported by language features.
        • classes, encapsulation, polymorphism
      This slide is based on material by Gregor Kiczales.
    13. Good Design This slide uses material by Roger Whitney .
      • Modules should
        • exhibit a high degree of cohesion .
          • The elements in the module exhibit a high degree of functional relatedness. This means that each element in the program unit should be essential for that unit to achieve its purpose. (Sommerville, 1989)
        • be loosely coupled .
          • The interaction or other interrelationship between any two modules at the same level of abstraction within the system should be as weak as possible.
      • Goal
        • Separation of Concerns
          • Locality of Change -> Maintainability
          • Loose Coupling -> Reusability
    14. Cross-Cutting Concerns
      • Object-Oriented Programming suffers from a limitation called the tyranny of the dominant decomposition .
        • The program can be modularized in only one way at a time, and the many kinds of concerns that do not align with that modularization end up scattered across many modules and tangled with one another.
      • To „break this tyranny“ all kinds of concerns of importance need to be separated simultaneously, including crosscutting concerns.
    15. Cross-Cutting Concerns Code that deals with XML parsing in Apache Tomcat Object-Oriented Decomposition works for this concern. As a result, the code for XML parsing is not scattered .
    16. Cross-Cutting Concerns Code that deals with logging in Apache Tomcat Object-Oriented Decomposition does not work for this concern. As a result, the code for logging is scattered and tangled .
    17. Aspect-Oriented Programming
      • Late 1970s, early 1980s
        • Cross-Cutting Structure
        • Mechanisms
          • Behavioral Reflection
          • Meta-Object Protocols
          • Subject-Oriented Programming
      • 1997
        • The term aspect-oriented programming is coined.
      This slide is based on material by Gregor Kiczales.
    18. Aspect-Oriented Programming This slide uses material by Günter Kniesel .
      • New Modularization Concept.
        • Quantification
          • Ability to declare actions to be applied consistently to many places in a program.
        • Obliviousness
          • The modified program entities do not need to be aware of being subject to aspect activity and do not need to provide special hooks for enabling such activity.
      • Functionality that would otherwise be scattered throughout a program can be encapsulated in one aspect.
    19. Aspect-Oriented Programming
      • A way of thinking
        • Aspects and Cross-Cutting Structure
      • that allows us to
        • make code look like the design
        • and improve the modularity of code and design
      • and is supported by language features.
        • Aspects, Join Points, Pointcuts, Advice, Inter-Type Declarations
      This slide is based on material by Gregor Kiczales.
    20. Aspect-Oriented Programming New Object Join Point Method Call Join Point
    21. Aspect-Oriented Programming
      • Join Point
        • A well-defined point in the execution of a program, for instance a method call or attribute access.
      • Pointcut
        • A predicate that matches join points.
    22. Aspect-Oriented Programming
      • Advice
        • A piece of code that is executed at a join point matched by a pointcut.
      • Inter-Type Declaration
        • An introduction of new code into an existing class.
      • Aspect
        • A module that can consist of pointcuts, advice, and inter-type declarations.
    23. Implementing AOP for PHP
      • Why?
        • Good question.
        • While attending a course on AOP at the University I started wondering how to implement AOP for with PHP.
      • Where could it be useful?
        • Enforce rules during development time.
          • This is also the most popular use of AspectJ at the moment.
        • Help with the development of tools such as PHPUnit.
          • Mock Objects, for instance, are easy to implement if you have class posing. An aspect can implement that.
    24. Implementing AOP for PHP
      • Implement AOP not on the language level.
        • Component / Container based frameworks
          • Seasar2
        • Graph-Oriented Programming (GOP)
          • Pointcuts on node transitions
          • Workflow component of the eZ components
    25. Implementing AOP for PHP
      • Preprocessor
        • A preprocessor can be used to perform source code transformations and statically weave the aspect code into the base program.
        • The result of this weaving is PHP source code that can then be deployed in a standard PHP environment.
      This slide uses material by William Candillon . PHPAspect
    26. PHPAspect
    27. PHPAspect
    28. Implementing AOP for PHP
      • Aspect-Aware PHP Interpreter
        • Zend Extension
          • Modify the executor to intercept events such as method calls and attribute accesses, for instance, and delegate them to an aspect-aware dispatcher.
          • This dispatcher can be either implemented as part of the extension or in userland.
        • Patch for the Zend Engine
          • Allows changes to scanner and parser rules.
          • But hard to maintain.
    29. Implementing AOP for PHP
      • Meta-Programming
        • Reflection API
        • Runkit
        • __get() , __set() , __call()
    30. GAP: Generic Aspects for PHP
      • G eneric A spects for P HP.
        • Generic Join Point model for PHP.
          • Framework to implement custom pointcut system.
        • Aspect Generic ity.
      • Advice = Plain PHP method.
        • Inside this method, the same information is available that is used by GAP for advice dispatching.
      • Sample pointcut system uses annotations in code comments to connect join points to aspect effects.
    31. GAP: Generic Aspects for PHP
      • Join Points
        • Object Initialization
        • Field Access
        • Method Call / Method Execution
      • Aspect Effects
        • Advice
        • Intertype-Declarations
        • Custom Errors
    32. GAP: Generic Aspects for PHP
      • Sample Pointcut System
        • initialization( class ( parameters ))
        • get( modifier class -> attribute )
        • set( modifier class -> attribute )
        • method( modifier class -> method ( parameters ))
        • source( modifier class -> method ( parameters ))
        • cflow( modifier class -> method ( parameters ))
    33. A GAP Aspect
    34. PHP Base Code
    35. Custom Errors
    36. Implementation of GAP Class Sources Aspect Sources Interception of loaded PHP source Source-Level Transformation Normal Compilation
    37. Implementation of GAP Bytecode-Level Transformation
    38. License
      • These slides are available under the Creative Commons Attribution 2.0 Germany license.
      • You are free:
        • to copy, distribute, display, and perform the work
        • to make derivative works
        • to make commercial use of the work
      • Under the following conditions:
        • Attribution: You must attribute the work in the manner specified by the author or licensor.
        • For any reuse or distribution, you must make clear to others the license terms of this work.
        • Any of these conditions can be waived if you get permission from the copyright holder.
      • Your fair use and other rights are in no way affected by the above.
      „ The State of AOP for PHP“ Sebastian Bergmann http://www.sebastian-bergmann.de/talks/

    + Sebastian BergmannSebastian Bergmann, 4 years ago

    custom

    2500 views, 5 favs, 2 embeds more stats

    Presentation at the php/db|works 2006 conference in more

    More info about this document

    CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

    Go to text version

    • Total Views 2500
      • 2485 on SlideShare
      • 15 from embeds
    • Comments 0
    • Favorites 5
    • Downloads 0
    Most viewed embeds
    • 14 views on http://phpunit.suprglu.com
    • 1 views on http://sebastian-bergmann.de

    more

    All embeds
    • 14 views on http://phpunit.suprglu.com
    • 1 views on http://sebastian-bergmann.de

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags

    Groups / Events