SlideShare a Scribd company logo
1 of 33
Download to read offline
Robert Lemke
          Create Clean Code with Aspect-Oriented Programming
           International PHP Conference, Mainz 2010



                             /**             Asp ect
                              *S  ecu   rity
                               *@   asp  ect
                                 */             ityA spe ct {
                                 cla s s Se cur        olic ies;
                                           tec ted $p
Mittwoch, 13. Oktober 2010
                                       pro
Robert Lemke
                chief architect of TYPO3 Phoenix and FLOW3

                co-founder of the TYPO3 Association

                34 years old

                lives in Lübeck, Germany

                1 wife, 1 daughter, 1 espresso machine

                likes drumming




Mittwoch, 13. Oktober 2010
= PHP 5.3 Full Stack Application Framework




Mittwoch, 13. Oktober 2010
DI        Dependency Injection              DRY
                                                                     YAA
                                           OOP   Object-Oriented Programming
      YAGNI
                             AOP Aspect-Oriented Programming
             CoC
                                           MVC   Model View Controller


                    POPO Plain Old PHP Object                      TDD

Mittwoch, 13. Oktober 2010
/**
         * Creates a new post
         *
         * @param F3BlogDomainModelPost $newPost A fresh Post object which has not yet been
         *                                                               added to the repository
         * @return void
         */
       public function createAction(F3BlogDomainModelPost $newPost) {
            if ($this->policyService->isGranted($this->currentUser, __CLASS__, __METHOD__) {
                $this->blog->addPost($newPost);
                $this->flashMessageContainer->add('Your new post was created.');
                $this->systemLogger->log('A new post was created.', LOG_INFO);
                $this->notificationService->notify('A new post was created.', 'robert@typo3.org');
            } else {
                $this->systemLogger->log('Someone tried to create a post.', LOG_WARNING);
                throw new F3FLOW3SecurityExceptionAccessDeniedException('Tried to create.');
            }
            $this->redirect('index');
       }


                Create Clean Code with AOP                      International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
/**
         * Creates a new post
         *
         * @param F3BlogDomainModelPost $newPost A fresh Post object which has not yet been
         *                                                               added to the repository
         * @return void
         */
       public function createAction(F3BlogDomainModelPost $newPost) {
            if ($this->policyService->isGranted($this->currentUser, __CLASS__, __METHOD__) {
                $this->blog->addPost($newPost);
                $this->flashMessageContainer->add('Your new post was created.');
                $this->systemLogger->log('A new post was created.', LOG_INFO);
                $this->notificationService->notify('A new post was created.', 'robert@typo3.org');
            } else {
                $this->systemLogger->log('Someone tried to create a post.', LOG_WARNING);
                throw new F3FLOW3SecurityExceptionAccessDeniedException('Tried to create.');
            }
            $this->redirect('index');
       }


                Create Clean Code with AOP                      International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
AOP
                Create Clean Code with AOP   International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Aspect-Oriented Programming
                             programming paradigm

                             separates concerns to improve modularization


                             OOP modularizes concerns into objects

                             AOP modularizes cross-cutting concerns into aspects




                Create Clean Code with AOP                           International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
/**
         * Creates a new post
         *
         * @param F3BlogDomainModelPost $newPost A fresh Post object which has not yet been
         *                                            added to the repository
         * @return void
         */
       public function createAction(F3BlogDomainModelPost $newPost) {
            $this->blog->addPost($newPost);
            $this->flashMessageContainer->add('Your new post was created.');
            $this->redirect('index');
       }




                Create Clean Code with AOP                   International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Concerns?
                Create Clean Code with AOP   International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Concerns
                             Separation of Concerns

                               group features and behavior into manageable parts

                               have a specific purpose and business to take care of

                             Cross-Cutting Concerns

                               are the party poopers who want to have a say in everything




                Create Clean Code with AOP                                International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Cross-Cutting Concerns
                             Logging

                             Security

                             Persistence

                             Global Business Logic

                             Dirty Hacks




                Create Clean Code with AOP           International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
We don't want infrastructure code
                 in our models.




                Create Clean Code with AOP   International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
We want to unit-test even
                 cross-cutting concerns




                Create Clean Code with AOP   International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
We want to centralize
                 security-related code




                Create Clean Code with AOP   International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
AOP Lingo


                Create Clean Code with AOP   International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Aspect
                             Part of the application where cross-cutting concerns are implemented

                             In FLOW3 aspects are classes annotated with @aspect




                Create Clean Code with AOP                                International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Join Point
                             Is a single point in the call graph

                               Method Execution

                               Exception

                             Represents an event, not a location




                Create Clean Code with AOP                         International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Pointcut
                             A set of join points where advices could be executed

                               can be composed

                               can be named




                Create Clean Code with AOP                                 International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Advice
                             Action to take at a join points defined by the point cut




                Create Clean Code with AOP                                  International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
DEMO
                                              Inspiring people to
                Hitchhiker's Guide to FLOW3   share
Mittwoch, 13. Oktober 2010
Kinds of Advice
                 Advice types supported by FLOW3:

                 @before
                 @afterreturning
                 @afterthrowing
                 @after
                 @around




                                                    Inspiring people to
                Hitchhiker's Guide to FLOW3         share
Mittwoch, 13. Oktober 2010
Pointcut Designators
                 method(F3MyPackageMyClass->myMethod())
                 class(F3MyPackageMyClass)
                 within(F3MyPackageMyInterface)
                 classTaggedWith(someTag)
                 methodTaggedWith(anotherTag)
                 setting(Demo.Stuff.SomeSetting = "yeah, do it")
                 filter(F3MyPackageMyCustomFilterImplementation)
                   fi




                                                           Inspiring people to
                Hitchhiker's Guide to FLOW3                share
Mittwoch, 13. Oktober 2010
Runtime Evaluations
                 evaluate(coffee.kind == "Arabica")




                                                      Inspiring people to
                Hitchhiker's Guide to FLOW3           share
Mittwoch, 13. Oktober 2010
Compound Pointcuts
!    /**
!     * @around method(.*Controller->(new|create|edit|update|delete)Action()) && 
            !methodTaggedWith(anybodyMayAccessThis)
!     */
!    public function interceptMethodCalls($joinPoint) {
        ...
     }




                                                            Inspiring people to
                Hitchhiker's Guide to FLOW3                 share
Mittwoch, 13. Oktober 2010
DEMO
                                              Inspiring people to
                Hitchhiker's Guide to FLOW3   share
Mittwoch, 13. Oktober 2010
FLOW3's AOP implementation
                             based on proxy classes

                               unlike with most pre-processors line numbers stay the same

                             no scaffolding

                               0 Lines of generated code which need to be maintained by you

                             fast (on the second hit)




                                                                                        Inspiring people to
                Hitchhiker's Guide to FLOW3                                             share
Mittwoch, 13. Oktober 2010
Inspiring people to
                Hitchhiker's Guide to FLOW3   share
Mittwoch, 13. Oktober 2010
Inspiring people to
                Hitchhiker's Guide to FLOW3   share
Mittwoch, 13. Oktober 2010
Progress

                                   FLOW3 1.0.0




                Create Clean Code with AOP       International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Further Reading
                             FLOW3 Website
                             http://flow3.typo3.org

                             FLOW3 Download
                             http://flow3.typo3.org/download
                             git://git.typo3.org/FLOW3/Distributions/Base.git

                             TYPO3 Forge
                             http://forge.typo3.org

                             Further Reading
                             http://flow3.typo3.org/about/principles/further-reading



                Create Clean Code with AOP                                  International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Questions

                 Email:            robert@typo3.org
                 Blog:             http://robertlemke.de/blog
                 Twitter:          @t3rob

                 Slides:           http://slideshare.net/rlmp




                Create Clean Code with AOP                      International PHP Conference, Mainz 2010
Mittwoch, 13. Oktober 2010
Mittwoch, 13. Oktober 2010

More Related Content

Similar to Creating Clean Code with AOP

Creating Clean Code with AOP (WebExpo 2010)
Creating Clean Code with AOP (WebExpo 2010)Creating Clean Code with AOP (WebExpo 2010)
Creating Clean Code with AOP (WebExpo 2010)Robert Lemke
 
Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)Robert Lemke
 
The Secret Recipe of a Juicy M
The Secret Recipe of a Juicy MThe Secret Recipe of a Juicy M
The Secret Recipe of a Juicy MRobert Lemke
 
Even better debugging; Equipped yourself with powerful tools.
Even better debugging; Equipped yourself with powerful tools.Even better debugging; Equipped yourself with powerful tools.
Even better debugging; Equipped yourself with powerful tools.Murshed Ahmmad Khan
 
Going open source with small teams
Going open source with small teamsGoing open source with small teams
Going open source with small teamsJamie Thomas
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-pythonYuvaraja Ravi
 
Learn How To Develop With CakePHP
Learn How To Develop With CakePHPLearn How To Develop With CakePHP
Learn How To Develop With CakePHPMichael Bourque
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCMayflower GmbH
 
PHP in a Mobile Ecosystem (Zendcon 2010)
PHP in a Mobile Ecosystem (Zendcon 2010)PHP in a Mobile Ecosystem (Zendcon 2010)
PHP in a Mobile Ecosystem (Zendcon 2010)Ivo Jansch
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with PythonBrian Lyttle
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIRobert Lemke
 
Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...
Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...
Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...Jazkarta, Inc.
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7Wim Godden
 
PHP Deployment With Capistrano
PHP Deployment With CapistranoPHP Deployment With Capistrano
PHP Deployment With Capistranojserpieters
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Create Cross-Platform Native Mobile Apps in Flex with ELIPS Studio
Create Cross-Platform Native Mobile Apps in Flex with ELIPS StudioCreate Cross-Platform Native Mobile Apps in Flex with ELIPS Studio
Create Cross-Platform Native Mobile Apps in Flex with ELIPS StudioGuilhem Ensuque
 
Microsoft ♥ Open Source
Microsoft ♥ Open SourceMicrosoft ♥ Open Source
Microsoft ♥ Open SourceRicardo Peres
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestJoshua Warren
 

Similar to Creating Clean Code with AOP (20)

Creating Clean Code with AOP (WebExpo 2010)
Creating Clean Code with AOP (WebExpo 2010)Creating Clean Code with AOP (WebExpo 2010)
Creating Clean Code with AOP (WebExpo 2010)
 
Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)
 
The Secret Recipe of a Juicy M
The Secret Recipe of a Juicy MThe Secret Recipe of a Juicy M
The Secret Recipe of a Juicy M
 
Even better debugging; Equipped yourself with powerful tools.
Even better debugging; Equipped yourself with powerful tools.Even better debugging; Equipped yourself with powerful tools.
Even better debugging; Equipped yourself with powerful tools.
 
Going open source with small teams
Going open source with small teamsGoing open source with small teams
Going open source with small teams
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-python
 
Learn How To Develop With CakePHP
Learn How To Develop With CakePHPLearn How To Develop With CakePHP
Learn How To Develop With CakePHP
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
 
PHP in a Mobile Ecosystem (Zendcon 2010)
PHP in a Mobile Ecosystem (Zendcon 2010)PHP in a Mobile Ecosystem (Zendcon 2010)
PHP in a Mobile Ecosystem (Zendcon 2010)
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DI
 
Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...
Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...
Scalable Plone hosting with Amazon EC2 for Rice University's Rhaptos open lea...
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
PHP Deployment With Capistrano
PHP Deployment With CapistranoPHP Deployment With Capistrano
PHP Deployment With Capistrano
 
Django introduction
Django introductionDjango introduction
Django introduction
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Create Cross-Platform Native Mobile Apps in Flex with ELIPS Studio
Create Cross-Platform Native Mobile Apps in Flex with ELIPS StudioCreate Cross-Platform Native Mobile Apps in Flex with ELIPS Studio
Create Cross-Platform Native Mobile Apps in Flex with ELIPS Studio
 
Microsoft ♥ Open Source
Microsoft ♥ Open SourceMicrosoft ♥ Open Source
Microsoft ♥ Open Source
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 

More from Robert Lemke

Neos Content Repository – Git for content
Neos Content Repository – Git for contentNeos Content Repository – Git for content
Neos Content Repository – Git for contentRobert Lemke
 
A General Purpose Docker Image for PHP
A General Purpose Docker Image for PHPA General Purpose Docker Image for PHP
A General Purpose Docker Image for PHPRobert Lemke
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesRobert Lemke
 
Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022Robert Lemke
 
GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022Robert Lemke
 
OpenID Connect with Neos and Flow
OpenID Connect with Neos and FlowOpenID Connect with Neos and Flow
OpenID Connect with Neos and FlowRobert Lemke
 
Neos Conference 2019 Keynote
Neos Conference 2019 KeynoteNeos Conference 2019 Keynote
Neos Conference 2019 KeynoteRobert Lemke
 
A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)Robert Lemke
 
