Upgrade to Pro — share decks privately, control downloads, hide ads and more …

5 Years with Symfony

5 Years with Symfony

My talk at SymfonyCon 2016, a bit nostalgic retrospective of Symfony development since its early versions.

7ae8ff67c92e2087f2e84884449d6da6?s=128

Pawel Jedrzejewski

December 01, 2016
Tweet

Transcript

  1. 5 Years With Lessons learned during an Open Source adventure

  2. Paweł Jędrzejewski Created Sylius Co-Founded LAKION Co-Organizing PHPers Łódź

  3. None
  4. I need my own framework. @pjedrzejewski

  5. @pjedrzejewski

  6. None
  7. None
  8. None
  9. Great! Let’s make a bundle. BundlegeneratorGeneratorBundle @pjedrzejewski

  10. Lesson #1 Clicking a shiny banner is not always a

    bad idea. It can change your life in many posiKve ways. @pjedrzejewski
  11. Lesson #1 Time is the only resource that maNers. Save

    yours and reuse. Focus on what you do best. PS. Use Bundles for the rest. @pjedrzejewski
  12. None
  13. Lesson #2 Websites for friends and family do not magically

    maintain and fix themselves. @pjedrzejewski
  14. DEPLOY

  15. Lesson #3 You rarely need to create a bundle. Do

    not use them as namespaces. @pjedrzejewski
  16. „A bundle is simply a structured set of files within

    a directory that implement a single feature.” @pjedrzejewski
  17. In 95% of cases you need AppBundle. @pjedrzejewski

  18. What is a good bundle? @pjedrzejewski

  19. None
  20. None
  21. Packagist is great, but Symfony could use a fresh bundles

    catalog. @pjedrzejewski
  22. None
  23. Few words about upgrading Symfony. Doing that since 2.0. @pjedrzejewski

  24. None
  25. 2.0 -> 2.1 was easy. 2.1 -> 2.3 was hard.

    (forms) 2.3 -> 2.8 was smooth. 2.8 -> 3.0 was… hard, but it was our fault. @pjedrzejewski
  26. Lesson #4 Upgrade. If your project does not have resources

    for a Symfony upgrade, there is something much bigger broken than compaKbility. @pjedrzejewski
  27. None
  28. 5m54.83s (678.72Mb) PHP 7 & Symfony 2.8 vs 4m38.20s (52.28Mb)

    PHP 7 & Symfony 3.2 13m6.17s (1.61Gb) PHP 5.6 & Symfony 2.8 vs 10m34.61s (96.04Mb) PHP 5.6 & Symfony 3.2 @pjedrzejewski
  29. Lesson #5 Be careful with sub requests. They are great,

    but loops are dangerous. @pjedrzejewski
  30. routing.yml app_partial_render_reviews: path: /_partial/render-reviews defaults: _controller: app.controller.reviews:renderAction homepage.html.twig {{ render(path(”app_partial_render_views”,

    {’limit’: 3)) }} security.yml access_control: - { path: "^/_partial.*", ip: 127.0.0.1 }
  31. routing.yml app_reviews_index: path: /reviews defaults: _controller: app.controller.reviews:renderAction template: „@FooBar/Reviews/index.html.twig app_reviews_overview:

    path: /overview defaults: _controller: app.controller.reviews:renderAction template: „@FooBar/Reviews/_overview.html.twig limit: 5
  32. public function renderAction($template, $limit = 3) { $reviews = …;

    return $this->templating->renderResponse($template, [’reviews’ => $reviews]); }
  33. Migrating away from legacy It should always be a step-by-step

    process. Just wrap your legacy app with Symfony. Is full migraKon worth it? @pjedrzejewski
  34. public function legacyAction() { $legacyFile = '/path/to/legacy-app/search.php'; ob_start(); include($legacyFile); $content

    = ob_get_clean(); return new Response($content); }
  35. Lesson #6 Do not push for a migraKon when not

    needed. Be smart about it. @pjedrzejewski
  36. Migrating away from legacy hNps:/ /www.theodo.fr/blog/2015/01/wrap-up-your- legacy-applicaKon-with-symfony/ @pjedrzejewski

  37. Symfony FORMS Retrospective With great power comes great responsibility and

    yeah, processing forms is damn hard. @pjedrzejewski
  38. $form = new Form('customer', $customer); $form->add(new TextField('name')); $form->add(new IntegerField(‚age')); $form->bind($this->get('request')-

    >request->get('customer'));
  39. class TaskType extends AbstractType { public function buildForm(FormBuilder $builder, array

    $options) { $builder->add('task'); $builder->add('dueDate', null, array(…)); } public function getName() { return 'task'; } }
  40. use Symfony\Component\OptionsResolver\OptionsResolverInterface; public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'validation_groups' =>

    array('registration'), )); }
  41. $form = $this->createFormBuilder($task) ->add('task', TextType::class) ->add('dueDate', DateType::class) ->getForm();

  42. Lesson #7 Appreciate Symfony forms. @pjedrzejewski

  43. $builder->setDataLocked(false); @pjedrzejewski

  44. Make a new form type, they are quite cheap now.

    Super-generic types are expensive. @pjedrzejewski
  45. Lesson #8 CRUD is great, but can be misused. AdminGenerators

    are great, but assuming too much can go wrong. @pjedrzejewski
  46. Integrating Symfony apps • API IntegraKons • Single-Kernel (Sylius +

    eZ Publish) • hNp:/ /stackphp.com/ @pjedrzejewski
  47. IntegraKng 2 Symfony apps, even via API is much nicer.

    Similar tools and approaches make it easy. Even details like directory structure.
  48. IDS are not unique enough If you applicaKon will integrate

    or share data with others. Unique codes will be your friend. @pjedrzejewski
  49. Single Kernel Integration Throw 2 Symfony apps in a single

    kernel, possible! @pjedrzejewski
  50. None
  51. None
  52. $ git clone git@github.com:netgen/ezplatform- sylius.git $ cd ezplatform-sylius $ composer

    install $ php app/console --env=prod sylius:install $ php app/console --env=prod ezplatform:install clean $ php app/console --env=prod assetic:dump $ php app/console --env=prod ezsylius:user:connect
  53. application contained in a bundle You can contain an enKre

    applicaKon in a bundle. Do not do it upfront, just apply good pracKces. @pjedrzejewski
  54. // AppKernel.php $bundles = array( new Sylius\Bundle\ShopBundle\SyliusShopBundle(), ); # config.yml

    imports: - { resource: "@SyliusShopBundle/Resources/config/ app/config.yml" } # routing.yml sylius_shop: resource: "@SyliusShopBundle/Resources/config/ routing.yml"
  55. Lesson #9 Symfony’s architecture allows for integraKons on a new

    level. @pjedrzejewski
  56. State machines are awesome Relying on a state machine for

    business logic makes your life simpler. hNps:/ /engineering.shopify.com/17488160-why- developers-should-be-force-fed-state-machines @pjedrzejewski
  57. Open source is … EASY? We are just too busy

    doing it. Sharing more knowledge about Open Source pracKce, project maintenance and contribuKng is something we should work on. @pjedrzejewski
  58. OPEN SOURCE CANVAS Lean Canvas for Open Source projects @pjedrzejewski

  59. Open Source Canvas (Lean Canvas, but less scary for devs)

    DEVELOPER SEGMENTS BENEFITS
  60. 350+ Code contributors over 3,100,000 Downloads 600+ Translators 250 Pull

    Requests last month Over 19,000 Travis-CI Builds
  61. BETA Sylius v1.0.0-beta.1 is around the corner… @pjedrzejewski

  62. @pjedrzejewski @Sylius @Lakion pjedrzejewski.com sylius.org lakion.com THANK YOU !