SlideShare a Scribd company logo
Getting rid of duplicate code:
weaving aspects in PHP with the help of Go! AOP library

                     Alexander Lisachenko
                   lisachenko.it@gmail.com
Speaker profile




      Lisachenko Alexander
• Senior Web Architect at Alpari
• Symfony2 enthusiast: nearly a dozen internal services based
on Symfony2, including primary site alpari.ru(CDN,
Varnish+ESI, Twig, Assetic, ~60 submodules, ~20 bundles)
The evolution of programming




• Machine programming;
• Structured programming;
• Procedure programming;
• Module programming;
• Object-oriented programming;
• < new high-level paradigm >
Good old OOP…




Key elements: classes, objects.
Principles: abstraction, encapsulation, inheritance and
polymorphism.
The principle of single responsibility
The principle of single responsibility
The principle of single responsibility
Authorization...
Logging...
Exception handling...
Why is this so?

All because of crosscutting concerns that permeates all
of the code, like a skewer.
This code can not be placed in separate classes, and is
everywhere:
• caching;
• logging;
• exception handling;
• authorization;
• transactionality.
What do we have in the end?

The clinical diagnosis of typical application: <censored>-
code
• unsuitable for reuse;
• difficult to understand the original purpose of the
class, tangled logic, cyclomatic complexity;
• more likely to make a mistake and forget to write
"boilerplate" code;
• copying of the code, the violation of DRY.
AOP to the rescue!
AOP to the rescue!

             Aspect-Oriented Programming
                        (AOP)
• AOP - programming technique in the class paradigm,
  based on the concept of aspect - a block of code that
  encapsulates the crosscutting logic in the class.
AOP History

•1974 – the principle of division of responsibility
•1990е – AOP research
 • Composition Filters
 • Subject-Oriented Programming
 • Adaptive Programming
• 1997 - Aspect-Oriented Programming (report on the
European Conference on OOP)
• 2001 – AspectJ AOP framework development
Basic concepts of AOP



• Aspect - the module or class implementing
crosscutting concerns. Aspect changes the behavior of
the rest of the code, using advice in joinpoints identified
by some pointcut.
• Advice - action taken by an aspect at a particular join
point. Different types of advice include "around,"
"before" and "after" advice.
Basic concepts of AOP



• Join point — a point during the execution of a
program, such as the execution of a method or the
handling of an exception.
• Pointcut — set of join point. Pointcut determines if it
is suitable join point to the advice given.
• Introduction — changing the structure of the class
and / or change the inheritance hierarchy to add aspect
functionality in foreign code.
Basic concepts of AOP
Basic advice types

• Before - advice that executes before a join point, but
which does not have the ability to prevent execution
flow proceeding to the join point.
• After - advice to be executed after a join point
completes normally.
• Around - advice that surrounds a join point such as a
method invocation. Around advice responsible for
choosing whether to proceed to the join point or to
shortcut the advised method execution by returning its
own return value or throwing an exception.
Basic advice types




                            Before


                             Before




                     After Throwing



                              After
Place for AOP in PHP




 AOP complements existing technology into a single
entity:
• Dependency injection (IoC, DIC)
• Abstraction of services (yaml, xml, php)
• Aspect-Oriented Programming
Place for AOP in PHP




• Dependency injection
• Abstraction of services
• Aspect-Oriented Programming
Current implementation of AOP

 Promising solutions:
• AOP-PHP
• JMSAopBundle
• TYPO3 Flow AOP component
 Cemetery:
• PHPAspect
• Aspect-Oriented PHP
• AspectPHP
Go! library

   The basic idea is not new - replace a class with a similar
class-decorator implementation.
   Key points:
      • Static analysis of classes before loading them into
  memory (php-token-reflection, ядро ApiGen)
      • Change the class hierarchy "on the fly"
      • Modification of source code for the class at the
  time of class load, caching
Go! library

• Does not use PHP-extensions, written entirely in PHP
itself;
• Does not require the DI-container for spoofing
services with proxy objects;
• Can intercept methods in final classes, final methods,
and static methods;
• Can intercept access to public and protected
properties;
• Clean code is generated, it is convenient to debug
classes and aspects with XDebug
Class source code
Aspect class
The result of running...
Processed code of the class
A good example is the best
sermon
A good example is the best
sermon
Caching with aspect example
What is expected?



• Pointcut parser (look at FLOW3)
• Introduction — add traits and interfaces to classes
• Caching array of advices in shared-memory — no
need to check anything at runtime (hello, serialization of
Closure)
• Init joinpoints — replace all «new» expressions with
custom joinpoints
• Maximum performance :)
Thank you!
                                 Questions?
                      https://github.com/lisachenko/go-aop-php