Neos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteNeos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteRobert Lemke
 
A practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSA practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSRobert Lemke
 
Neos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteNeos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteRobert Lemke
 
IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes Robert Lemke
 
IPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersIPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersRobert Lemke
 
Docker in Production - IPC 2016
Docker in Production - IPC 2016Docker in Production - IPC 2016
Docker in Production - IPC 2016Robert Lemke
 
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Robert Lemke
 
The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)Robert Lemke
 
Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Robert Lemke
 
Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Robert Lemke
 
Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Robert Lemke
 
Turning Neos inside out / React.js HH
Turning Neos inside out / React.js HHTurning Neos inside out / React.js HH
Turning Neos inside out / React.js HHRobert Lemke
 

More from Robert Lemke (20)

Neos Content Repository – Git for content
Neos Content Repository – Git for contentNeos Content Repository – Git for content
Neos Content Repository – Git for content
 
A General Purpose Docker Image for PHP
A General Purpose Docker Image for PHPA General Purpose Docker Image for PHP
A General Purpose Docker Image for PHP
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in Kubernetes
 
Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022
 
GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022
 
OpenID Connect with Neos and Flow
OpenID Connect with Neos and FlowOpenID Connect with Neos and Flow
OpenID Connect with Neos and Flow
 
Neos Conference 2019 Keynote
Neos Conference 2019 KeynoteNeos Conference 2019 Keynote
Neos Conference 2019 Keynote
 
