SlideShare a Scribd company logo
1 of 82
Silex, the micro-framework
@blongden
symfony/http-foundation
symfony/event-dispatcher
symfony/routing
symfony/http-kernel
pimple/pimple
Why Silex?
alias getcomposer='curl -s https://getcomposer.org/installer | php'
alias composer='php composer.phar'
Routes
Method, Pattern & Closure
Dynamic Routes
Converting Parameters
Route Assertions
Providers
• Service Providers
• Controller Providers
•   DoctrineServiceProvider

•   MonologServiceProvider

•   SessionServiceProvider

•   SwiftmailerServiceProvider

•   TwigServiceProvider

•   TranslationServiceProvider

•   UrlGeneratorServiceProvider

•   ValidatorServiceProvider

•   HttpCacheServiceProvider

•   FormServiceProvider

•   SecurityServiceProvider
Twig Templates
Traits
Forms
Handling POST
UrlGeneratorServiceProvider
View the guestbook
Http Cache
Edge Side Includes
<esi:include src=”/message” />
https://github.com/blongden/silex-guestbook
https://joind.in/6948
wallcoo.net
                   http://www.flickr.com/photos/8ballofwakefield/513907976/
           http://weblogs.wxmi.com/news/traffic/dirty-windshield/Highway%20signs.JPG
                             http://plaza.ufl.edu/dianis/images/dna.jpg
http://4.bp.blogspot.com/-ucuY9INjqrI/TajciAM3V_I/AAAAAAAAClY/EgdsT_i01Jg/s1600/P1040125.JPG
              http://www.greatgiddingschool.co.uk/wpimages/wpa87715ae_05_06.jpg
        http://upload.wikimedia.org/wikipedia/commons/5/5b/Cache_Memory-jurvetson.jpg
             http://img1.etsystatic.com/003/0/6263865/il_fullxfull.361156505_ghgv.jpg

More Related Content

What's hot

Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 

What's hot (20)

Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Don't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaDon't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and Joomla
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Building RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ Grape
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Ruby On Grape
Ruby On GrapeRuby On Grape
Ruby On Grape
 
Building Cloud Castles - LRUG
Building Cloud Castles - LRUGBuilding Cloud Castles - LRUG
Building Cloud Castles - LRUG
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
 

Similar to Silex, the microframework

Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
Satish b
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
Phil Windley
 

Similar to Silex, the microframework (20)

Hack & Fix, Hands on ColdFusion Security Training
Hack & Fix, Hands on ColdFusion Security TrainingHack & Fix, Hands on ColdFusion Security Training
Hack & Fix, Hands on ColdFusion Security Training
 
(STG205) Secure Content Delivery Using Amazon CloudFront
(STG205) Secure Content Delivery Using Amazon CloudFront(STG205) Secure Content Delivery Using Amazon CloudFront
(STG205) Secure Content Delivery Using Amazon CloudFront
 
Presentation Magento OroCRM - MageConf 2014
Presentation Magento OroCRM - MageConf 2014Presentation Magento OroCRM - MageConf 2014
Presentation Magento OroCRM - MageConf 2014
 
FIWARE Wednesday Webinars - How to Secure IoT Devices
FIWARE Wednesday Webinars - How to Secure IoT DevicesFIWARE Wednesday Webinars - How to Secure IoT Devices
FIWARE Wednesday Webinars - How to Secure IoT Devices
 
Secure Content Delivery Using Amazon CloudFront and AWS WAF
Secure Content Delivery Using Amazon CloudFront and AWS WAFSecure Content Delivery Using Amazon CloudFront and AWS WAF
Secure Content Delivery Using Amazon CloudFront and AWS WAF
 
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
Understanding Identity in the World of Web APIs – Ronnie Mitra,  API Architec...Understanding Identity in the World of Web APIs – Ronnie Mitra,  API Architec...
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
 
Integrating Alfresco with Portals
Integrating Alfresco with PortalsIntegrating Alfresco with Portals
Integrating Alfresco with Portals
 
Testing in the 21st Century (ExpoQA)
Testing in the 21st Century (ExpoQA)Testing in the 21st Century (ExpoQA)
Testing in the 21st Century (ExpoQA)
 
Symfony demonstration
Symfony demonstrationSymfony demonstration
Symfony demonstration
 
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
 
DEF CON 24 - workshop - Craig Young - brainwashing embedded systems
DEF CON 24 - workshop - Craig Young - brainwashing embedded systemsDEF CON 24 - workshop - Craig Young - brainwashing embedded systems
DEF CON 24 - workshop - Craig Young - brainwashing embedded systems
 
Cloud Foundry Meetup Tokyo #1 Route service
Cloud Foundry Meetup Tokyo #1 Route serviceCloud Foundry Meetup Tokyo #1 Route service
Cloud Foundry Meetup Tokyo #1 Route service
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless OverviewOpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
 
Hyperleger Composer Architecure Deep Dive
Hyperleger Composer Architecure Deep DiveHyperleger Composer Architecure Deep Dive
Hyperleger Composer Architecure Deep Dive
 
Web Standards Support in WebKit
Web Standards Support in WebKitWeb Standards Support in WebKit
Web Standards Support in WebKit
 
Running microservices successfully | Bastian Hofmann | CODEiD
Running microservices successfully | Bastian Hofmann | CODEiDRunning microservices successfully | Bastian Hofmann | CODEiD
Running microservices successfully | Bastian Hofmann | CODEiD
 
