SlideShare a Scribd company logo
USING THE SYMFONY2 COMPONENTS 
FOR PAINLESS INTEGRATION 
C I A R A N M C N U L T Y 
L I G H T N I N G T A L K S S E S S I O N 1
DRUPAL + SYMFONY
”SYMFONY2 IS A REUSABLE SET OF STANDALONE, 
DECOUPLED, AND COHESIVE PHP COMPONENTS 
THAT SOLVE COMMON WEB DEVELOPMENT 
PROBLEMS.” 
– F A B I E N P O T E N C I E R , 2 0 1 1
SYMFONY2 ADOPTION 
http://zalas.eu/symfony2-adoption/
SYMFONY2 ADOPTION 
Driven by Components 
Out of 4994 packages that depend on Symfony: 
! 
1911 depend on the symfony/framework-bundle, 
! 
1985 depend on specific components, 
! 
1098 depend on symfony/symfony. 
http://zalas.eu/symfony2-adoption/
SYMFONY2 ADOPTION 
SHARED COMPONENTS 
! 
= 
! 
INTEROPERABILITY
HTTPFOUNDATION 
+ 
HTTPKERNEL
REQUEST/RESPONSE MODEL 
HTTP REQUEST HTTP RESPONSE 
APPLICATION
REQUEST/RESPONSE MODEL 
HTTP REQUEST HTTP RESPONSE 
APPLICATION 
Request Object Response Object 
SymfonyComponentHttpFoundationRequest SymfonyComponentHttpFoundationResponse
REQUEST/RESPONSE MODEL 
HTTP REQUEST HTTP RESPONSE 
APPLICATION 
Request Object Response Object 
SymfonyComponentHttpFoundationRequest SymfonyComponentHttpFoundationResponse 
Kernel Interface 
SymfonyComponentHttpKernelHttpKernelInterface
KERNEL INTERFACE 
interface HttpKernelInterface 
{ 
const MASTER_REQUEST = 1; 
const SUB_REQUEST = 2; 
! 
/** 
* @return Response 
*/ 
public function handle( 
Request $request, 
$type = self::MASTER_REQUEST, 
$catch = true 
); 
}
SYMFONY FRAMEWORK USAGE 
$kernel = new AppKernel('prod', false); 
$kernel->loadClassCache(); 
! 
$request = Request::createFromGlobals(); 
! 
$response = $kernel->handle($request); 
! 
$response->send();
DRUPAL 8 USAGE 
$request = Request::createFromGlobals(); 
! 
$kernel = DrupalKernel::createFromRequest( 
$request, 
$autoloader, 
‘prod' 
); 
! 
$response = $kernel->handle($request); 
! 
$response->send();
HTTPKERNEL USAGE
WHAT IS THE 
BENEFIT?
SYMFONY2 PAGE CACHING 
$kernel = new AppKernel('prod', false); 
$kernel->loadClassCache(); 
! 
$kernel = new AppCache($kernel); 
! 
$request = Request::createFromGlobals(); 
! 
$response = $kernel->handle($request); 
! 
$response->send();
“Symfony's HttpKernelInterface provides a solid interface, which 
makes creating and sharing framework-agnostic HTTP filters a breeze”
WRITING A MIDDLEWARE 
class DrupalConPromoter implements HttpKernelInterface 
{ 
private $innerKernel; 
! 
public function __construct(HttpKernelInterface $kernel) 
{ 
$this->innerKernel = $kernel; 
} 
! 
public function handle( 
Request $request, 
$type = HttpKernelInterface::MASTER_REQUEST, $catch = true 
) 
{ 
$response = $this->innerKernel->handle($request, $type, $catch); 
$newContent = str_replace( 
'<body>', '<body><h1>DRUPALCON ROCKS</h1>', 
$response->getContents()); 
$response->setContents($newContent); 
! 
return $response; 
} 
}
USING OUR OWN MIDDLEWARE 
$kernel = new AppKernel('prod', false); 
$kernel->loadClassCache(); 
$kernel = new AppCache($kernel); 
! 
$kernel = new DrupalConPromoter($kernel); 
! 
$request = Request::createFromGlobals(); 
! 
$response = $kernel->handle($request); 
! 
$response->send();
AVAILABLE MIDDLEWARES 
CookieGuard - Encrypts/decrypts cookies 
! 
GeoIP - Looks up country from IP and adds to Request 
! 
CORS - Adds CORS headers 
! 
Negotiation - Works out what content-type to send client 
! 
IpRestrict - block blacklisted IP Requests 
! 
Backstage - displays maintenance page if one exists 
! 
+ plenty more!
USING IN DRUPAL 
Problem: 
’Edit index.php’ is not something a typical Drupal 
developer is happy with 
! 
Solution: 
Middlewares are registered via the Service Container 
(another Symfony component) 
<service id=“my_drupalcon_promoter” 
class=“DrupalConPromoter”>" 
" <tag name=“http_middleware” priority=“1” />" 
</service>
RUNNING MULTIPLE KERNELS 
! 
$request = Request::createFromGlobals(); 
! 
$symfonyKernel = new AppKernel('prod', false); 
$symfonyKernel->loadClassCache(); 
! 
$drupalKernel = DrupalKernel::createFromRequest( 
$request, 
$autoloader, 
'prod' 
); 
! 
$kernel = UrlMap( 
$drupalKernel, 
['/blog' => $symfonyKernel] 
); 
! 
$response = $kernel->handle($request); 
$response->send();
CIARAN MCNULTY 
! 
@ciaranmcnulty 
! 
Core contributor to PhpSpec 
! 
BDD / Agile / DDD enthusiast 
! 
Senior Trainer at Inviqa Group
See us on stand 309
WHAT DID YOU THINK? 
E V A U L A T E T H I S S E S S I O N - A M S T E R D A M 2 0 1 4 . D R U P A L . O R G / S C H E D U L E 
THANK YOU!
Ad