Our company profile
                                                            Link to the library:
on hh.ru

More Related Content

What's hot (20)

PPTX
AspectJ Android with Example
firstthumb
 
PDF
Rootcon X - Reverse Engineering Swift Applications
eightbit
 
PPTX
Architectural changes in Orion
Tomas Dermisek
 
PDF
Wahckon[2] - iOS Runtime Hacking Crash Course
eightbit
 
KEY
Language Engineering in the Cloud
lennartkats
 
PPTX
Intro to kotlin
Tomislav Homan
 
PPTX
CPAN Curation
neilbowers
 
PDF
The Rise of Functional Programming
Tjerk W
 
PDF
Robot framework - Lord of the Rings
Asheesh Mehdiratta
 
KEY
Test-driven language development
lennartkats
 
ODP
Fast, Faster and Super-Fast Queries
Edward Willink
 
PDF
Introduction to Scala Implicits, Pimp my library and Typeclasses
Jordi Pradel
 
PDF
Thinking Functionally
Piyush Katariya
 
PDF
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
lennartkats
 
PDF
Advice weaving in AspectJ
Sander Mak (@Sander_Mak)
 
ODP
Using Functional Programming to improve your code: A working example
Jorge Sánchez
 
PPTX
CPAN Exporter modules for Perl 5
neilbowers
 
PPSX
Kotlin Language powerpoint show file
Saurabh Tripathi
 
PPT
Error handling in visual fox pro 9
Mike Feltman
 
AspectJ Android with Example
firstthumb
 
Rootcon X - Reverse Engineering Swift Applications
eightbit
 
Architectural changes in Orion
Tomas Dermisek
 
Wahckon[2] - iOS Runtime Hacking Crash Course
eightbit
 
Language Engineering in the Cloud
lennartkats
 
Intro to kotlin
Tomislav Homan
 
CPAN Curation
neilbowers
 
The Rise of Functional Programming
Tjerk W
 
Robot framework - Lord of the Rings
Asheesh Mehdiratta
 
Test-driven language development
lennartkats
 
Fast, Faster and Super-Fast Queries
Edward Willink
 
Introduction to Scala Implicits, Pimp my library and Typeclasses
Jordi Pradel
 
Thinking Functionally
Piyush Katariya
 
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
lennartkats
 
Advice weaving in AspectJ
Sander Mak (@Sander_Mak)
 
Using Functional Programming to improve your code: A working example
Jorge Sánchez
 
CPAN Exporter modules for Perl 5
neilbowers
 
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Error handling in visual fox pro 9
Mike Feltman
 

Viewers also liked (20)

PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Alexander Lisachenko
 
PDF
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Alexander Lisachenko
 
ODP
Aspect-Oriented Programming for PHP
William Candillon
 
PDF
AOP in Python API design
meij200
 
PPTX
Enterprise Symfony Architecture (RU)
Alexander Lisachenko
 
PDF
Spring framework aop
Taemon Piya-Lumyong
 
PDF
Symfony Components
Fabien Potencier
 
PPT
Внедрение аспектов в PHP с помощью библиотеки GO! AOP
Alexander Lisachenko
 
PDF
Fluid powered TYPO3
Christof Rodejohann
 
ODP
Go nuts with Go and PHP
Mariano Iglesias
 
ODP
FED presentation
ClausDue
 
ODP
2016 fsc
Thomas Kieslich
 
PPT
Spring AOP
AnushaNaidu
 
PDF
CoffeeScript
Jeroen Rosenberg
 
PDF
MVP & Startup, with OpenSource Software and Microsoft Azure
Francesco Fullone
 
PPSX
Spring AOP
cteguh
 
PPT
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Meet Magento Italy
 
PPTX
Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015
Meet Magento Italy
 
PDF
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Symfoniacs
 
PPT
Have you played this Symfony? Why Symfony is great choice for Web development
Mike Taylor
 
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Alexander Lisachenko
 
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Alexander Lisachenko
 
Aspect-Oriented Programming for PHP
William Candillon
 
AOP in Python API design
meij200
 
Enterprise Symfony Architecture (RU)
Alexander Lisachenko
 
Spring framework aop
Taemon Piya-Lumyong
 
Symfony Components
Fabien Potencier
 
Внедрение аспектов в PHP с помощью библиотеки GO! AOP
Alexander Lisachenko
 
Fluid powered TYPO3
Christof Rodejohann
 
Go nuts with Go and PHP
Mariano Iglesias
 
FED presentation
ClausDue
 
2016 fsc
Thomas Kieslich
 
Spring AOP
AnushaNaidu
 
