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

Like this? Share it with your network

Share

Speed up your developments with Symfony2

  • 6,686 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
6,686
On Slideshare
6,517
From Embeds
169
Number of Embeds
11

Actions

Shares
Downloads
85
Comments
0
Likes
9

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

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
  • 2.
  • 3. Hugo Hamon
    Trainings Manager
    hhamon on Twitter
    International speaker
  • 4. Builtaroundstandalone and decoupled components…
  • 5. … and a full-stackframeworkbased on those components
  • 6. Application bundles
    Third party bundles
    The Symfony2 stack
    Bridges
    Third party libraries
    Core Bundles
    Standalone Components
  • 7. « A Bundleis a directory that has a well-defined structure and can host anythingfrom classes to controllers and web resources.  »
  • 8. Whatmakes Symfony2 unique?
  • 9. Symfony2 follows standards
    & best practices
  • Symfonyisnoweasier
    to install and configure
    http://symfony.com/download
  • 13. Several distributions available
    Download the Standard Edition that hosts the framework, standard bundles and a default application architecture.
  • 14. Easy installation and configuration
  • 15. Web configuration
    Configure the databaseaccessparameters
  • 16. Start to use Symfony2and happy coding
  • 17. Want to giveit a try?
  • 18. Symfony2 Philosophy
    « Basically, Symfony2 asksyou to convert a Requestinto a Response »
  • 19. Request Handling
    classDefaultControllerextends Controller
    {
    /**
    * @Route("/hello/{name}")
    */
    public functionindexAction($name)
    {
    // ... do things
    returnnewResponse(sprintf('Hello %s!', $name));
    }
    }
  • 20. RequestHandling
    classDefaultControllerextends Controller
    {
    /**
    * @Route("/hello/{name}")
    */
    public functionindexAction($name)
    {
    // ... do things
    return $this->render(
    'SensioHelloBundle:Default:index.html.twig',
    array('name'=> $name)
    );
    }
    }
  • 21. RequestHandling
    classDefaultControllerextends Controller
    {
    /**
    * @Route("/schedule")
    *@Template()
    */
    public functionindexAction()
    {
    $title='ConferencesSchedule';
    returnarray('title'=> $title);
    }
    }
    Template vars
  • 22. 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%}
  • 23. Twig Template Engine
    Twigis a modern templateengine for PHP
  • 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
  • 29. Template inheritance
    {%extends"::base.html.twig"%}
    {%blockbody%}
    <imgsrc="/images/logo.gif" alt="Confoo 2011"/>
    {%blockcontent%}{%endblock%}
    {%endblock%}
    layout.html.twig
  • 30. <!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
  • 31. Template inheritance
    base.html.twig
    layout.html.twig
    index.html.twig
  • 32. Smart URIs
  • 33. Smart URIs
    Native routingmechanism
    Bidirectional
    Parametersconstraints support
  • 34. 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)
    {
    // ...
    }
    }
  • 35. 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);
    }
    }
  • 36. Easy
    Debugging
    http://www.flickr.com/photos/artelaphe/
  • 37. The Web DebugToolbar
    Memory
    Queries
    Recorded logs
    Timers
    Currentenvironment
    Currentresponse
    Symfony2 version
    PHP environment
  • 38. The Profiler Application
  • 39. The Profiler Application
  • 40. Exception Stack Trace
  • 41. Exception Stack Trace
  • 42. Recorded Logs
  • 43. http://www.flickr.com/photos/chanceprojects/
  • 44. Doctrine2 Support
    • 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)
  • 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;
    }
  • 49. Validation
  • 50. Validation Framework
    • ValidatePOPOs (properties & methods)
    • 51. Easy configuration with annotations
    • 52. 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;
    }
    }
  • 53. namespaceSensioBundleTodoBundleEntity;
    useSymfonyComponentValidatorConstraintsasAssert;
    classTask
    {
    /**
    * @AssertNotBlank()
    * @AssertMinLength(5)
    * @AssertMaxLength(30)
    */
    private $name;
    /**
    * @AssertNotBlank()
    * @AssertType()
    * @AssertMaxLength(30)
    */
    private $dueDate;
    // ...
    }
  • 54. Forms Management
    http://www.flickr.com/photos/miahz/
  • 55. Forms Management
    • Transparent layer on top of yourdomainobject
    • 56. Native CSRF protection
    • 57. Coupled to the Validation framework
    • 58. Twigintegration
  • namespaceSensioBundleTodoBundleForm;
    useSymfonyComponentFormAbstractType;
    useSymfonyComponentFormFormBuilder;
    classTaskTypeextendsAbstractType
    {
    public functionbuildForm(FormBuilder $builder, array $options)
    {
    $builder->add('name');
    $builder->add('dueDate', 'date');
    }
    public functiongetName()
    {
    return'task';
    }
    }
  • 59. 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'));
    }
    }
    }
  • 60. Prototyping
    {%extends'SensioTodoBundle::layout.html.twig'%}
    {%blockcontent%}
    <form action="#" method="post">
    {{form_widget(form) }}
    <input type="submit" value="Send!" />
    </form>
    {%endblock%}
  • 61. FunctionalTesting
    http://www.flickr.com/photos/kenstein/
  • 62. FunctionalTesting
    Simulating an end-user browsing
    Crawling API for links & forms
    Testinginternalobjects
    Testing the response
  • 63. 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'));
    }
    }
  • 64. HTTP Compliance (RFC2616)
  • 65. Expiration / Validation
  • 66. Expiration – Expires Header Field
    classDefaultControllerextends Controller
    {
    /**
    * @Route("/schedule")
    * @Template
    * @Cache(expires="tomorrow")
    */
    public functionindexAction()
    {
    $title='ConferencesSchedule';
    returnarray('title'=> $title);
    }
    }
  • 67. Expiration – Cache-Control Header Field
    classDefaultControllerextends Controller
    {
    /**
    * @Route("/schedule")
    * @Template
    * @Cache(maxage="20")
    */
    public functionindexAction()
    {
    $title='ConferencesSchedule';
    returnarray('title'=> $title);
    }
    }
  • 68. Native PHP Reverse Proxy Cache
  • 69. Varnish / Squid
  • 70. http://varnish-cache.org
  • 71. EdgeSideIncludes
    <esi:includesrc="http://..." />
  • 72. EdgeSideIncludes Support
    No ESI
  • 73. EdgeSideIncludes Support
    With ESI
    <esi:include … />
  • 74. Interactive
    Code Generators
  • 75. $ phpapp/console generate:bundle
  • 76.
  • 77. $ phpapp/console generate:doctrine:crud
  • 78. http://www.flickr.com/photos/bwop/
  • 79. <?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>
  • 80. Translating Messages FromTwig
    {%setmessage = 'Symfony2 isgreat'%}
    {{message|trans}}
    {%setmessage = 'Mynameis %name%!'%}
    {{message|trans({'%name%': 'Hugo'}, "hello") }}
  • 81. http://www.flickr.com/photos/cstein96/
  • 82. Roadmap for 2.1?
    http://www.flickr.com/photos/mkrigsman/
  • 83. Thank You!