More Related Content

What's hot (20)

RESTful web services
RESTful web servicesRESTful web services
RESTful web services
Tudor Constantin
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
bpmedley
 
Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
Alexey Popravka
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
Chris Tankersley
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
Bobby Bouwmann
 
Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
Ryan Szrama
 
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with DistilleryYaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Elixir Club
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an API
chrisdkemper
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
Marcus Ramberg
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
Anatoly Sharifulin
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
Areski Belaid
 
Start developing Facebook apps in 13 steps
Start developing Facebook apps in 13 stepsStart developing Facebook apps in 13 steps
Start developing Facebook apps in 13 steps
Masakuni Kato
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2
Vikas Chauhan
 
Php Training Workshop by Vtips
Php Training Workshop by VtipsPhp Training Workshop by Vtips
Php Training Workshop by Vtips
Vidya Topa Institute of Professional Studies
 
Confluent kafka on docker
Confluent kafka on dockerConfluent kafka on docker
Confluent kafka on docker
Sunil kumar Mohanty
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Yusuke Wada
 
Perl gui
Perl guiPerl gui
Perl gui
umnix
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with ease
Oscar Merida
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
 
Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5
Oleg Poludnenko
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
bpmedley
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
Bobby Bouwmann
 
Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
Ryan Szrama
 
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with DistilleryYaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Elixir Club
 
Silex: From nothing to an API
Silex: From nothing to an APISilex: From nothing to an API
Silex: From nothing to an API
chrisdkemper
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
Marcus Ramberg
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
Anatoly Sharifulin
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
Areski Belaid
 
Start developing Facebook apps in 13 steps
Start developing Facebook apps in 13 stepsStart developing Facebook apps in 13 steps
Start developing Facebook apps in 13 steps
Masakuni Kato
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2
Vikas Chauhan
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Yusuke Wada
 
Perl gui
Perl guiPerl gui
Perl gui
umnix
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with ease
Oscar Merida
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
 
Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5
Oleg Poludnenko
 

Similar to Using HttpKernelInterface for Painless Integration (20)

Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
Fabien Potencier
 
Symfony 2 (PHP day 2009)
Symfony 2 (PHP day 2009)Symfony 2 (PHP day 2009)
Symfony 2 (PHP day 2009)
Fabien Potencier
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
GrUSP
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard Developers
Henri Bergius
 
Creating a modern web application using Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform AtlantaCreating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using Symfony API Platform Atlanta
Jesus Manuel Olivas
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Kacper Gunia
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
Deepak Chandani
 
Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
Fabien Potencier
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
Fabien Potencier
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
Fabien Potencier
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
Ryan Weaver
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
Hugo Hamon
 
Symfony 4 & Flex news
Symfony 4 & Flex newsSymfony 4 & Flex news
Symfony 4 & Flex news
🌘 Alex Rock
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to Laravel
Jason McCreary
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
Javier Eguiluz
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
Achieve Internet
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
Eyal Vardi
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
chartjes
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
Fabien Potencier
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
GrUSP
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard Developers
Henri Bergius
 
