Silex, the microframework

Technical Assurance Manager at Inviqa
Oct. 6, 2012
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
Silex, the microframework
1 of 82

More Related Content

What's hot

Silex and Twig (PHP Dorset talk)Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Dave Hulbert
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 Vaswanivvaswani
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
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 JoomlaPierre-André Vullioud
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stackPaul Bearne
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeDaniel Doubrovkine

Similar to Silex, the microframework

Hack & Fix, Hands on ColdFusion Security TrainingHack & Fix, Hands on ColdFusion Security Training
Hack & Fix, Hands on ColdFusion Security TrainingColdFusionConference
(STG205) Secure Content Delivery Using Amazon CloudFront(STG205) Secure Content Delivery Using Amazon CloudFront
(STG205) Secure Content Delivery Using Amazon CloudFrontAmazon Web Services
Presentation Magento OroCRM - MageConf 2014Presentation Magento OroCRM - MageConf 2014
Presentation Magento OroCRM - MageConf 2014Sylvain Rayé
FIWARE Wednesday Webinars - How to Secure IoT DevicesFIWARE Wednesday Webinars - How to Secure IoT Devices
FIWARE Wednesday Webinars - How to Secure IoT DevicesFIWARE
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 WAFAmazon Web Services
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...CA API Management

Recently uploaded

"The Intersection of architecture and implementation", Mark Richards"The Intersection of architecture and implementation", Mark Richards
"The Intersection of architecture and implementation", Mark RichardsFwdays
Webhook Testing StrategyWebhook Testing Strategy
Webhook Testing StrategyDimpy Adhikary
Product Research Presentation-Maidy Veloso.pptxProduct Research Presentation-Maidy Veloso.pptx
Product Research Presentation-Maidy Veloso.pptxMaidyVeloso
GDSC ZHCET Google Study Jams 23.pdfGDSC ZHCET Google Study Jams 23.pdf
GDSC ZHCET Google Study Jams 23.pdfAbhishekSingh313342
GIT AND GITHUB (1).pptxGIT AND GITHUB (1).pptx
GIT AND GITHUB (1).pptxGDSCCVRGUPoweredbyGo
Mule Meetup Calgary- API Governance & Conformance.pdfMule Meetup Calgary- API Governance & Conformance.pdf
Mule Meetup Calgary- API Governance & Conformance.pdfNithaJoseph4

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 & 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’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 & 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’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“compiler assisted copy & paste”\n
  45. All built-in providers have traits to enhance the Application object\nShort array syntax since we know we’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’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’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’s ‘guestbooks’ 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’re using the trait and registering the provider\n
  60. We use bind to give this route a name, ‘homepage’.\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’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->run\nDEMO!\n
  79. \n
  80. Go build sandcastles!\n
  81. \n