SlideShare uma empresa Scribd logo
1 de 34
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

Mais conteúdo relacionado

Mais procurados

AspectJ Android with Example
AspectJ Android with ExampleAspectJ Android with Example
AspectJ Android with Examplefirstthumb
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applicationseightbit
 
Architectural changes in Orion
Architectural changes in OrionArchitectural changes in Orion
Architectural changes in OrionTomas 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 Courseeightbit
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloudlennartkats
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional ProgrammingTjerk Wolterink
 
Robot framework - Lord of the Rings
Robot framework - Lord of the RingsRobot framework - Lord of the Rings
Robot framework - Lord of the RingsAsheesh 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 QueriesEdward 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 TypeclassesJordi Pradel
 
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
 
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 exampleJorge Sánchez
 
CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5CPAN Exporter modules for Perl 5
CPAN Exporter modules for Perl 5neilbowers
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show fileSaurabh 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 9Mike Feltman
 

Mais procurados (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
 

Destaque

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 PHPWilliam Candillon
 
AOP in Python API design
AOP in Python API designAOP in Python API design
AOP in Python API designmeij200
 
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! AOPAlexander Lisachenko
 
FED presentation
FED presentationFED presentation
FED presentationClausDue
 
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 AzureFrancesco 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 2015Meet 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 developmentMike Taylor
 

Destaque (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
 

Semelhante a 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
 
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 BonsaiIvo Andreev
 
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 ProgrammingMichael 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 8Heartin Jacob
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPrashant 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
 
[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 Atlantadoughellmann
 

Semelhante a 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
 

Último

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Último (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

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