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

AspectJ Android with Example
AspectJ Android with ExampleAspectJ Android with Example
AspectJ Android with Example
firstthumb
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applications
eightbit
 
Architectural changes in Orion
Architectural changes in OrionArchitectural changes in Orion
Architectural changes in Orion
Tomas Dermisek
 
Wahckon[2] - iOS Runtime Hacking Crash Course
Wahckon[2] - iOS Runtime Hacking Crash CourseWahckon[2] - iOS Runtime Hacking Crash Course
Wahckon[2] - iOS Runtime Hacking Crash Course
eightbit
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloudlennartkats
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
Tomislav Homan
 
CPAN Curation
CPAN CurationCPAN Curation
CPAN Curation
neilbowers
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
Tjerk Wolterink
 
Robot framework - Lord of the Rings
Robot framework - Lord of the RingsRobot framework - Lord of the Rings
Robot framework - Lord of the Rings
Asheesh Mehdiratta
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language developmentlennartkats
 
Fast, Faster and Super-Fast Queries
Fast, Faster and Super-Fast QueriesFast, Faster and Super-Fast Queries
Fast, Faster and Super-Fast Queries
Edward Willink
 
Introduction to Scala Implicits, Pimp my library and Typeclasses
Introduction to Scala Implicits, Pimp my library and TypeclassesIntroduction to Scala Implicits, Pimp my library and Typeclasses
Introduction to Scala Implicits, Pimp my library and Typeclasses
Jordi Pradel
 
Thinking Functionally
Thinking FunctionallyThinking Functionally
Thinking Functionally
Piyush Katariya
 
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
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...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...lennartkats
 
Advice weaving in AspectJ
Advice weaving in AspectJAdvice weaving in AspectJ
Advice weaving in AspectJ
Sander Mak (@Sander_Mak)
 
Using Functional Programming to improve your code: A working example
Using Functional Programming to improve your code: A working exampleUsing Functional Programming to improve your code: A working example
Using Functional Programming to improve your code: A working example
Jorge Sánchez
 
CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5
neilbowers
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Error handling in visual fox pro 9
Error handling in visual fox pro 9Error handling in visual fox pro 9
Error handling in visual fox pro 9
Mike Feltman
 

What's hot (20)

AspectJ Android with Example
AspectJ Android with ExampleAspectJ Android with Example
AspectJ Android with Example
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applications
 
Architectural changes in Orion
Architectural changes in OrionArchitectural changes in Orion
Architectural changes in Orion
 
Wahckon[2] - iOS Runtime Hacking Crash Course
Wahckon[2] - iOS Runtime Hacking Crash CourseWahckon[2] - iOS Runtime Hacking Crash Course
Wahckon[2] - iOS Runtime Hacking Crash Course
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloud
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
CPAN Curation
CPAN CurationCPAN Curation
CPAN Curation
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
 
Robot framework - Lord of the Rings
Robot framework - Lord of the RingsRobot framework - Lord of the Rings
Robot framework - Lord of the Rings
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
 
Fast, Faster and Super-Fast Queries
Fast, Faster and Super-Fast QueriesFast, Faster and Super-Fast Queries
Fast, Faster and Super-Fast Queries
 
Introduction to Scala Implicits, Pimp my library and Typeclasses
Introduction to Scala Implicits, Pimp my library and TypeclassesIntroduction to Scala Implicits, Pimp my library and Typeclasses
Introduction to Scala Implicits, Pimp my library and Typeclasses
 
Thinking Functionally
Thinking FunctionallyThinking Functionally
Thinking Functionally
 
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
 
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
 
Advice weaving in AspectJ
Advice weaving in AspectJAdvice weaving in AspectJ
Advice weaving in AspectJ
 
Using Functional Programming to improve your code: A working example
Using Functional Programming to improve your code: A working exampleUsing Functional Programming to improve your code: A working example
Using Functional Programming to improve your code: A working example
 
CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Error handling in visual fox pro 9
Error handling in visual fox pro 9Error handling in visual fox pro 9
Error handling in visual fox pro 9
 

Viewers also liked

Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Alexander Lisachenko
 
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016 Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Alexander Lisachenko
 
Aspect-Oriented Programming for PHP
Aspect-Oriented Programming for PHPAspect-Oriented Programming for PHP
Aspect-Oriented Programming for PHP
William Candillon
 
AOP in Python API design
AOP in Python API designAOP in Python API design
AOP in Python API design
meij200
 
Enterprise Symfony Architecture (RU)
Enterprise Symfony Architecture (RU)Enterprise Symfony Architecture (RU)
Enterprise Symfony Architecture (RU)
Alexander Lisachenko
 
Внедрение аспектов в PHP с помощью библиотеки GO! AOP
Внедрение аспектов в PHP с помощью библиотеки GO! AOPВнедрение аспектов в PHP с помощью библиотеки GO! AOP
Внедрение аспектов в PHP с помощью библиотеки GO! AOP
Alexander Lisachenko
 
Fluid powered TYPO3
Fluid powered TYPO3Fluid powered TYPO3
Fluid powered TYPO3
Christof Rodejohann
 
FED presentation
FED presentationFED presentation
FED presentation
ClausDue
 
2016 fsc
2016 fsc2016 fsc
2016 fsc
Thomas Kieslich
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
AnushaNaidu
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Jeroen Rosenberg
 
MVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft AzureMVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft Azure
Francesco Fullone
 
Spring AOP
Spring AOPSpring AOP
Spring AOPcteguh
 
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
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
Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015
Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015
Meet Magento Italy
 
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Enterprise symfony architecture (Alexander Lisachenko, Alpari)Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Symfoniacs
 
