SlideShare a Scribd company logo
@magma_digital
Code All the Things
An introduction to Aspect–Oriented Programming
@magma_digital
Who am I?
๏ Jeremy Coates, CEO, Magma Digital Ltd
๏ Founder of PHPNW User Group & Conference
๏ Digital Lancashire CIC Founding Director
๏ International Conference Speaker
๏ Coach of Coaches - WeCa.mp (code camp)
๏ @phpcodemonkey
๏ linkedin.com/in/jeremycoates
@magma_digital
★ Aspect–Oriented Programming - using Go! AOP
• Separate cross-cutting concerns (logging, caching etc.) into
Aspects (aka. a class that implements Aspect)
• Adds behaviour without modifying code itself - Advice (can
be an annotation e.g. @Around, @Before or @After)
• An approach to specify where to apply an Advice - Pointcut
(regex matching) / Join Points (a script execution point e.g.
method)
Aspect–Oriented What?
@magma_digital
★ Concerns like logging, security, caching
• Don’t neatly fit traditional OOP models
• They cut across concerns and litter our code
• $logger->info(‘message’);
• $perm->hasPriv(‘admin’);
OOP but not as we know it
@magma_digital
★ Regular classes that bundle functionality
• Like logging, caching, security etc.
• Use annotations to trigger method invocation
• @Before(“@execution(MagmaDigitalAnnotatio
nLoggable)”)
• @Before("execution(public Example->*(*))")
Aspect
@magma_digital
★ A conceptual term indicating a point during the
execution of a script e.g.
• Method or
• Property Access
Join Point
@magma_digital
★ Action taken by an Aspect at a given Join Point - Identified by
an annotation
• @Before - executes before the Join Point
• @After / @AfterThrowing - Executes after the Join Point
exits
• @Around - surrounds the Join Point
• Custom behaviour before & after, can also prevent
continued execution, return own value/exception etc.
@Advice
@magma_digital
★ Simply a regular expression that matches join points
• An Advice is linked to the Pointcut and runs at any
Join Point matched by the regex
• e.g. methods matching a certain name stub
• @Pointcut("@execution(MagmaDigital
AnnotationLoggableDetailed)")
Pointcut
@magma_digital
★ Framework depends on autoloading
• Really old legacy code needs converting first
★ composer require goaop/framework
★ Create application AspectKernel
★ Configure AspectKernel
★ Create an Aspect class (& Register in AspectKernel)
Go! AOP
First 10 Minutes
@magma_digital
★ Aspect–Oriented Programming can also
• Introduce new interfaces / traits (inter-type
declaration)
• e.g. make all DTOs implement Serializable
• Weave code - link to other applications/objects
• e.g. Doctrine Entities
Advanced Use
@magma_digital
★ PHPStorm - Go! AOP Framework plugin
• also needs PHP Annotations Plugin
★ Frameworks
• goaop-laravel-bridge
• goaop-symfony-bundle
• goaop-zf2-module
Support
@magma_digital
★ Codeception/AspectMock (github)
• Based on Go! AOP
• Create test doubles for static methods
• Create test doubles for class methods (wherever
they’re called)
• Redefine (PHP or user)methods on the fly
Aspect–Oriented Testing
@magma_digital
★ http://go.aopphp.com/docs/
★ https://packagist.org/packages/goaop/framework
★ https://github.com/goaop/framework
• https://github.com/goaop
★ https://github.com/Codeception/AspectMock
Resources

More Related Content

Similar to Aspect Oriented Programming (20)

ODP
Weaving aspects in PHP with the help of Go! AOP library
Alexander Lisachenko
 
PDF
WoMakersCode 2016 - Shit Happens
Jackson F. de A. Mafra
 
ODP
Aspect-Oriented Programming for PHP
William Candillon
 
PDF
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Alexander Lisachenko
 
PDF
AOP (Aspect-Oriented Programming) spring boot
PLAYAFIFI
 
PDF
TDC 2015 - POA - Trilha PHP - Shit Happens
Jackson F. de A. Mafra
 
PPTX
Aspect Oriented Programming
Rajesh Ganesan
 
PPTX
Spring AOP in Nutshell
Onkar Deshpande
 
PPTX
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Yan Cui
 
PPTX
Spring AOP
Radhakrishna Mutthoju
 
PPT
Aop spring
chamilavt
 
ODP
Aspect-oriented programming in Perl
megakott
 
