Your SlideShare is downloading. ×
0
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Speed up your developments with Symfony2
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Speed up your developments with Symfony2

6,453

Published on

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,453
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
91
Comments
0
Likes
10
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Speed Up YourDevelopmentswith Symfony2<br />
  • 2.
  • 3. Hugo Hamon<br />Trainings Manager<br />hhamon on Twitter<br />International speaker<br />
  • 4. Builtaroundstandalone and decoupled components…<br />
  • 5. … and a full-stackframeworkbased on those components<br />
  • 6. Application bundles<br />Third party bundles<br />The Symfony2 stack<br />Bridges<br />Third party libraries<br />Core Bundles<br />Standalone Components<br />
  • 7. « A Bundleis a directory that has a well-defined structure and can host anythingfrom classes to controllers and web resources.  »<br />
  • 8. Whatmakes Symfony2 unique?<br />
  • 9. Symfony2 follows standards <br />&amp; best practices<br /><ul><li>RFC2616
  • 10. PHPUnit
  • 11. Jinja Templates
  • 12. Design Patterns</li></li></ul><li>Symfonyisnoweasier<br />to install and configure<br />http://symfony.com/download<br />
  • 13. Several distributions available<br />Download the Standard Edition that hosts the framework, standard bundles and a default application architecture.<br />
  • 14. Easy installation and configuration<br />
  • 15. Web configuration<br />Configure the databaseaccessparameters<br />
  • 16. Start to use Symfony2and happy coding<br />
  • 17. Want to giveit a try?<br />
  • 18. Symfony2 Philosophy<br />« Basically, Symfony2 asksyou to convert a Requestinto a Response »<br />
  • 19. Request Handling<br />classDefaultControllerextends Controller<br />{<br />/**<br /> * @Route(&quot;/hello/{name}&quot;)<br /> */<br />public functionindexAction($name)<br /> {<br />// ... do things<br />returnnewResponse(sprintf(&apos;Hello %s!&apos;, $name));<br /> }<br />}<br />
  • 20. RequestHandling<br />classDefaultControllerextends Controller<br />{<br />/**<br /> * @Route(&quot;/hello/{name}&quot;)<br /> */<br />public functionindexAction($name)<br /> {<br />// ... do things<br />return $this-&gt;render(<br />&apos;SensioHelloBundle:Default:index.html.twig&apos;,<br />array(&apos;name&apos;=&gt; $name)<br /> );<br /> }<br />}<br />
  • 21. RequestHandling<br />classDefaultControllerextends Controller<br />{<br />/**<br /> * @Route(&quot;/schedule&quot;)<br /> *@Template()<br />*/<br />public functionindexAction()<br /> {<br /> $title=&apos;ConferencesSchedule&apos;;<br />returnarray(&apos;title&apos;=&gt; $title);<br /> }<br />}<br />Template vars<br />
  • 22. ViewRendering<br />{%extends&quot;SensioConferenceBundle::layout.html.twig&quot;%}<br />{%blockcontent%}<br /> &lt;h1&gt; {{title}} &lt;/h1&gt;<br /> &lt;ul&gt;<br /> &lt;li&gt;Caching on the Edge, by Fabien Potencier&lt;/li&gt;<br /> &lt;li&gt;HipHop for PHP, by Scott Mac Vicar&lt;/li&gt;<br /> &lt;li&gt;XDebug, by Derick Rethans&lt;/li&gt;<br /> &lt;li&gt;...&lt;/li&gt;<br /> &lt;/ul&gt;<br />{%endblock%}<br />
  • 23. Twig Template Engine<br />Twigis a modern templateengine for PHP<br /><ul><li>Fast
  • 24. Concise and richsyntax
  • 25. Automatic output escaping
  • 26. Modern features
  • 27. Extensible
  • 28. Flexible</li></li></ul><li>Template inheritance<br />{%extends&quot;SensioConferenceBundle::layout.html.twig&quot;%}<br />{%block content %}<br /> &lt;h1&gt; {{title}} &lt;/h1&gt;<br /> &lt;ul&gt;<br /> &lt;li&gt;Caching on the Edge, by Fabien Potencier&lt;/li&gt;<br /> &lt;li&gt;HipHop for PHP, by Scott Mac Vicar&lt;/li&gt;<br /> &lt;li&gt;XDebug, by Derick Rethans&lt;/li&gt;<br /> &lt;li&gt;...&lt;/li&gt;<br /> &lt;/ul&gt;<br />{%endblock%}<br />index.html.twig<br />
  • 29. Template inheritance<br />{%extends&quot;::base.html.twig&quot;%}<br />{%blockbody%}<br /> &lt;imgsrc=&quot;/images/logo.gif&quot; alt=&quot;Confoo 2011&quot;/&gt;<br />{%blockcontent%}{%endblock%}<br />{%endblock%}<br />layout.html.twig<br />
  • 30. &lt;!DOCTYPE html&gt;<br />&lt;html&gt;<br /> &lt;head&gt;<br /> &lt;meta http-equiv=&quot;Content-Type&quot; <br /> content=&quot;text/html; charset=utf-8&quot; /&gt;<br /> &lt;title&gt;<br />{%blocktitle%}Welcome!{%endblock%}<br />&lt;/title&gt;<br /> &lt;link rel=&quot;shortcut icon&quot; <br />href=&quot;{{asset(&apos;favicon.ico&apos;) }}&quot; /&gt;<br /> &lt;/head&gt;<br /> &lt;body&gt;<br />{%blockbody%}{%endblock%}<br /> &lt;/body&gt;<br />&lt;/html&gt;<br />base.html.twig<br />
  • 31. Template inheritance<br />base.html.twig<br />layout.html.twig<br />index.html.twig<br />
  • 32. Smart URIs<br />
  • 33. Smart URIs<br />Native routingmechanism<br />Bidirectional<br />Parametersconstraints support<br />
  • 34. classDefaultControllerextends Controller<br />{<br />/**<br />* @Route(<br /> * &quot;/{year}/talk/{month}/{day}/{slug}&quot;, <br /> * requirements={<br /> * &quot;year&quot;=&quot;d{4}&quot;,<br /> * &quot;month&quot;=&quot;d{2}&quot;,<br /> * &quot;day&quot;=&quot;d{2}&quot;<br /> * }<br /> * )<br /> * @Template()<br /> */<br />public functionshowAction($slug, $day, $month, $year)<br />{<br />// ...<br /> }<br />}<br />
  • 35. Doctrine ParameterConverter<br />Convertsrequestsparameters to a Doctrine entity.<br />classDefaultControllerextends Controller<br />{<br />/**<br />* @Route(&quot;/talk/{id}&quot;)<br /> * @ParamConverter(&quot;talk&quot;, class=&quot;SensioConferenceBundle:Talk&quot;)<br /> * @Template()<br /> */<br />public functionshowAction(Talk $talk)<br />{<br />returnarray(&apos;talk&apos;=&gt; $talk);<br /> }<br />}<br />
  • 36. Easy<br />Debugging<br />http://www.flickr.com/photos/artelaphe/<br />
  • 37. The Web DebugToolbar<br />Memory<br />Queries<br />Recorded logs<br />Timers<br />Currentenvironment<br />Currentresponse<br />Symfony2 version<br />PHP environment<br />
  • 38. The Profiler Application<br />
  • 39. The Profiler Application<br />
  • 40. Exception Stack Trace<br />
  • 41. Exception Stack Trace<br />
  • 42. Recorded Logs<br />
  • 43. http://www.flickr.com/photos/chanceprojects/<br />
  • 44. Doctrine2 Support<br /><ul><li>Database Abstraction Layer on top of PDO
  • 45. Object Relational Mapper
  • 46. Migrations support
  • 47. Object Document Mapper (MongoDB)
  • 48. Object XML Mapper (XML databases)</li></li></ul><li>Data Mapper Implementation<br />/**<br /> * @ORMEntity()<br />*/<br />class Talk<br />{<br />/**<br /> * @ORMId()<br /> * @ORMGeneratedValue()<br /> * @ORMColumn(type=&quot;integer&quot;)<br /> */<br />private$id;<br />/** @ORMColumn(length=80) */<br />private $title;<br />/** @ORMColumn(type=&quot;text&quot;) */<br />private $synopsis;<br />/** @ORMColumn(type=&quot;datetime&quot;) */<br />private $schedule;<br />/** @ORMManyToMany(targetEntity=&quot;Speaker&quot;, mappedBy=&quot;talks&quot;) */<br />private $speakers;<br />}<br />
  • 49. Validation<br />
  • 50. Validation Framework<br /><ul><li>ValidatePOPOs (properties &amp; methods)
  • 51. Easy configuration with annotations
  • 52. Easy to customize and extend</li></li></ul><li>namespaceSensioBundleTodoBundleEntity;<br />classTask<br />{<br />private$name;<br />private $dueDate;<br />public functiongetName() {<br />return $this-&gt;name;<br /> }<br />public functionsetName($name) {<br /> $this-&gt;name = $name;<br /> }<br />public functiongetDueDate() {<br />return $this-&gt;dueDate;<br /> }<br />public functionsetDueDate(DateTime $dueDate=null) {<br /> $this-&gt;dueDate= $dueDate;<br /> }<br />}<br />
  • 53. namespaceSensioBundleTodoBundleEntity;<br />useSymfonyComponentValidatorConstraintsasAssert;<br />classTask<br />{<br />/**<br /> * @AssertNotBlank()<br /> * @AssertMinLength(5)<br /> * @AssertMaxLength(30)<br /> */<br />private $name;<br />/**<br /> * @AssertNotBlank()<br /> * @AssertType()<br /> * @AssertMaxLength(30)<br /> */<br />private $dueDate;<br />// ...<br />}<br />
  • 54. Forms Management<br />http://www.flickr.com/photos/miahz/<br />
  • 55. Forms Management<br /><ul><li>Transparent layer on top of yourdomainobject
  • 56. Native CSRF protection
  • 57. Coupled to the Validation framework
  • 58. Twigintegration</li></li></ul><li>namespaceSensioBundleTodoBundleForm;<br />useSymfonyComponentFormAbstractType;<br />useSymfonyComponentFormFormBuilder;<br />classTaskTypeextendsAbstractType<br />{<br />public functionbuildForm(FormBuilder $builder, array $options)<br /> {<br /> $builder-&gt;add(&apos;name&apos;);<br /> $builder-&gt;add(&apos;dueDate&apos;, &apos;date&apos;);<br /> }<br />public functiongetName()<br /> {<br />return&apos;task&apos;;<br /> }<br />}<br />
  • 59. useSensioBundleTodoBundleEntityTask;<br />useSensioBundleTodoBundleFormTaskType;<br />public functionnewAction()<br />{<br /> $task =newTask();<br /> $task-&gt;setName(&apos;Write a blog post&apos;);<br /> $task-&gt;setDueDate(new DateTime(&apos;tomorrow&apos;));<br /> $request = $this-&gt;getRequest(); <br /> $form = $this-&gt;createForm(newTaskType(), $task);<br />if ($request-&gt;getMethod() ==&apos;POST&apos;) {<br /> $form-&gt;bindRequest($request);<br />if ($form-&gt;isValid()) {<br />// save the task to the database...<br />return $this-&gt;redirect($this-&gt;generateUrl(&apos;success&apos;));<br /> }<br /> }<br />}<br />
  • 60. Prototyping<br />{%extends&apos;SensioTodoBundle::layout.html.twig&apos;%}<br />{%blockcontent%}<br />&lt;form action=&quot;#&quot; method=&quot;post&quot;&gt;<br />{{form_widget(form) }}<br /> &lt;input type=&quot;submit&quot; value=&quot;Send!&quot; /&gt;<br />&lt;/form&gt;<br />{%endblock%}<br />
  • 61. FunctionalTesting<br />http://www.flickr.com/photos/kenstein/<br />
  • 62. FunctionalTesting<br />Simulating an end-user browsing<br />Crawling API for links &amp; forms<br />Testinginternalobjects<br />Testing the response<br />
  • 63. FunctionalTesting<br />classDefaultControllerTestextendsWebTestCase<br />{<br />public functiontestIndex()<br /> {<br /> $client =static::createClient();<br /> $crawler = $client-&gt;request(&apos;GET&apos;, &apos;/schedule&apos;);<br /> $this-&gt;assertTrue(<br /> $crawler-&gt;filter(&apos;html:contains(&quot;Fabien&quot;)&apos;)-&gt;count() &gt;0<br /> );<br /> $response = $client-&gt;getResponse();<br /> $this-&gt;assertTrue($response-&gt;headers-&gt;has(&apos;expires&apos;));<br /> }<br />}<br />
  • 64. HTTP Compliance (RFC2616)<br />
  • 65. Expiration / Validation<br />
  • 66. Expiration – Expires Header Field<br />classDefaultControllerextends Controller<br />{<br />/**<br /> * @Route(&quot;/schedule&quot;)<br /> * @Template<br />* @Cache(expires=&quot;tomorrow&quot;)<br />*/<br />public functionindexAction()<br /> {<br /> $title=&apos;ConferencesSchedule&apos;;<br />returnarray(&apos;title&apos;=&gt; $title);<br /> }<br />}<br />
  • 67. Expiration – Cache-Control Header Field<br />classDefaultControllerextends Controller<br />{<br />/**<br /> * @Route(&quot;/schedule&quot;)<br /> * @Template<br />* @Cache(maxage=&quot;20&quot;)<br />*/<br />public functionindexAction()<br /> {<br /> $title=&apos;ConferencesSchedule&apos;;<br />returnarray(&apos;title&apos;=&gt; $title);<br /> }<br />}<br />
  • 68. Native PHP Reverse Proxy Cache<br />
  • 69. Varnish / Squid<br />
  • 70. http://varnish-cache.org<br />
  • 71. EdgeSideIncludes<br />&lt;esi:includesrc=&quot;http://...&quot; /&gt;<br />
  • 72. EdgeSideIncludes Support<br />No ESI<br />
  • 73. EdgeSideIncludes Support<br />With ESI<br />&lt;esi:include … /&gt;<br />
  • 74. Interactive<br />Code Generators<br />
  • 75. $ phpapp/console generate:bundle<br />
  • 76.
  • 77. $ phpapp/console generate:doctrine:crud<br />
  • 78. http://www.flickr.com/photos/bwop/<br />
  • 79. &lt;?xml version=&quot;1.0&quot;?&gt;<br />&lt;xliff version=&quot;1.2&quot;<br />xmlns=&quot;urn:oasis:names:tc:xliff:document:1.2&quot;&gt;<br /> &lt;file source-language=&quot;en&quot;<br />datatype=&quot;plaintext&quot;<br /> original=&quot;file.ext&quot;&gt;<br /> &lt;body&gt;<br /> &lt;trans-unit id=&quot;1&quot;&gt;<br /> &lt;source&gt;Symfony2 isgreat&lt;/source&gt;<br /> &lt;target&gt;J&apos;aime Symfony2&lt;/target&gt;<br /> &lt;/trans-unit&gt;<br /> &lt;trans-unit id=&quot;2&quot;&gt;<br /> &lt;source&gt;My name is %name%!&lt;/source&gt;<br /> &lt;target&gt;Je m&apos;appelle %name% !&lt;/target&gt;<br /> &lt;/trans-unit&gt;<br /> &lt;/body&gt;<br /> &lt;/file&gt;<br />&lt;/xliff&gt;<br />
  • 80. Translating Messages FromTwig<br />{%setmessage = &apos;Symfony2 isgreat&apos;%}<br />{{message|trans}}<br />{%setmessage = &apos;Mynameis %name%!&apos;%}<br />{{message|trans({&apos;%name%&apos;: &apos;Hugo&apos;}, &quot;hello&quot;) }}<br />
  • 81. http://www.flickr.com/photos/cstein96/<br />
  • 82. Roadmap for 2.1?<br />http://www.flickr.com/photos/mkrigsman/<br />
  • 83. Thank You!<br />

×