A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)
 
Neos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteNeos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome Keynote
 
A practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSA practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRS
 
Neos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteNeos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome Keynote
 
IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes
 
IPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersIPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for Developers
 
Docker in Production - IPC 2016
Docker in Production - IPC 2016Docker in Production - IPC 2016
Docker in Production - IPC 2016
 
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
 
The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)
 
Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)
 
Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!
 
Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!
 
Turning Neos inside out / React.js HH
Turning Neos inside out / React.js HHTurning Neos inside out / React.js HH
Turning Neos inside out / React.js HH
 

Creating Clean Code with AOP

  • 1. Robert Lemke Create Clean Code with Aspect-Oriented Programming International PHP Conference, Mainz 2010 /** Asp ect *S ecu rity *@ asp ect */ ityA spe ct { cla s s Se cur olic ies; tec ted $p Mittwoch, 13. Oktober 2010 pro
  • 2. Robert Lemke chief architect of TYPO3 Phoenix and FLOW3 co-founder of the TYPO3 Association 34 years old lives in Lübeck, Germany 1 wife, 1 daughter, 1 espresso machine likes drumming Mittwoch, 13. Oktober 2010
  • 3. = PHP 5.3 Full Stack Application Framework Mittwoch, 13. Oktober 2010
  • 4. DI Dependency Injection DRY YAA OOP Object-Oriented Programming YAGNI AOP Aspect-Oriented Programming CoC MVC Model View Controller POPO Plain Old PHP Object TDD Mittwoch, 13. Oktober 2010
  • 5. /** * Creates a new post * * @param F3BlogDomainModelPost $newPost A fresh Post object which has not yet been * added to the repository * @return void */ public function createAction(F3BlogDomainModelPost $newPost) { if ($this->policyService->isGranted($this->currentUser, __CLASS__, __METHOD__) { $this->blog->addPost($newPost); $this->flashMessageContainer->add('Your new post was created.'); $this->systemLogger->log('A new post was created.', LOG_INFO); $this->notificationService->notify('A new post was created.', 'robert@typo3.org'); } else { $this->systemLogger->log('Someone tried to create a post.', LOG_WARNING); throw new F3FLOW3SecurityExceptionAccessDeniedException('Tried to create.'); } $this->redirect('index'); } Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 6. /** * Creates a new post * * @param F3BlogDomainModelPost $newPost A fresh Post object which has not yet been * added to the repository * @return void */ public function createAction(F3BlogDomainModelPost $newPost) { if ($this->policyService->isGranted($this->currentUser, __CLASS__, __METHOD__) { $this->blog->addPost($newPost); $this->flashMessageContainer->add('Your new post was created.'); $this->systemLogger->log('A new post was created.', LOG_INFO); $this->notificationService->notify('A new post was created.', 'robert@typo3.org'); } else { $this->systemLogger->log('Someone tried to create a post.', LOG_WARNING); throw new F3FLOW3SecurityExceptionAccessDeniedException('Tried to create.'); } $this->redirect('index'); } Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 7. AOP Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 8. Aspect-Oriented Programming programming paradigm separates concerns to improve modularization OOP modularizes concerns into objects AOP modularizes cross-cutting concerns into aspects Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 9. /** * Creates a new post * * @param F3BlogDomainModelPost $newPost A fresh Post object which has not yet been * added to the repository * @return void */ public function createAction(F3BlogDomainModelPost $newPost) { $this->blog->addPost($newPost); $this->flashMessageContainer->add('Your new post was created.'); $this->redirect('index'); } Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 10. Concerns? Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 11. Concerns Separation of Concerns group features and behavior into manageable parts have a specific purpose and business to take care of Cross-Cutting Concerns are the party poopers who want to have a say in everything Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 12. Cross-Cutting Concerns Logging Security Persistence Global Business Logic Dirty Hacks Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 13. We don't want infrastructure code in our models. Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 14. We want to unit-test even cross-cutting concerns Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 15. We want to centralize security-related code Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 16. AOP Lingo Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 17. Aspect Part of the application where cross-cutting concerns are implemented In FLOW3 aspects are classes annotated with @aspect Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 18. Join Point Is a single point in the call graph Method Execution Exception Represents an event, not a location Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 19. Pointcut A set of join points where advices could be executed can be composed can be named Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 20. Advice Action to take at a join points defined by the point cut Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 21. DEMO Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 22. Kinds of Advice Advice types supported by FLOW3: @before @afterreturning @afterthrowing @after @around Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 23. Pointcut Designators method(F3MyPackageMyClass->myMethod()) class(F3MyPackageMyClass) within(F3MyPackageMyInterface) classTaggedWith(someTag) methodTaggedWith(anotherTag) setting(Demo.Stuff.SomeSetting = "yeah, do it") filter(F3MyPackageMyCustomFilterImplementation) fi Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 24. Runtime Evaluations evaluate(coffee.kind == "Arabica") Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 25. Compound Pointcuts ! /** !  * @around method(.*Controller->(new|create|edit|update|delete)Action()) &&  !methodTaggedWith(anybodyMayAccessThis) !  */ ! public function interceptMethodCalls($joinPoint) { ... } Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 26. DEMO Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 27. FLOW3's AOP implementation based on proxy classes unlike with most pre-processors line numbers stay the same no scaffolding 0 Lines of generated code which need to be maintained by you fast (on the second hit) Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 28. Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 29. Inspiring people to Hitchhiker's Guide to FLOW3 share Mittwoch, 13. Oktober 2010
  • 30. Progress FLOW3 1.0.0 Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 31. Further Reading FLOW3 Website http://flow3.typo3.org FLOW3 Download http://flow3.typo3.org/download git://git.typo3.org/FLOW3/Distributions/Base.git TYPO3 Forge http://forge.typo3.org Further Reading http://flow3.typo3.org/about/principles/further-reading Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010
  • 32. Questions Email: robert@typo3.org Blog: http://robertlemke.de/blog Twitter: @t3rob Slides: http://slideshare.net/rlmp Create Clean Code with AOP International PHP Conference, Mainz 2010 Mittwoch, 13. Oktober 2010