Creating a modern web application using Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform AtlantaCreating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using Symfony API Platform Atlanta
Jesus Manuel Olivas
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Kacper Gunia
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
Deepak Chandani
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
Fabien Potencier
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
Ryan Weaver
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
Hugo Hamon
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to Laravel
Jason McCreary
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
Javier Eguiluz
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
Achieve Internet
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
Eyal Vardi
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
chartjes
 
Ad

More from CiaranMcNulty (20)

Greener web development at PHP London
Greener web development at PHP LondonGreener web development at PHP London
Greener web development at PHP London
CiaranMcNulty
 
Doodle Driven Development
Doodle Driven DevelopmentDoodle Driven Development
Doodle Driven Development
CiaranMcNulty
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
CiaranMcNulty
 
Behat Best Practices
Behat Best PracticesBehat Best Practices
Behat Best Practices
CiaranMcNulty
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
CiaranMcNulty
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
CiaranMcNulty
 
Modelling by Example Workshop - PHPNW 2016
Modelling by Example Workshop - PHPNW 2016Modelling by Example Workshop - PHPNW 2016
Modelling by Example Workshop - PHPNW 2016
CiaranMcNulty
 
Conscious Coupling
Conscious CouplingConscious Coupling
Conscious Coupling
CiaranMcNulty
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
CiaranMcNulty
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the Job
CiaranMcNulty
 
Conscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHPConscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHP
CiaranMcNulty
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
CiaranMcNulty
 
Fly In Style (without splashing out)
Fly In Style (without splashing out)Fly In Style (without splashing out)
Fly In Style (without splashing out)
CiaranMcNulty
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
CiaranMcNulty
 
Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015
CiaranMcNulty
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
CiaranMcNulty
 
TDD with PhpSpec
TDD with PhpSpecTDD with PhpSpec
TDD with PhpSpec
CiaranMcNulty
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
CiaranMcNulty
 
Why Your Test Suite Sucks
Why Your Test Suite SucksWhy Your Test Suite Sucks
Why Your Test Suite Sucks
CiaranMcNulty
 
Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpec
CiaranMcNulty
 
Greener web development at PHP London
Greener web development at PHP LondonGreener web development at PHP London
Greener web development at PHP London
CiaranMcNulty
 
Doodle Driven Development
Doodle Driven DevelopmentDoodle Driven Development
Doodle Driven Development
CiaranMcNulty
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
CiaranMcNulty
 
Behat Best Practices
Behat Best PracticesBehat Best Practices
Behat Best Practices
CiaranMcNulty
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
CiaranMcNulty
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
CiaranMcNulty
 
Modelling by Example Workshop - PHPNW 2016
Modelling by Example Workshop - PHPNW 2016Modelling by Example Workshop - PHPNW 2016
Modelling by Example Workshop - PHPNW 2016
CiaranMcNulty
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
CiaranMcNulty
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the Job
CiaranMcNulty
 
Conscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHPConscious Decoupling - Lone Star PHP
Conscious Decoupling - Lone Star PHP
CiaranMcNulty
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
CiaranMcNulty
 
Fly In Style (without splashing out)
Fly In Style (without splashing out)Fly In Style (without splashing out)
Fly In Style (without splashing out)
CiaranMcNulty
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
CiaranMcNulty
 
Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015
CiaranMcNulty
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
CiaranMcNulty
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
CiaranMcNulty
 
Why Your Test Suite Sucks
Why Your Test Suite SucksWhy Your Test Suite Sucks
Why Your Test Suite Sucks
CiaranMcNulty
 
Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpec
CiaranMcNulty
 
Ad

Recently uploaded (20)

Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Top 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing ServicesTop 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing Services
Infrassist Technologies Pvt. Ltd.
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 