PPTX
Spring AOP Introduction
b0ris_1
 
PPTX
Aspect Oriented Programming
Rodger Oates
 
PPT
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
Thuy_Dang
 
PPTX
Summary of Aspect Oriented Programming
Michael Jo
 
PPTX
Aspect Oriented Programming
Shreya Chatterjee
 
PPSX
Spring AOP
cteguh
 
PPTX
Aspect Oriented Programming
Fernando Almeida
 
PPTX
AspectMock
Bryce Embry
 
Weaving aspects in PHP with the help of Go! AOP library
Alexander Lisachenko
 
WoMakersCode 2016 - Shit Happens
Jackson F. de A. Mafra
 
Aspect-Oriented Programming for PHP
William Candillon
 
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Alexander Lisachenko
 
AOP (Aspect-Oriented Programming) spring boot
PLAYAFIFI
 
TDC 2015 - POA - Trilha PHP - Shit Happens
Jackson F. de A. Mafra
 
Aspect Oriented Programming
Rajesh Ganesan
 
Spring AOP in Nutshell
Onkar Deshpande
 
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Yan Cui
 
Aop spring
chamilavt
 
Aspect-oriented programming in Perl
megakott
 
Spring AOP Introduction
b0ris_1
 
Aspect Oriented Programming
Rodger Oates
 
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
Thuy_Dang
 
Summary of Aspect Oriented Programming
Michael Jo
 
Aspect Oriented Programming
Shreya Chatterjee
 
Spring AOP
cteguh
 
Aspect Oriented Programming
Fernando Almeida
 
AspectMock
Bryce Embry
 

More from Jeremy Coates (17)

PPTX
Cyber Security and GDPR
Jeremy Coates
 
PDF
Why is PHP Awesome
Jeremy Coates
 
PDF
Testing with Codeception
Jeremy Coates
 
KEY
An introduction to Phing the PHP build system (PHPDay, May 2012)
Jeremy Coates
 
KEY
An introduction to Phing the PHP build system
Jeremy Coates
 
KEY
Insects in your mind
Jeremy Coates
 
KEY
Phing
Jeremy Coates
 
KEY
Hudson Continuous Integration for PHP
Jeremy Coates
 
PDF
The Uncertainty Principle
Jeremy Coates
 
PPT
Exploiting Php With Php
Jeremy Coates
 
ODP
What's new, what's hot in PHP 5.3
Jeremy Coates
 
PDF
Kiss Phpnw08
Jeremy Coates
 
PPT
Regex Basics
Jeremy Coates
 
ODP
Search Lucene
Jeremy Coates
 
PDF
Mysql Explain Explained
Jeremy Coates
 
ODP
Introduction to Version Control
Jeremy Coates
 
ODP
PHPNW Conference Update
Jeremy Coates
 
Cyber Security and GDPR
Jeremy Coates
 
Why is PHP Awesome
Jeremy Coates
 
Testing with Codeception
Jeremy Coates
 
An introduction to Phing the PHP build system (PHPDay, May 2012)
Jeremy Coates
 
An introduction to Phing the PHP build system
Jeremy Coates
 
Insects in your mind
Jeremy Coates
 
Hudson Continuous Integration for PHP
Jeremy Coates
 
The Uncertainty Principle
Jeremy Coates
 
Exploiting Php With Php
Jeremy Coates
 
What's new, what's hot in PHP 5.3
Jeremy Coates
 
Kiss Phpnw08
Jeremy Coates
 
Regex Basics
Jeremy Coates
 
Search Lucene
Jeremy Coates
 
Mysql Explain Explained
Jeremy Coates
 
Introduction to Version Control
Jeremy Coates
 
PHPNW Conference Update
Jeremy Coates
 
Ad

Recently uploaded (20)

PPTX
For my supp to finally picking supp that work
necas19388
 
PDF
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
 
PDF
How DeepSeek Beats ChatGPT: Cost Comparison and Key Differences
sumitpurohit810
 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
PDF
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PPTX
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
 
PPTX
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
PPTX
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
PDF
Automated Test Case Repair Using Language Models
Lionel Briand
 
PPTX
How Can Recruitment Management Software Improve Hiring Efficiency?
HireME
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PDF
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
For my supp to finally picking supp that work
necas19388
 
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
 