CoffeeScript
Jeroen Rosenberg
 
MVP & Startup, with OpenSource Software and Microsoft Azure
Francesco Fullone
 
Spring AOP
cteguh
 
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Meet Magento Italy
 
Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015
Meet Magento Italy
 
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Symfoniacs
 
Have you played this Symfony? Why Symfony is great choice for Web development
Mike Taylor
 
Ad

Similar to Weaving aspects in PHP with the help of Go! AOP library (20)

PDF
WoMakersCode 2016 - Shit Happens
Jackson F. de A. Mafra
 
PPTX
Spring AOP
Radhakrishna Mutthoju
 
PDF
Aspect-Oriented Programming and Depedency Injection
Robert Lemke
 
PPTX
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Yan Cui
 
PPT
Aspect Oriented Software Development
Jignesh Patel
 
PPT
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
Thuy_Dang
 
PPTX
Aspect Oriented Programming
Shreya Chatterjee
 
PPTX
Aspect Oriented Programming
Rodger Oates
 
PPTX
Spring AOP in Nutshell
Onkar Deshpande
 
PPTX
Aspect Oriented Programming
Rajesh Ganesan
 
PPT
ASPECT ORIENTED PROGRAMING(aop)
kvsrteja
 
PPTX
spring aop
Kalyani Patil
 
PDF
Aspect oriented software development
Maryam Malekzad
 
PPTX
Spring AOP Introduction
b0ris_1
 
PPTX
Introduction To AOP
Donald Belcham
 
PPTX
Introduction to Aspect Oriented Programming by Donald Belcham
.NET Conf UY
 
PPTX
Intro To AOP
Donald Belcham
 
PPTX
Introduction to Aspect Oriented Programming
Yan Cui
 
PPTX
Aspect Oriented Programming
Fernando Almeida
 
ODP
Aspect-oriented programming in Perl
megakott
 
WoMakersCode 2016 - Shit Happens
Jackson F. de A. Mafra
 
Aspect-Oriented Programming and Depedency Injection
Robert Lemke
 
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Yan Cui
 
Aspect Oriented Software Development
Jignesh Patel
 
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
Thuy_Dang
 
Aspect Oriented Programming
Shreya Chatterjee
 
Aspect Oriented Programming
Rodger Oates
 
Spring AOP in Nutshell
Onkar Deshpande
 
Aspect Oriented Programming
Rajesh Ganesan
 
ASPECT ORIENTED PROGRAMING(aop)
kvsrteja
 
spring aop
Kalyani Patil
 
Aspect oriented software development
Maryam Malekzad
 
Spring AOP Introduction
b0ris_1
 
Introduction To AOP
Donald Belcham
 
Introduction to Aspect Oriented Programming by Donald Belcham
.NET Conf UY
 
Intro To AOP
Donald Belcham
 
Introduction to Aspect Oriented Programming
Yan Cui
 
Aspect Oriented Programming
Fernando Almeida
 
Aspect-oriented programming in Perl
megakott
 
Ad

Recently uploaded (20)

PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PPTX
Earn Agentblazer Status with Slack Community Patna.pptx
SanjeetMishra29
 
PPTX
Lecture 5 - Agentic AI and model context protocol.pptx
Dr. LAM Yat-fai (林日辉)
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PPTX
Machine Learning Benefits Across Industries
SynapseIndia
 
PPTX
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
PDF
Arcee AI - building and working with small language models (06/25)
Julien SIMON
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
Novus Safe Lite- What is Novus Safe Lite.pdf
Novus Hi-Tech
 
PDF
Productivity Management Software | Workstatus
Lovely Baghel
 
PDF
Bitcoin+ Escalando sin concesiones - Parte 1
Fernando Paredes García
 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
PDF
2025-07-15 EMEA Volledig Inzicht Dutch Webinar
ThousandEyes
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Integrating IIoT with SCADA in Oil & Gas A Technical Perspective.pdf
Rejig Digital
 
PDF
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PDF
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
Earn Agentblazer Status with Slack Community Patna.pptx
SanjeetMishra29
 
Lecture 5 - Agentic AI and model context protocol.pptx
Dr. LAM Yat-fai (林日辉)
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Machine Learning Benefits Across Industries
SynapseIndia
 
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
Arcee AI - building and working with small language models (06/25)
Julien SIMON
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Novus Safe Lite- What is Novus Safe Lite.pdf
Novus Hi-Tech
 
Productivity Management Software | Workstatus
Lovely Baghel
 
Bitcoin+ Escalando sin concesiones - Parte 1
Fernando Paredes García
 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
