SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Aspects of
Love
Aspects of
Love
Go Deep into the Rabbit Hole,
and Enter a Wonderland of
Possibilities with Aspect
Oriented Programming
Aspects of Love
Aspects of Love
What is AOP?
Aspect Oriented Programming
Aspects of Love
What is AOP?
Procedural Programming
Object Oriented Programming (OOP)
Functional Programming (FP)
Aspect Oriented Programming (AOP)
Aspects of Love
What is AOP?
Object Oriented Programming (OOP)
+
Aspect Oriented Programming (AOP)
Aspects of Love
Separation of Concerns
Business Logic
Aspects
Cross-Cutting Concerns
Aspects of Love
namespace AppHttpControllers;
use AppUser;
use AppHttpControllersController;
class UserController extends Controller
{
public function showProfile($id)
{
return view('user.profile', ['user' => User::findOrFail($id)]);
}
}
Route::get('user/{id}', 'UserController@showProfile');
Aspects of Love
But only Logged-
in Users should
be able to see
another User’s
Profile
Aspects of Love
class UserController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
...
}
Route::get('profile', 'UserController@showProfile')
->middleware('auth');
Aspects of Love
We need to log
every time that
somebody views
any User’s
Profile
Aspects of Love
Don’t forget that
we also want to
cache recently
accessed User
Profiles to improve
performance
Aspects of Love
And in the
functionality to
Edit a User’s
Profile, we need
an audit record
of all the changes
that were made
Except
passwords
(of course)
Aspects of Love
class UserController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware('log');
$this->middleware('audit')->only('edit');
$this->middleware('cache');
}
...
}
Aspects of Love
Aspects of Love
S O L I D
Aspects of Love
S O L I D
Aspects of Love
Cross-Cutting Concerns
Security Privilege Checks
Logging
Auditing
Caching
Transaction Management
Aspects of Love
Terminology
Aspect
Advice
Join Point
Pointcut
Advice Chain
Aspect Weaver
Aspects of Love
Terminology
Aspect
AOP Implementation
of a Cross-Cutting Concern
Aspects of Love
Terminology
Aspects apply an “Advice”
A specific behaviour
or piece of code logic
Aspects of Love
Terminology
Aspects apply Advices at “Join
Points”
Points within the Business
Logic
where the additional
behaviour
should be joined
Aspects of Love
Terminology
Join Points are identified by
“Pointcuts”
Expressions that identify one
or more
Join Points where an Advice
should be applied.
Aspects of Love
Terminology
An Advice Chain is a series of
Advices
that will all be applied to a
single
Join Point
Aspects of Love
Aspects of Love
namespace SystemAspect;
use GoAopAspect;
use GoAopInterceptMethodInvocation;
use GoLangAnnotationBefore;
class LoggingAspect implements Aspect
{
/**
* @Before("execution(public *UserController->showProfile(*))", order=-128)
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
Log::info(sprintf(
'Access to %s with arguments %s’,
$invocation,
json_encode($invocation->getArguments())
);
}
}
Aspects of Love
namespace SystemAspect;
use GoAopAspect;
use GoAopInterceptMethodInvocation;
use GoLangAnnotationBefore;
class LoggingAspect implements Aspect
{
/**
* @Before("execution(public *UserController->showProfile(*))", order=-128)
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
Log::info(sprintf(
'Access to %s with arguments %s’,
$invocation,
json_encode($invocation->getArguments())
);
}
}
Aspects of Love
namespace SystemAspect;
use GoAopAspect;
use GoAopInterceptMethodInvocation;
use GoLangAnnotationBefore;
class LoggingAspect implements Aspect
{
/**
* @Before("execution(public *UserController->showProfile(*))", order=-128)
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
Log::info(sprintf(
'Access to %s with arguments %s’,
$invocation,
json_encode($invocation->getArguments())
);
}
}
Aspects of Love
Aspects of Love
PointCuts
Methods
Public or Protected
Final or Static
Before
After
After Return
After Throw
Around
Aspects of Love
PointCuts
Properties
Public or Protected
Final or Static
Get
Set
Aspects of Love
PointCuts
Class Initialisation
System Functions (within namespaces)
Aspects of Love
Terminology
Aspect Weaver
Aspects of Love
Terminology
Aspect Weaver
The Code/Framework that
applies
Aspects to the appropriate
Join
Points in the Business
Logic
Aspects of Love
And that’s the Magic!
Aspects of Love
And that’s the Magic!
AOP allows us to do “stuff” before or
after a method call (or even override
it completely),
without modifying the original code!
Aspects of Love
But I don’t like Magic! ™
Aspects of Love
But the number of AOP
Libraries/frameworks that are
available suggests that some people
do like their magic
Aspects of Love
AOP Libraries/Extensions
AOP PECL Extension
PHP 5 (there is a PR for PHP 7, but
unmerged)
https://github.com/AOP-PHP/AOP
http://aop-php.github.io/
Aspects of Love
AOP Libraries/Extensions
JMS AOP Bundle
For Symfony 2+
http://jmsyst.com/bundles/JMSAopBundle
https://github.com/schmittjoh/JMSAopBu
ndle
Aspects of Love
AOP Libraries/Extensions
Lithium Framework
https://github.com/UnionOfRAD/lithium
Aspects of Love
AOP Libraries/Extensions
Ray.Aop
https://github.com/ray-di/Ray.Aop
Aspects of Love
AOP Libraries/Extensions
Kdyby/Aop
For the Nette Framework
https://github.com/Kdyby/Aop
Aspects of Love
AOP Libraries/Extensions
Swoft
Coroutine componentisation Framework,
based on swoole 2 native Coroutines
https://github.com/swoft-cloud/swoft
Aspects of Love
AOP Libraries/Extensions
Flow
Formerly Typo3 Flow, formerly Flow3
https://flow.neos.io/
Aspects of Love
AOP Libraries/Extensions
Go! AOP
https://github.com/goaop/framework
https://go-aop-php.readthedocs.io/
Aspects of Love
Go! AOP framework
Symfony Bundle:
https://github.com/goaop/goaop-symfony-bundle
Laravel bridge:
https://github.com/goaop/goaop-laravel-bridge
Zend 2 module:
https://github.com/goaop/goaop-zf2-module
IDEA plugin (PHPStorm, IntelliJ):
https://github.com/goaop/idea-plugin
Aspects of Love
Go! AOP – How does the magic work?
Aspects of Love
But I don’t like Magic! ™
Aspects of Love
Clarke’s third law
“Any sufficiently advanced technology is
indistinguishable from magic.”
Arthur C. Clarke, “Profiles of The Future”, 1961
Aspects of Love
Go! AOP – How does the magic work?
Wraps the Composer loader with its own proxy
Intercepts calls to load a class file, and
applies its own stream filter to read the file
without actually “loading” it
Tokenises and parses the file to an AST (using
the nikic/PHP-Parser library), and applies
static reflection
Aspects of Love
Go! AOP – How does the magic work?
Checks all registered pointcuts and transforms
the original class code, renaming it as
<class>_AopProxied
Creates its own version of the original class
file, with the additional logic from the
relevant Advices, extending <class>_AopProxied,
and stores that new file in the cache folder
Aspects of Love
Go! AOP – How does the magic work?
Directs the autoloader to load the new file from
the cache folder
Autoloader will subsequently load
<class>_AopProxied as well, because the new
version of the class extends that, but no
further transformation is required
Aspects of Love
So they all lived
happily ever after…
Aspects of Love
So they all lived
happily ever after…
Well, not necessarily…
Aspects of Love
Potential Problems with AOP
Aspects of Love
Potential Problems with AOP
Generic Advices
Non-Obvious Aspects
Fragile Pointcuts
Lack of Visibility
Difficult to Debug
Aspects of Love
Potential Problems with AOP
Aspects of Love
Potential Benefits with AOP
Aspects of Love
Potential Benefits with AOP
Separation of Concerns
Separate Unit Tests for Business Logic
and for Aspects
Simplifies Unit Testing for Business
Logic
No need to mock Aspect Objects
like Loggers
Aspects of Love
Potential Benefits with AOP
Aspects of Love
Libraries Using AOP
AspectMock
https://github.com/Codeception/AspectMock
Roave/StrictPHP
https://github.com/Roave/StrictPhp
PHPDeal (Design by Contract)
https://github.com/php-deal/framework
Aspects of Love
Alternatives to AOP
Events
Aspects of Love
The Future?
Composite Oriented Programming
https://www.infoq.com/articles/Composite-Programming-
Qi4j
Aspect Oriented Programming
Dependency Injection
Domain-Driven Design
Aspects of Love
The Future?
Apache Polygene
https://polygene.apache.org/
Behavior Depends on Context
Decoupling is a Virtue
Business Rules (and Domain Model) matters
more
Classes are Dead, Long Live Interfaces
Aspects of Love
Are you ready to start
exploring the magic of
Wonderland?
Aspects of Love
All Images are
from the
Alice Tarot deck
published by
Baba Studios
© Karen Mahony
&
Baba Studios
Used with
permission

Weitere ähnliche Inhalte

Was ist angesagt?

java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasGanesh Samarthyam
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features OverviewSergii Stets
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
Java 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJava 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJosé Paumard
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Harmeet Singh(Taara)
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 

Was ist angesagt? (20)

Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Functional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting LambdasFunctional Programming in Java 8 - Exploiting Lambdas
Functional Programming in Java 8 - Exploiting Lambdas
 
Java8
Java8Java8
Java8
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
 
Java 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJava 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java Comparison
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
 

Ähnlich wie Aspects of love slideshare

Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application FrameworkJady Yang
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?Oliver Gierke
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsSolution4Future
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
Code transformation With Spoon
Code transformation With SpoonCode transformation With Spoon
Code transformation With SpoonGérard Paligot
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPStephan Schmidt
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPstubbles
 
From polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchFrom polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchSergi González Pérez
 
EvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge Bases
EvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge BasesEvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge Bases
EvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge BasesSebastian Tramp
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial BasicsLuca Garulli
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
070517 Jena
070517 Jena070517 Jena
070517 Jenayuhana
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express jsAhmed Assaf
 

Ähnlich wie Aspects of love slideshare (20)

Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
Apache Persistence Layers
Apache Persistence LayersApache Persistence Layers
Apache Persistence Layers
 
Code transformation With Spoon
Code transformation With SpoonCode transformation With Spoon
Code transformation With Spoon
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHP
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHP
 
From polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchFrom polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratch
 
EvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge Bases
EvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge BasesEvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge Bases
EvoPat - Pattern-Based Evolution and Refactoring of RDF Knowledge Bases
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
070517 Jena
070517 Jena070517 Jena
070517 Jena
 
Ext 0523
Ext 0523Ext 0523
Ext 0523
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 

Mehr von Mark Baker

Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to ProductionMark Baker
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to ProductionMark Baker
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to ProductionMark Baker
 
A Brief History of Elephpants
A Brief History of ElephpantsA Brief History of Elephpants
A Brief History of ElephpantsMark Baker
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Mark Baker
 
A Brief History of ElePHPants
A Brief History of ElePHPantsA Brief History of ElePHPants
A Brief History of ElePHPantsMark Baker
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding HorrorsMark Baker
 
Anonymous classes2
Anonymous classes2Anonymous classes2
Anonymous classes2Mark Baker
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the UntestableMark Baker
 
Anonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskAnonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskMark Baker
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Mark Baker
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding HorrorsMark Baker
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Mark Baker
 
Giving birth to an ElePHPant
Giving birth to an ElePHPantGiving birth to an ElePHPant
Giving birth to an ElePHPantMark Baker
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015Mark Baker
 

Mehr von Mark Baker (20)

Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
A Brief History of Elephpants
A Brief History of ElephpantsA Brief History of Elephpants
A Brief History of Elephpants
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?
 
A Brief History of ElePHPants
A Brief History of ElePHPantsA Brief History of ElePHPants
A Brief History of ElePHPants
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
Anonymous classes2
Anonymous classes2Anonymous classes2
Anonymous classes2
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the Untestable
 
Anonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskAnonymous Classes: Behind the Mask
Anonymous Classes: Behind the Mask
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?
 
Giving birth to an ElePHPant
Giving birth to an ElePHPantGiving birth to an ElePHPant
Giving birth to an ElePHPant
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015
 

Kürzlich hochgeladen

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 

Kürzlich hochgeladen (20)

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 

Aspects of love slideshare

  • 2. Aspects of Love Go Deep into the Rabbit Hole, and Enter a Wonderland of Possibilities with Aspect Oriented Programming
  • 4. Aspects of Love What is AOP? Aspect Oriented Programming
  • 5. Aspects of Love What is AOP? Procedural Programming Object Oriented Programming (OOP) Functional Programming (FP) Aspect Oriented Programming (AOP)
  • 6. Aspects of Love What is AOP? Object Oriented Programming (OOP) + Aspect Oriented Programming (AOP)
  • 7. Aspects of Love Separation of Concerns Business Logic Aspects Cross-Cutting Concerns
  • 8. Aspects of Love namespace AppHttpControllers; use AppUser; use AppHttpControllersController; class UserController extends Controller { public function showProfile($id) { return view('user.profile', ['user' => User::findOrFail($id)]); } } Route::get('user/{id}', 'UserController@showProfile');
  • 9. Aspects of Love But only Logged- in Users should be able to see another User’s Profile
  • 10. Aspects of Love class UserController extends Controller { public function __construct() { $this->middleware('auth'); } ... } Route::get('profile', 'UserController@showProfile') ->middleware('auth');
  • 11. Aspects of Love We need to log every time that somebody views any User’s Profile
  • 12. Aspects of Love Don’t forget that we also want to cache recently accessed User Profiles to improve performance
  • 13. Aspects of Love And in the functionality to Edit a User’s Profile, we need an audit record of all the changes that were made Except passwords (of course)
  • 14. Aspects of Love class UserController extends Controller { public function __construct() { $this->middleware('auth'); $this->middleware('log'); $this->middleware('audit')->only('edit'); $this->middleware('cache'); } ... }
  • 16. Aspects of Love S O L I D
  • 17. Aspects of Love S O L I D
  • 18. Aspects of Love Cross-Cutting Concerns Security Privilege Checks Logging Auditing Caching Transaction Management
  • 19. Aspects of Love Terminology Aspect Advice Join Point Pointcut Advice Chain Aspect Weaver
  • 20. Aspects of Love Terminology Aspect AOP Implementation of a Cross-Cutting Concern
  • 21. Aspects of Love Terminology Aspects apply an “Advice” A specific behaviour or piece of code logic
  • 22. Aspects of Love Terminology Aspects apply Advices at “Join Points” Points within the Business Logic where the additional behaviour should be joined
  • 23. Aspects of Love Terminology Join Points are identified by “Pointcuts” Expressions that identify one or more Join Points where an Advice should be applied.
  • 24. Aspects of Love Terminology An Advice Chain is a series of Advices that will all be applied to a single Join Point
  • 26. Aspects of Love namespace SystemAspect; use GoAopAspect; use GoAopInterceptMethodInvocation; use GoLangAnnotationBefore; class LoggingAspect implements Aspect { /** * @Before("execution(public *UserController->showProfile(*))", order=-128) */ public function beforeMethodExecution(MethodInvocation $invocation) { Log::info(sprintf( 'Access to %s with arguments %s’, $invocation, json_encode($invocation->getArguments()) ); } }
  • 27. Aspects of Love namespace SystemAspect; use GoAopAspect; use GoAopInterceptMethodInvocation; use GoLangAnnotationBefore; class LoggingAspect implements Aspect { /** * @Before("execution(public *UserController->showProfile(*))", order=-128) */ public function beforeMethodExecution(MethodInvocation $invocation) { Log::info(sprintf( 'Access to %s with arguments %s’, $invocation, json_encode($invocation->getArguments()) ); } }
  • 28. Aspects of Love namespace SystemAspect; use GoAopAspect; use GoAopInterceptMethodInvocation; use GoLangAnnotationBefore; class LoggingAspect implements Aspect { /** * @Before("execution(public *UserController->showProfile(*))", order=-128) */ public function beforeMethodExecution(MethodInvocation $invocation) { Log::info(sprintf( 'Access to %s with arguments %s’, $invocation, json_encode($invocation->getArguments()) ); } }
  • 30. Aspects of Love PointCuts Methods Public or Protected Final or Static Before After After Return After Throw Around
  • 31. Aspects of Love PointCuts Properties Public or Protected Final or Static Get Set
  • 32. Aspects of Love PointCuts Class Initialisation System Functions (within namespaces)
  • 34. Aspects of Love Terminology Aspect Weaver The Code/Framework that applies Aspects to the appropriate Join Points in the Business Logic
  • 35. Aspects of Love And that’s the Magic!
  • 36. Aspects of Love And that’s the Magic! AOP allows us to do “stuff” before or after a method call (or even override it completely), without modifying the original code!
  • 37. Aspects of Love But I don’t like Magic! ™
  • 38. Aspects of Love But the number of AOP Libraries/frameworks that are available suggests that some people do like their magic
  • 39. Aspects of Love AOP Libraries/Extensions AOP PECL Extension PHP 5 (there is a PR for PHP 7, but unmerged) https://github.com/AOP-PHP/AOP http://aop-php.github.io/
  • 40. Aspects of Love AOP Libraries/Extensions JMS AOP Bundle For Symfony 2+ http://jmsyst.com/bundles/JMSAopBundle https://github.com/schmittjoh/JMSAopBu ndle
  • 41. Aspects of Love AOP Libraries/Extensions Lithium Framework https://github.com/UnionOfRAD/lithium
  • 42. Aspects of Love AOP Libraries/Extensions Ray.Aop https://github.com/ray-di/Ray.Aop
  • 43. Aspects of Love AOP Libraries/Extensions Kdyby/Aop For the Nette Framework https://github.com/Kdyby/Aop
  • 44. Aspects of Love AOP Libraries/Extensions Swoft Coroutine componentisation Framework, based on swoole 2 native Coroutines https://github.com/swoft-cloud/swoft
  • 45. Aspects of Love AOP Libraries/Extensions Flow Formerly Typo3 Flow, formerly Flow3 https://flow.neos.io/
  • 46. Aspects of Love AOP Libraries/Extensions Go! AOP https://github.com/goaop/framework https://go-aop-php.readthedocs.io/
  • 47. Aspects of Love Go! AOP framework Symfony Bundle: https://github.com/goaop/goaop-symfony-bundle Laravel bridge: https://github.com/goaop/goaop-laravel-bridge Zend 2 module: https://github.com/goaop/goaop-zf2-module IDEA plugin (PHPStorm, IntelliJ): https://github.com/goaop/idea-plugin
  • 48. Aspects of Love Go! AOP – How does the magic work?
  • 49. Aspects of Love But I don’t like Magic! ™
  • 50. Aspects of Love Clarke’s third law “Any sufficiently advanced technology is indistinguishable from magic.” Arthur C. Clarke, “Profiles of The Future”, 1961
  • 51. Aspects of Love Go! AOP – How does the magic work? Wraps the Composer loader with its own proxy Intercepts calls to load a class file, and applies its own stream filter to read the file without actually “loading” it Tokenises and parses the file to an AST (using the nikic/PHP-Parser library), and applies static reflection
  • 52. Aspects of Love Go! AOP – How does the magic work? Checks all registered pointcuts and transforms the original class code, renaming it as <class>_AopProxied Creates its own version of the original class file, with the additional logic from the relevant Advices, extending <class>_AopProxied, and stores that new file in the cache folder
  • 53. Aspects of Love Go! AOP – How does the magic work? Directs the autoloader to load the new file from the cache folder Autoloader will subsequently load <class>_AopProxied as well, because the new version of the class extends that, but no further transformation is required
  • 54. Aspects of Love So they all lived happily ever after…
  • 55. Aspects of Love So they all lived happily ever after… Well, not necessarily…
  • 56. Aspects of Love Potential Problems with AOP
  • 57. Aspects of Love Potential Problems with AOP Generic Advices Non-Obvious Aspects Fragile Pointcuts Lack of Visibility Difficult to Debug
  • 58. Aspects of Love Potential Problems with AOP
  • 59. Aspects of Love Potential Benefits with AOP
  • 60. Aspects of Love Potential Benefits with AOP Separation of Concerns Separate Unit Tests for Business Logic and for Aspects Simplifies Unit Testing for Business Logic No need to mock Aspect Objects like Loggers
  • 61. Aspects of Love Potential Benefits with AOP
  • 62. Aspects of Love Libraries Using AOP AspectMock https://github.com/Codeception/AspectMock Roave/StrictPHP https://github.com/Roave/StrictPhp PHPDeal (Design by Contract) https://github.com/php-deal/framework
  • 64. Aspects of Love The Future? Composite Oriented Programming https://www.infoq.com/articles/Composite-Programming- Qi4j Aspect Oriented Programming Dependency Injection Domain-Driven Design
  • 65. Aspects of Love The Future? Apache Polygene https://polygene.apache.org/ Behavior Depends on Context Decoupling is a Virtue Business Rules (and Domain Model) matters more Classes are Dead, Long Live Interfaces
  • 66. Aspects of Love Are you ready to start exploring the magic of Wonderland?
  • 67. Aspects of Love All Images are from the Alice Tarot deck published by Baba Studios © Karen Mahony & Baba Studios Used with permission