Speed up your developments with Symfony2
Upcoming SlideShare
Loading in...5
×
 

Speed up your developments with Symfony2

on

  • 6,073 views

 

Statistics

Views

Total Views
6,073
Slideshare-icon Views on SlideShare
5,904
Embed Views
169

Actions

Likes
9
Downloads
77
Comments
0

11 Embeds 169

http://symfony-friends.blogspot.com 71
http://paper.li 23
http://www.techgig.com 23
http://www.sfexception.com 16
http://symfony-gu.ru 11
http://symfony-friends.blogspot.be 8
http://twitter.com 7
https://twitter.com 4
http://symfony-friends.blogspot.fr 3
http://guru-dev.com 2
http://symfony2developer.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Speed up your developments with Symfony2 Speed up your developments with Symfony2 Presentation Transcript

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