2025-07-15 EMEA Volledig Inzicht Dutch Webinar
ThousandEyes
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Integrating IIoT with SCADA in Oil & Gas A Technical Perspective.pdf
Rejig Digital
 
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Novus-Safe Pro: Brochure-What is Novus Safe Pro?.pdf
Novus Hi-Tech
 

Weaving aspects in PHP with the help of Go! AOP library

  • 1. Getting rid of duplicate code: weaving aspects in PHP with the help of Go! AOP library Alexander Lisachenko [email protected]
  • 2. Speaker profile Lisachenko Alexander • Senior Web Architect at Alpari • Symfony2 enthusiast: nearly a dozen internal services based on Symfony2, including primary site alpari.ru(CDN, Varnish+ESI, Twig, Assetic, ~60 submodules, ~20 bundles)
  • 3. The evolution of programming • Machine programming; • Structured programming; • Procedure programming; • Module programming; • Object-oriented programming; • < new high-level paradigm >
  • 4. Good old OOP… Key elements: classes, objects. Principles: abstraction, encapsulation, inheritance and polymorphism.
  • 5. The principle of single responsibility
  • 6. The principle of single responsibility
  • 7. The principle of single responsibility
  • 11. Why is this so? All because of crosscutting concerns that permeates all of the code, like a skewer. This code can not be placed in separate classes, and is everywhere: • caching; • logging; • exception handling; • authorization; • transactionality.
  • 12. What do we have in the end? The clinical diagnosis of typical application: <censored>- code • unsuitable for reuse; • difficult to understand the original purpose of the class, tangled logic, cyclomatic complexity; • more likely to make a mistake and forget to write "boilerplate" code; • copying of the code, the violation of DRY.
  • 13. AOP to the rescue!
  • 14. AOP to the rescue! Aspect-Oriented Programming (AOP) • AOP - programming technique in the class paradigm, based on the concept of aspect - a block of code that encapsulates the crosscutting logic in the class.
  • 15. AOP History •1974 – the principle of division of responsibility •1990е – AOP research • Composition Filters • Subject-Oriented Programming • Adaptive Programming • 1997 - Aspect-Oriented Programming (report on the European Conference on OOP) • 2001 – AspectJ AOP framework development
  • 16. Basic concepts of AOP • Aspect - the module or class implementing crosscutting concerns. Aspect changes the behavior of the rest of the code, using advice in joinpoints identified by some pointcut. • Advice - action taken by an aspect at a particular join point. Different types of advice include "around," "before" and "after" advice.
  • 17. Basic concepts of AOP • Join point — a point during the execution of a program, such as the execution of a method or the handling of an exception. • Pointcut — set of join point. Pointcut determines if it is suitable join point to the advice given. • Introduction — changing the structure of the class and / or change the inheritance hierarchy to add aspect functionality in foreign code.
  • 19. Basic advice types • Before - advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point. • After - advice to be executed after a join point completes normally. • Around - advice that surrounds a join point such as a method invocation. Around advice responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.
  • 20. Basic advice types Before Before After Throwing After
  • 21. Place for AOP in PHP AOP complements existing technology into a single entity: • Dependency injection (IoC, DIC) • Abstraction of services (yaml, xml, php) • Aspect-Oriented Programming
  • 22. Place for AOP in PHP • Dependency injection • Abstraction of services • Aspect-Oriented Programming
  • 23. Current implementation of AOP Promising solutions: • AOP-PHP • JMSAopBundle • TYPO3 Flow AOP component Cemetery: • PHPAspect • Aspect-Oriented PHP • AspectPHP
  • 24. Go! library The basic idea is not new - replace a class with a similar class-decorator implementation. Key points: • Static analysis of classes before loading them into memory (php-token-reflection, ядро ApiGen) • Change the class hierarchy "on the fly" • Modification of source code for the class at the time of class load, caching
  • 25. Go! library • Does not use PHP-extensions, written entirely in PHP itself; • Does not require the DI-container for spoofing services with proxy objects; • Can intercept methods in final classes, final methods, and static methods; • Can intercept access to public and protected properties; • Clean code is generated, it is convenient to debug classes and aspects with XDebug
  • 28. The result of running...
  • 29. Processed code of the class
  • 30. A good example is the best sermon
  • 31. A good example is the best sermon
  • 33. What is expected? • Pointcut parser (look at FLOW3) • Introduction — add traits and interfaces to classes • Caching array of advices in shared-memory — no need to check anything at runtime (hello, serialization of Closure) • Init joinpoints — replace all «new» expressions with custom joinpoints • Maximum performance :)
  • 34. Thank you! Questions? https://github.com/lisachenko/go-aop-php Our company profile Link to the library: on hh.ru