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

Symfony3 Best Practices from the trenches

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Symfony3 Best Practices from the trenches

As done at PHP.FRL meetup in Heerenveen

Stefan Koopmanschap

May 24, 2016

Transcript

39 slides
  1. About me » PHPBenelux » PFZ » PHPAmersfoort/PHP.FRL » Ingewikkeld

    » phpBB, Zend Framework, Symfony and many more
  2. Dependency Injection » No hardcoded dependencies » Easily manage and

    update specific classes » Program to contracts, not implementations » Minimize bootstrap code » More testable code
  3. Dependency Injection class Foo { public function bar() { $coffee

    = new Coffee(); $coffee->init(); return $coffee->drink(); } }
  4. Dependency Injection class Coffee implements Roastable {} class Foo {

    private $coffee; public function __construct(Roastable $coffee) { $this->coffee = $coffee; } }
  5. Dependency Injection parameters: coffee.class: "Coffee" foo.class: "Foo" services: coffee: class:

    "%coffee.class%" foo: class: "%foo.class%" arguments: - "@coffee"
  6. Dependency Injection class DefaultController { private $foo; public function __construct(Foo

    $foo) { $this->foo = $foo; } public function fooAction() { $this->foo->bar(); } }
  7. Service layer » Seperation of concerns » Business logic should

    not be bound to the application » Service layer can be accessed through the service container
  8. Service layer public function showAction($productId) { $product = $this->getDoctrine() ->getRepository('AppBundle:Product')

    ->find($productId); if (!$product) { throw $this->createNotFoundException( 'No product found for id '.$productId ); } // ... do something, like pass the $product object into a template }
  9. Documentation » The best starting point for your search »

    Not the ultimate source for information
  10. Project Configuration Everything in its right place » config*.yml »

    routing*.yml » security.yml » parameters.yml
  11. Choose » You can do things in multiple ways »

    THIS IS GREAT! » Clarity, readability, maintainability
  12. Ready for action? » Use bundles correctly » Maximize external

    library usage » Avoid |raw » .gitignore your parameters.yml » Translate! » Log all the things! » Stay up-to-date
  13. Up-to-date » 2.7 - support until 05/2018, EOL 05/2019 »

    2.8 - support until 11/2018, EOL 11/2019 » 3.0 - support until 07/2016, EOL 01/2017 » Next LTS: 3.4: support until 11/2020, EOL 11/2021

More Decks by Stefan Koopmanschap

Other Decks in Technology