Have you played this Symfony? Why Symfony is great choice for Web development
Have you played this Symfony? Why Symfony is great choice for Web developmentHave you played this Symfony? Why Symfony is great choice for Web development
Have you played this Symfony? Why Symfony is great choice for Web development
Mike Taylor
 

Viewers also liked (20)

Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
 
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016 Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
Solving Cross-Cutting Concerns in PHP - DutchPHP Conference 2016
 
Aspect-Oriented Programming for PHP
Aspect-Oriented Programming for PHPAspect-Oriented Programming for PHP
Aspect-Oriented Programming for PHP
 
AOP in Python API design
AOP in Python API designAOP in Python API design
AOP in Python API design
 
Enterprise Symfony Architecture (RU)
Enterprise Symfony Architecture (RU)Enterprise Symfony Architecture (RU)
Enterprise Symfony Architecture (RU)
 
Spring framework aop
Spring framework aopSpring framework aop
Spring framework aop
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
Внедрение аспектов в PHP с помощью библиотеки GO! AOP
Внедрение аспектов в PHP с помощью библиотеки GO! AOPВнедрение аспектов в PHP с помощью библиотеки GO! AOP
Внедрение аспектов в PHP с помощью библиотеки GO! AOP
 
Fluid powered TYPO3
Fluid powered TYPO3Fluid powered TYPO3
Fluid powered TYPO3
 
Go nuts with Go and PHP
Go nuts with Go and PHPGo nuts with Go and PHP
Go nuts with Go and PHP
 
FED presentation
FED presentationFED presentation
FED presentation
 
2016 fsc
2016 fsc2016 fsc
2016 fsc
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
MVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft AzureMVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft Azure
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
 
Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015
Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015
Basilio Bentivegna: I principali business trends nell’eCommerce per il 2015
 
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Enterprise symfony architecture (Alexander Lisachenko, Alpari)Enterprise symfony architecture (Alexander Lisachenko, Alpari)
Enterprise symfony architecture (Alexander Lisachenko, Alpari)
 
Have you played this Symfony? Why Symfony is great choice for Web development
Have you played this Symfony? Why Symfony is great choice for Web developmentHave you played this Symfony? Why Symfony is great choice for Web development
Have you played this Symfony? Why Symfony is great choice for Web development
 

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

Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and BytecodeYoav Avrahami
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratchtutorialsruby
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratchtutorialsruby
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
Mayank Panchal
 
Constrained Optimization with Genetic Algorithms and Project Bonsai
Constrained Optimization with Genetic Algorithms and Project BonsaiConstrained Optimization with Genetic Algorithms and Project Bonsai
Constrained Optimization with Genetic Algorithms and Project Bonsai
Ivo Andreev
 
Spring AOP
Spring AOPSpring AOP
Design patterns and MV
Design patterns and MVDesign patterns and MV
Design patterns and MVSway Wang
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
Summary of Aspect Oriented Programming
Summary of Aspect Oriented ProgrammingSummary of Aspect Oriented Programming
Summary of Aspect Oriented Programming
Michael Jo
 
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Arnaud Bouchez
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
Heartin Jacob
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
Prashant Rane
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to SpringSujit Kumar
 
2012 S&P Paper Reading Session1
2012 S&P Paper Reading Session12012 S&P Paper Reading Session1
2012 S&P Paper Reading Session1Chong-Kuan Chen
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
Chris Aniszczyk
 
[meetup] Mastering Java enhancements like a Pro: practical design patterns an...
[meetup] Mastering Java enhancements like a Pro: practical design patterns an...[meetup] Mastering Java enhancements like a Pro: practical design patterns an...
[meetup] Mastering Java enhancements like a Pro: practical design patterns an...
Miro Wengner
 
Oslo Program Overview, OpenStack Atlanta
Oslo Program Overview, OpenStack AtlantaOslo Program Overview, OpenStack Atlanta
Oslo Program Overview, OpenStack Atlanta
doughellmann
 

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

Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratch
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratch
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Constrained Optimization with Genetic Algorithms and Project Bonsai
Constrained Optimization with Genetic Algorithms and Project BonsaiConstrained Optimization with Genetic Algorithms and Project Bonsai
Constrained Optimization with Genetic Algorithms and Project Bonsai
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Design patterns and MV
Design patterns and MVDesign patterns and MV
Design patterns and MV
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Summary of Aspect Oriented Programming
Summary of Aspect Oriented ProgrammingSummary of Aspect Oriented Programming
Summary of Aspect Oriented Programming
 
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)Object Pascal Clean Code Guidelines Proposal (at EKON 22)
Object Pascal Clean Code Guidelines Proposal (at EKON 22)
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
2012 S&P Paper Reading Session1
2012 S&P Paper Reading Session12012 S&P Paper Reading Session1
2012 S&P Paper Reading Session1
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
 
[meetup] Mastering Java enhancements like a Pro: practical design patterns an...
[meetup] Mastering Java enhancements like a Pro: practical design patterns an...[meetup] Mastering Java enhancements like a Pro: practical design patterns an...
[meetup] Mastering Java enhancements like a Pro: practical design patterns an...
 
Spring fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
 
Oslo Program Overview, OpenStack Atlanta
Oslo Program Overview, OpenStack AtlantaOslo Program Overview, OpenStack Atlanta
Oslo Program Overview, OpenStack Atlanta
 

Recently uploaded

Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

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 lisachenko.it@gmail.com
  • 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