[Oslo and Helsinki meetups] Status about Symfony

[Oslo and Helsinki meetups] Status about Symfony

This presentation has been done for those meetups:
- Ez publish meetup in Oslo, Norway (http://www.meetup.com/eZ-Oslo-Meetup/events/222305799/)
- PHP meetup in Helsinki, Finland (http://www.meetup.com/Helsinki-Symfony-Meetup/events/222295052/)

34ade09dd3d11004ca8ee4174fd3d6a2?s=128

Sarah KHALIL

June 05, 2015
Tweet

Transcript

  1. Status about Tuesday May 4th, 2015 – Helsinki – Finland

  2. WHO AM I? • Head of • Trainer & Developer

    • Enjoying sharer • Contributor to
  3. 3

  4. https://sensiolabs.com

  5. 5

  6. 1.  WHAT  IS  SYMFONY   2.  WHAT’S  NEW? 6 Summary

  7. 7

  8. 8

  9. WHAT  IS  SYMFONY? 9 Round  1

  10. Framework Philosophy Community

  11. None
  12. None
  13. Dependency Injection BrowserKit ClassLoader Config CssSelector Debug DomCrawler Filesystem Finder

    HttpFoundation HttpKernel Locale Intl Icu OptionsResolver Process PropertyAccess Serializer Stopwatch Templating Translation Validator ExpressionLanguage Console yaml EventDispatcher Routing Security Form
  14. None
  15. None
  16. https://symfony.com/roadmap

  17. INTRODUCING…  THE  COMMUNITY! 17 Round  1  -­‐  What  is  Symfony

  18. +1,000 code contributors

  19. +700 documentation contributors

  20. +2,500 community bundles

  21. And many open source projects!

  22. SIMPLIFY  THE  DEVS’  LIFE:   IDE  INTEGRATION 22 Round  1

     -­‐  What  is  Symfony
  23. None
  24. SIMPLIFY  THE  DEVS’  LIFE:   EASY  INSTALLATION 24 Round  1

     -­‐  What  is  Symfony
  25. Easy installation with Composer

  26. Easy  installation 26

  27. Easy  installation  with  the  installer 27

  28. THE  PHILOSOPHY   28 Round  1  -­‐  What  is  Symfony

  29. # web/app.php use Symfony\Component\HttpFoundation\Request; $kernel = new AppKernel('prod', false); $kernel->loadClassCache();

    $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);
  30. 30 Separation of Concerns Implementation Controller View Model Modifies the

    model Returns model data Renders the view The Controller analyses the user request, calls the Model and passes data to the View. The View layer formats data in a dedicated format (html, json…) The Model stores the business logic and classes that manipulate data. R Router Response Request /hello/fabien
  31. 30 Separation of Concerns Implementation Controller View Model Modifies the

    model Returns model data Renders the view The Controller analyses the user request, calls the Model and passes data to the View. The View layer formats data in a dedicated format (html, json…) The Model stores the business logic and classes that manipulate data. R Router Response Request /hello/fabien
  32. 30 Separation of Concerns Implementation Controller View Model Modifies the

    model Returns model data Renders the view The Controller analyses the user request, calls the Model and passes data to the View. The View layer formats data in a dedicated format (html, json…) The Model stores the business logic and classes that manipulate data. R Router Response Request /hello/fabien
  33. VC  Framework 31

  34. namespace Acme\DemoBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\[…]\Route; use Symfony\Component\HttpFoundation\Response; class DefaultController { /**

    @Route("/hello/{name}") */ public function indexAction($name) { return new Response('Hello '.$name); } }
  35. class DefaultController extends Controller { /** @Route("/hello/{name}") */ public function

    indexAction($name) { return $this->render( 'AcmeDemoBundle:Default:index.html.twig', [ 'name' => $name ] ); } }
  36. class DefaultController { /** * @Route("/schedule") * @Template */ public

    function indexAction() { return [ 'title' => 'Schedule' ]; } }
  37. 35 Round  1  -­‐  What  is  Symfony GREAT  TOOL  TO

     CODE  FASTER:   TWIG
  38. {% extends "SensioConferenceBundle::layout.html.twig" %} {% block content %} <h1> {{

    title }} </h1> <ul> <li>HTTP Caching, by Fabien Potencier</li> <li>HipHop for PHP, by Scott Mac Vicar</li> <li>XDebug, by Derick Rethans</li> <li>...</li> </ul> {% endblock %}
  39. {% extends "SensioConferenceBundle::layout.html.twig" %} {% block title 'Conference Schedule' %}

    {% block content %} <h1> {{ title }} </h1> <ul> <li>HTTP Caching, 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
  40. {% extends "::base.html.twig" %} {% block body %} <img src="/images/logo.gif"

    /> {% block content '' %} {% endblock %} layout.html.twig
  41. <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ... /> <title>{% block

    title 'Welcome!' %}</title> <link … href="{{ asset('favicon.ico') }}" /> </head> <body> {% block body '' %} </body> </html> base.html.twig
  42. base.html.twig layout.html.twig index.html.twig

  43. Twig is a modern template engine for PHP ▪ Fast

    ▪ Concise and rich syntax ▪ Automatic output escaping ▪ Modern features ▪ Extensible
  44. Twig is a modern template engine for PHP ▪ Fast

    ▪ Concise and rich syntax ▪ Automatic output escaping ▪ Modern features ▪ Extensible twig.sensiolabs.org
  45. SIMPLIFY  THE  DEVS’  LIFE:   DEVELOPMENT  TOOLS 42 Round  1

     -­‐  What  is  Symfony
  46. None
  47. None
  48. None
  49. None
  50. SIMPLIFY  THE  DEVS’  LIFE:   CODE  GENERATORS 47 Round  1

     -­‐  What  is  Symfony
  51. $ php app/console generate:bundle

  52. None
  53. $ php app/console generate:doctrine:crud

  54. GREAT  TOOL  TO  CODE  FASTER:   ROUTING  COMPONENT 51 Round

     1  -­‐  What  is  Symfony
  55. The router maps a url pattern to a set of

    internal parameters.
  56. The router maps a url pattern to a set of

    internal parameters. It’s about matching a request to a callable => action
  57. /** * @Route( * "/{year}/talk/{month}/{day}/{slug}", * requirements={ * "year"="\d{4}", *

    "month"="\d{2}", * "day"="\d{2}" * } * ) */ public function showAction($slug, $day, $month, $year) { // ... }
  58. acme_blog_show: path: /{year}/talk/{month}/{day}/{slug} defaults: { _controller: AcmeBlogBundle:Blog:blog } requirements: year:

    "\d{4}" month: "\d{2}" day: "\d{2}" schemes: https methods: GET host: blog.my-domain.com condition: "request.headers.get('User-Agent') matches '/firefox/i'" YAML Configuration
  59. <?xml version="1.0" encoding="UTF-8" ?> <routes> <route id="acme_blog_show" path="/{year}/talk/{month}/{day}/{slug}" schemes="https" method="GET"

    > <default key="_controller">AcmeBlogBundle:Blog:show</default> <requirement key="year">\d{4}</requirement> <requirement key="month">\d{2}</requirement> <requirement key="day">\d{2}</requirement> <condition>request.headers.get('User-Agent') matches '/firefox/i'<condition> </route> </routes> XML Configuration
  60. /** @Route("/talk/{id}") */ function showAction(Talk $talk) { // ... }

    Automatic Arguments Discovery
  61. GREAT  TOOL  TO  CODE  FASTER:   DATABASE  HANDLING 57 Round

     1  -­‐  What  is  Symfony
  62. ▪ Database Abstraction Layer on top of PDO ▪ Object

    Relational Mapper ▪ Migrations support ▪ Object Document Mapper (MongoDB) Doctrine2 Support
  63. /** @ORM\Entity */ class Talk { /** * @ORM\Id *

    @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** @ORM\Column(length=80) */ private $title; /** @ORM\Column(type="text") */ private $synopsis; /** @ORM\Column(type="datetime") */ private $schedule; /** @ORM\ManyToMany(targetEntity="Speaker", mappedBy="talks") */ private $speakers; }
  64. GREAT  TOOL  TO  CODE  FASTER:   SERVICE  CONTAINER 60 Round

     1  -­‐  What  is  Symfony
  65. Service != Domain object has  a  state makes  something  for

     the   application
  66. The service container manages initialization of objects.

  67. services: user_manager: class: Acme\UserManager arguments: - "@event_dispatcher" - "@security.encoder_factory" -

    "@doctrine.orm.entity_manager" - "@security.context" YAML Configuration
  68. <?xml version="1.0" ?> <container> <services> <service id="user_manager" class="Acme\UserManager"> <argument type="service"

    id="event_dispatcher"/> <argument type="service" id="security.encoder_factory"/> <argument type="service" id="doctrine.orm.entity_manager"/> <argument type="service" id="security.context" /> </service> </services> </container> XML Configuration
  69. class appProdProjectContainer extends Container { protected function getUserManagerService() { $instance

    = new Acme\UserManager( $this->get('debug.event_dispatcher'), $this->get('security.encoder_factory'), $this->get('doctrine.orm.default_entity_manager'), $this->get('security.context') ); $this->services['user_manager'] = $instance; return $instance; } } Service Factory Method
  70. $manager = $this ->container ->get('user_manager') ; Service Lazy Loading

  71. GREAT  TOOL  TO  CODE  FASTER:   DATA  VALIDATION 67 Round

     1  -­‐  What  is  Symfony
  72. The validator component validates objects against a set of constraints.

  73. /** @Assert\UniqueEntity("username") */ class User { /** * @Assert\NotBlank *

    @Assert\Email */ private $username; /** * @Assert\NotBlank * @Assert\Length(min = 8, max = 32) */ private $password; // ... }
  74. $user = new User(); $user->setUsername('x@abc.com'); $user->setPassword('changeme'); $validator = $this->get('validator'); $errors

    = $validator->validate($user); Validating an Object
  75. GREAT  TOOL  TO  CODE  FASTER:   FORM  MANAGEMENT 71 Round

     1  -­‐  What  is  Symfony
  76. namespace Sensio\UserBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class UserType extends AbstractType

    { function buildForm(FormBuilderInterface $builder, …) { $builder ->add('username', 'email') ->add('password', 'password') ->add('submit', 'submit') ; } }
  77. public function userAction(Request $request) { $user = new User(); $user->setUsername('x@abc.com');

    $form = $this->createForm(new UserType(), $user); $form->handleRequest($request); if ($form->isValid()) { // ... } return ['form' => $form->createView() ]; }
  78. {{ form(form) }} Displaying the form

  79. GREAT  TOOL  TO  CODE  FASTER:   AUTOMATED  TESTS 75 Round

     1  -­‐  What  is  Symfony
  80. UNIT TESTING

  81. FUNCTIONAL TESTING

  82. None
  83. GREAT  TOOL  TO  CODE  FASTER:   HTTP  CACHING 79 Round

     1  -­‐  What  is  Symfony
  84. RFC2616

  85. Expiration   Validation

  86. class DefaultController { /** * @Template * @Cache(expires="tomorrow") */ public

    function indexAction() { return [ 'title' => 'Schedule' ]; } }
  87. class DefaultController { /** * @Template * @Cache(maxage=120) */ public

    function indexAction() { return [ 'title' => 'Schedule' ]; } }
  88. HTTP Reverse Proxy Caching

  89. varnish-cache.org

  90. Edge Side Includes <esi:include src="http://..." />

  91. No ESI

  92. <esi:include … /> With ESI

  93. GREAT  TOOL  TO  CODE  FASTER:   INTERNATIONALISATION  /  LOCALISATION 89

    Round  1  -­‐  What  is  Symfony
  94. <?xml version="1.0"?> <xliff version="1.2"> <file …> <body> <trans-unit id="1"> <source>Symfony2

    is great</source> <target>J'aime Symfony2</target> </trans-unit> </body> </file> </xliff>
  95. {% set message = 'Symfony2 is great' %} {{ message|trans

    }} {% set message = 'My name is %name%!' %} {{ message|trans({'%name%': 'Hugo'}, "hello") }}
  96. GREAT  TOOL  TO  CODE  FASTER:   AUTHENTICATION  /  AUTHORIZATION 92

    Round  1  -­‐  What  is  Symfony
  97. Built-in authentication means •Form login/password •X509 certificate •HTTP Basic •HTTP

    Digest authentication
  98. •FOSUserBundle •HWIOAuthBundle (Oauth) •… authentication Third party library

  99. /** * @Security("has_role('ROLE_ADMIN')") */ public function editAction($id) { // granted

    to perform an action... } Using annotations to secure an action authorization
  100. Advanced authorization method: Voters

  101. None
  102. None
  103. WHAT’S  NEW? 98 Round  2

  104. SYMFONY  3.0 99 Round  2  -­‐  What  is  new?

  105. 100

  106. 100

  107. 3.0

  108. What  is  it  going  to  be? • Compared to 2.x?

    => No new feature • Removal of descending compatibility layer • Keeping the compatibility when possible • >= PHP 5.5.9
  109. Symfony  2.8  LTS? • Last refactoring of the 2.X branch

    • Last deprecations • New features • It will be the 3.0 + descending layers of compatibility • >= PHP 5.3.9
  110. How  to  handle  the  migration? • UPGRADE.md • Do not

    ignore the deprecation notices • grep/ack ;) • PHPStorm • • error_reporting(E_ALL–E_USER_DEPRECATED) https://knpuniversity.com/blog/upgrading-­‐symfony-­‐2.7
  111. WHAT  IS  GOING  TO  CHANGE  IN   YOUR  APPLICATIONS? 105

    Round  2  -­‐  What  is  new?
  112. Deprecated  constants • UuidValidator::STRICT_PATTERN   • UuidValidator::LOOSE_PATTERN   • UuidValidator::STRICT_UUID_LENGTH

      • FormEvents::BIND   • FormEvents::PRE_BIND   • FormEvents::POST_BIND   • Unescaper::ENCODING
  113. Configuration  variables • `twig.form.resources`  becomes`twig.form_themes`   • Removal  of  `framework.csrf_protection.field_name`

      • `pattern`  becomes  `path`  for  the  routes
  114. Twig  templates • Removal  of  the  {% render %} tag

      • Removal  of  the  {% include %} tag   • Removal  of  the  global  variable  `app.security`
  115. ClassLoader • Removal  of  the  ApcUniversalClassLoader • Removal  of  the

     DebugClassLoader  (use  the  Debug’s  one)   • Removal  of  the  DebugUniversalClassLoader • Removal  of  the  UniversalClassLoader  (use  Composer)
  116. Dependency  Injection  Component • No  more  «  scopes  ».  

    • «  synchronized  »  services  disappear.   • «  factory-­‐*  »  attributes  become  «  factory  »  tags.
  117. Routing • Attribut  Route::$pattern becomes  Route::$path • ApacheUrlMatcher  disappears  (mind

     to  remove  it  in  your  front   controllers)
  118. Console • DialogHelper  replaced  by  Question   • ProgressBarHelper  replaced

     by  ProgressBar   • TableHelper  replaced  by  Table   • Removal  of  the  Application::asText()  and::asXml()   • Removal  of  the  Command::asText()  and  ::asXml()   • Removal  of  the  InputDefinition::asText()  and  ::asXml()
  119. Event  Dispatcher • Removal  of  methods   • Event::setName()  

    • Event::getName()   • Event::getDispatcher()   • Event::setDispatcher()
  120. HTTP  Kernel • Removal  of  the  leagcy  LoggerInterface • Kernel::init()

    disappears  for  the  __construct() • HttpCache::getEsi()replaced  by   HttpCache::getSurrogate()
  121. Form  component • Form::bind()  -­‐>  Form::submit()  /  Form::handleRequest()   •

    No  more  Form::isBound()  neither  Form::getErrorsAsString()   • AbstractType::setDefaultOptions()   -­‐>  AbstractType::configureOptions()   • AbstractTypeExtension::setDefaultOptions()   -­‐>  AbstractTypeExtension::configureOptions()   • No  more  of  the  «  virtual  »  option
  122. Locale  component • The  component  is  removed.   • Use

     the  Intl  component  instead.
  123. OptionsResolver  component • Removal  /  renaming  of  several   methods

     of  the  OptionsResolver   class.
  124. Process  component • Removal  of  the  Process::getStdin()   and  Process::setStdin()

      • Refactoring  coming  up  in  2.8
  125. 119

  126. 119

  127. Property  Access  component • Removal  of  the   PropertyAccess::getPropertyAccessor()

  128. FrameworkBundle • Controller::getRequest() disappears.   • $this->get('request’) disappears.   •

    Use  the  RequestStack.
  129. Security • security.context  service  disappears   • Use  the  security.token_storage


                             &  security.authorization_checker • Removal  of  the  app.security  in  Twig          -­‐>  use  is_granted()
  130. Serializer • Removal  of  the  JsonDecode::getLastError()   • Removal  of

     the  JsonEncode::getLastError()   • Removal  of  the  JsonEncoder::getLastError()
  131. Translation • Removal  of  the   Translator::setFallbackLocale()

  132. Validator • ViolationBuilder  /  ExecutionContext   -­‐>  addViolation()  replaced  by

     buildViolation().   • API  BC  (use  of  the  2.5  version).   • Function  Twig  form_enctype()  disappears.   • No  more  «  type  »  option  in  the  ISBN  constraint.   • No  more  «  methods  »  option  in  the  Callback  constraint.   • No  more  «  deep  »  option    in  the  Valid  constraint.   • The  constraints  Optional  &  Required  disappear.
  133. 126

  134. 126

  135. None
  136. None
  137. The point is to keep everyone on the road. Smooth

    migration!
  138. 128 One more thing!

  139. 129

  140. 130

  141. 131

  142. 132

  143. 132

  144. Useful  links • http://symfony.com/roadmap   • http://symfony.com/blog/   • https://insight.sensiolabs.com/

    133
  145. Thank you! @saro0h speakerdeck.com/saro0h/ This is a zero guys!