Consul First Steps
Consul First StepsConsul First Steps
Consul First Steps
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Silex, the microframework

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. This talk contains a lot of code\nKeep up!\n
  7. OO layer for the HTTP specification\nRequest and Response object\nUploaded files, cookies &amp; sessions\n
  8. Lightweight implementation of the Observer design pattern\naddListener with event\ndispatch event\n
  9. Associates a request with the code that will convert it to a response\n
  10. The engine for Silex and Symfony\nThe building blocks for building a framework\n- Reverse Proxy with caching and ESI\n- Exception Listener\n- Functional Testing\nSimple interface to turn a request into a response\n
  11. Simple Dependency Injection Container\n50 lines of code\n
  12. You COULD use Plain Old PHP.\nSingle Page apps\n- Concise\n- Extensible via Pimple\n- Testable abstract Request and Response\n
  13. \n
  14. \n
  15. Easy installation\n
  16. Minimum config required to get you up and running\n
  17. A tip for people who use composer a lot\n
  18. Symfony dependencies and versions\n
  19. Lock file (install specific version)\nAutoload file which we use in our code\n
  20. Minimum bootstrap\nSet&amp;#x2019;s composers autoloader and sets up Silex\n
  21. PHP Development server\nNo apache required before we get started!\n
  22. No controllers, so all requests will 404.\n
  23. \n
  24. \n
  25. How the framework translates your request into the code that is executed\nEffectively maps Request data to Code\n
  26. Request data &amp; Code\nMethod = HTTP Method\nPattern = URL path\nClosure (anoymous function) = the code\n
  27. Closure returns a string, or a response object\nGET, POST, PUT, DELETE\n\n
  28. \n
  29. \n
  30. This route will only match a Url *with* a name supplied\nParam is passed into the function\n
  31. The default allows it to match / and optionally {name}\n
  32. \n
  33. The results of the convert function passed to Closure\nThis could be an object of a class, for example.\n
  34. Allow us to add arbitrary conditions to a route before it will match\n
  35. Contrived example! 2 routes with asserts\n/word matched the first route\n/4 matches the second\n
  36. Key part of the provided functionality in Silex\n\n
  37. Service providers are a way of reusing code across controllers\nController Providers are a way of reusing Controllers themselves\n
  38. These are provided\nThird party to provide Propel, Redis, Mongo, alternative templating engines, Config (XML/JSON/YAML), Gravatar, Memcache, Solr etc.\n
  39. Silex supports Twig out the box\n
  40. A few more dependencies - silex is very light on its own\ntwig-bridge optional but adds some convenience methods to Twig\n - path and url for UrlGeneratorServiceProvider\n - trans and transchoice for TranslationServiceProvider\n - set of methods for handling forms in templates (which is what we are using)\n - is_granted for SecurityServiceHelper\n
  41. Pass a directory for where the templates can be found\nWe&amp;#x2019;re not actually using twig at this point - just registering\n
  42. \n
  43. \n
  44. Is everyone familiar with Traits in PHP 5.4?\n&amp;#x201C;compiler assisted copy &amp; paste&amp;#x201D;\n
  45. All built-in providers have traits to enhance the Application object\nShort array syntax since we know we&amp;#x2019;re using 5.4!\n
  46. \n
  47. We add two line to our dependencies - symfony/form and symfony translation.\n
  48. The translation provider is required for the default form layout\nSymfony forms are a talk on there own and there&amp;#x2019;s docs out there\nSplit the services and traits out into a bootstrap file\n
  49. This looks like too much controller logic\n
  50. We don&amp;#x2019;t like fat controllers...\n
  51. Refactor form code\nmake it more re-usable\n
  52. Reduce code in controllers\n
  53. form_widget is a twig helper from the symfony bridge\n
  54. Until the invention of twitter bootstrap all my forms looked like this\n
  55. Much better\nExcept now all my forms look like this\n
  56. Any old enough to remember the 1990&amp;#x2019;s &amp;#x2018;guestbooks&amp;#x2019; on websites\n
  57. In handling POST we need to identify the target URL\n\n
  58. We do this with another service provider\nAnd an optional Trait\n
  59. We&amp;#x2019;re using the trait and registering the provider\n
  60. We use bind to give this route a name, &amp;#x2018;homepage&amp;#x2019;.\n
  61. Template grown a little since the last time we saw it\nEssentially the only change is the form action\n
  62. Update the method to match\nAdd methods to match to method\nAdd code to validate and save the new entry\nRecap!\n
  63. This creates a guestbook and adds the new entry\nProblem with instantiating the model in the controller\nWe need to create a service to supply the guestbook\n
  64. This is a shared service\nFirst time it&amp;#x2019;s accessed it will create the object\nOnce created it returns the same object\nlazy loading\n
  65. We then refactor code to make use of the service we defined\nReduce controller responsibility\n
  66. \n
  67. Set up a new route with the code to display the messages list\n
  68. \n
  69. The render function allows us to use another controller\nThis is excellent for apps using AJAX as calling this route will return the HTML block\n
  70. \n
  71. Caches are the reason the web is able to scale\nBrowser caches are good but server cache is fun!\nSymfony has a built in reverse proxy with support for ESI\nOr we can use varnish\n\n
  72. Small markup language for edge level dynamic content assembly\n
  73. Inserted into HTML or any text based content as creation\nInterpreted by an intermediary\nAllow for blocks of code to be independently cached from the main page\n
  74. Because no presentation is complete without a picture of a cloud...\nSymfony components can handle Server Cache and Application as part of the same app\n
  75. This is the version that caused Silex to render the result of the messages controller\nA small change required to use ESI\n
  76. We simply update the markup so that the http output contains the ESI directive\n
  77. Set the cache directory to store static HTML\nSet debug so we can see the headers\n
  78. Set TTL on responses and Surrogate-Control header for proxy\nrun the http_cache rather than $app-&gt;run\nDEMO!\n
  79. \n
  80. Go build sandcastles!\n
  81. \n