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 Cloud
lennartkats
 
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 development
lennartkats
 
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
 
Spring framework aop
Spring framework aopSpring framework aop
Spring framework aop
Taemon Piya-Lumyong
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
Fabien Potencier
 
Внедрение аспектов в 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
 
Go nuts with Go and PHP
Go nuts with Go and PHPGo nuts with Go and PHP
Go nuts with Go and PHP
Mariano Iglesias
 
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 AOP
cteguh
 
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 Bytecode
Yoav Avrahami
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratch
tutorialsruby
 
symfony_from_scratch
symfony_from_scratchsymfony_from_scratch
symfony_from_scratch
tutorialsruby
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
Vinay H G
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger 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 MV
Sway Wang
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger 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 Spring
Sujit Kumar
 
2012 S&P Paper Reading Session1
2012 S&P Paper Reading Session12012 S&P Paper Reading Session1
2012 S&P Paper Reading Session1
Chong-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
 
Spring fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
Santosh Gokak
 
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

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
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
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 

Recently uploaded (20)

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
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 ...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 

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