Using HttpKernelInterface for Painless Integration

  • 1. USING THE SYMFONY2 COMPONENTS FOR PAINLESS INTEGRATION C I A R A N M C N U L T Y L I G H T N I N G T A L K S S E S S I O N 1
  • 3. ”SYMFONY2 IS A REUSABLE SET OF STANDALONE, DECOUPLED, AND COHESIVE PHP COMPONENTS THAT SOLVE COMMON WEB DEVELOPMENT PROBLEMS.” – F A B I E N P O T E N C I E R , 2 0 1 1
  • 5. SYMFONY2 ADOPTION Driven by Components Out of 4994 packages that depend on Symfony: ! 1911 depend on the symfony/framework-bundle, ! 1985 depend on specific components, ! 1098 depend on symfony/symfony. http://zalas.eu/symfony2-adoption/
  • 6. SYMFONY2 ADOPTION SHARED COMPONENTS ! = ! INTEROPERABILITY
  • 8. REQUEST/RESPONSE MODEL HTTP REQUEST HTTP RESPONSE APPLICATION
  • 9. REQUEST/RESPONSE MODEL HTTP REQUEST HTTP RESPONSE APPLICATION Request Object Response Object SymfonyComponentHttpFoundationRequest SymfonyComponentHttpFoundationResponse
  • 10. REQUEST/RESPONSE MODEL HTTP REQUEST HTTP RESPONSE APPLICATION Request Object Response Object SymfonyComponentHttpFoundationRequest SymfonyComponentHttpFoundationResponse Kernel Interface SymfonyComponentHttpKernelHttpKernelInterface
  • 11. KERNEL INTERFACE interface HttpKernelInterface { const MASTER_REQUEST = 1; const SUB_REQUEST = 2; ! /** * @return Response */ public function handle( Request $request, $type = self::MASTER_REQUEST, $catch = true ); }
  • 12. SYMFONY FRAMEWORK USAGE $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); ! $request = Request::createFromGlobals(); ! $response = $kernel->handle($request); ! $response->send();
  • 13. DRUPAL 8 USAGE $request = Request::createFromGlobals(); ! $kernel = DrupalKernel::createFromRequest( $request, $autoloader, ‘prod' ); ! $response = $kernel->handle($request); ! $response->send();
  • 15. WHAT IS THE BENEFIT?
  • 16. SYMFONY2 PAGE CACHING $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); ! $kernel = new AppCache($kernel); ! $request = Request::createFromGlobals(); ! $response = $kernel->handle($request); ! $response->send();
  • 17. “Symfony's HttpKernelInterface provides a solid interface, which makes creating and sharing framework-agnostic HTTP filters a breeze”
  • 18. WRITING A MIDDLEWARE class DrupalConPromoter implements HttpKernelInterface { private $innerKernel; ! public function __construct(HttpKernelInterface $kernel) { $this->innerKernel = $kernel; } ! public function handle( Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true ) { $response = $this->innerKernel->handle($request, $type, $catch); $newContent = str_replace( '<body>', '<body><h1>DRUPALCON ROCKS</h1>', $response->getContents()); $response->setContents($newContent); ! return $response; } }
  • 19. USING OUR OWN MIDDLEWARE $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); $kernel = new AppCache($kernel); ! $kernel = new DrupalConPromoter($kernel); ! $request = Request::createFromGlobals(); ! $response = $kernel->handle($request); ! $response->send();
  • 20. AVAILABLE MIDDLEWARES CookieGuard - Encrypts/decrypts cookies ! GeoIP - Looks up country from IP and adds to Request ! CORS - Adds CORS headers ! Negotiation - Works out what content-type to send client ! IpRestrict - block blacklisted IP Requests ! Backstage - displays maintenance page if one exists ! + plenty more!
  • 21. USING IN DRUPAL Problem: ’Edit index.php’ is not something a typical Drupal developer is happy with ! Solution: Middlewares are registered via the Service Container (another Symfony component) <service id=“my_drupalcon_promoter” class=“DrupalConPromoter”>" " <tag name=“http_middleware” priority=“1” />" </service>
  • 22. RUNNING MULTIPLE KERNELS ! $request = Request::createFromGlobals(); ! $symfonyKernel = new AppKernel('prod', false); $symfonyKernel->loadClassCache(); ! $drupalKernel = DrupalKernel::createFromRequest( $request, $autoloader, 'prod' ); ! $kernel = UrlMap( $drupalKernel, ['/blog' => $symfonyKernel] ); ! $response = $kernel->handle($request); $response->send();
  • 23. CIARAN MCNULTY ! @ciaranmcnulty ! Core contributor to PhpSpec ! BDD / Agile / DDD enthusiast ! Senior Trainer at Inviqa Group
  • 24. See us on stand 309
  • 25. WHAT DID YOU THINK? E V A U L A T E T H I S S E S S I O N - A M S T E R D A M 2 0 1 4 . D R U P A L . O R G / S C H E D U L E THANK YOU!