How DeepSeek Beats ChatGPT: Cost Comparison and Key Differences
sumitpurohit810
 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
 
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
Automated Test Case Repair Using Language Models
Lionel Briand
 
How Can Recruitment Management Software Improve Hiring Efficiency?
HireME
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
Ad

Aspect Oriented Programming

  • 1. @magma_digital Code All the Things An introduction to Aspect–Oriented Programming
  • 2. @magma_digital Who am I? ๏ Jeremy Coates, CEO, Magma Digital Ltd ๏ Founder of PHPNW User Group & Conference ๏ Digital Lancashire CIC Founding Director ๏ International Conference Speaker ๏ Coach of Coaches - WeCa.mp (code camp) ๏ @phpcodemonkey ๏ linkedin.com/in/jeremycoates
  • 3. @magma_digital ★ Aspect–Oriented Programming - using Go! AOP • Separate cross-cutting concerns (logging, caching etc.) into Aspects (aka. a class that implements Aspect) • Adds behaviour without modifying code itself - Advice (can be an annotation e.g. @Around, @Before or @After) • An approach to specify where to apply an Advice - Pointcut (regex matching) / Join Points (a script execution point e.g. method) Aspect–Oriented What?
  • 4. @magma_digital ★ Concerns like logging, security, caching • Don’t neatly fit traditional OOP models • They cut across concerns and litter our code • $logger->info(‘message’); • $perm->hasPriv(‘admin’); OOP but not as we know it
  • 5. @magma_digital ★ Regular classes that bundle functionality • Like logging, caching, security etc. • Use annotations to trigger method invocation • @Before(“@execution(MagmaDigitalAnnotatio nLoggable)”) • @Before("execution(public Example->*(*))") Aspect
  • 6. @magma_digital ★ A conceptual term indicating a point during the execution of a script e.g. • Method or • Property Access Join Point
  • 7. @magma_digital ★ Action taken by an Aspect at a given Join Point - Identified by an annotation • @Before - executes before the Join Point • @After / @AfterThrowing - Executes after the Join Point exits • @Around - surrounds the Join Point • Custom behaviour before & after, can also prevent continued execution, return own value/exception etc. @Advice
  • 8. @magma_digital ★ Simply a regular expression that matches join points • An Advice is linked to the Pointcut and runs at any Join Point matched by the regex • e.g. methods matching a certain name stub • @Pointcut("@execution(MagmaDigital AnnotationLoggableDetailed)") Pointcut
  • 9. @magma_digital ★ Framework depends on autoloading • Really old legacy code needs converting first ★ composer require goaop/framework ★ Create application AspectKernel ★ Configure AspectKernel ★ Create an Aspect class (& Register in AspectKernel) Go! AOP First 10 Minutes
  • 10. @magma_digital ★ Aspect–Oriented Programming can also • Introduce new interfaces / traits (inter-type declaration) • e.g. make all DTOs implement Serializable • Weave code - link to other applications/objects • e.g. Doctrine Entities Advanced Use
  • 11. @magma_digital ★ PHPStorm - Go! AOP Framework plugin • also needs PHP Annotations Plugin ★ Frameworks • goaop-laravel-bridge • goaop-symfony-bundle • goaop-zf2-module Support
  • 12. @magma_digital ★ Codeception/AspectMock (github) • Based on Go! AOP • Create test doubles for static methods • Create test doubles for class methods (wherever they’re called) • Redefine (PHP or user)methods on the fly Aspect–Oriented Testing
  • 13. @magma_digital ★ http://go.aopphp.com/docs/ ★ https://packagist.org/packages/goaop/framework ★ https://github.com/goaop/framework • https://github.com/goaop ★ https://github.com/Codeception/AspectMock Resources

Editor's Notes

  • #3: I’ve been a developer for almost 20 years and have long history of consulting, adopting other peoples projects and running kick-ass software agency. For my day job, I am CEO of Magma Digital Ltd, a 20 strong team focussing on delivering business critical software development, using PHP, to enterprise. I am also the driving force behind the UK's PHPNW conference, user group and brand, I started the group in 2008 and have, with assistance from many others, helped the group to be able to deliver seven years of high quality conferences, now with 400+ delegates. The passion for this comes from my personal drive to improve skills in those around me who I serve through mentoring, coaching, training and speaking. Pleasure of attending all but 1 Benelux conference and speaking at PHPBNL 12, 14 and now 16 - seems like even numbered years are my thing!