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

Get Started, Move Fast & Break things in Symfony2

weaverryan
February 08, 2014

Get Started, Move Fast & Break things in Symfony2

Grab some coffee and let's get your project moving on Symfony2! Since its 2.0 release in 2011, a lot of fantastic tools and best-practices have been built up around Symfony. In this talk, we'll start a real project and learn about some of these tools that can make us dangerous as quickly as possible! Symfony2 lets you write beautiful, maintainable code, and I'll give you 5 tips to do just that while staying aggressive with getting features out the door. RAD!

weaverryan

February 08, 2014
Tweet

More Decks by weaverryan

Other Decks in Technology

Transcript

  1. Who is this beach bum? • The Symfony “Docs” guy

    ! • KnpLabs US - Symfony consulting, training, Kumbaya ! • Writer for KnpUniversity.com screencasts knplabs.com github.com/weaverryan PHP Tutorial Screencasts
  2. I delivered exactly what the client asked for? needed C

    http://www.flickr.com/photos/adesigna/4090782772/
  3. Define good… - BDD/TDD is *good*, right? - Skinny controllers

    are definitely good… I think? - 80%+ test coverage - is that good?
  4. Measuring Success X*Quality - (1-X)*Speed = Success Score ! where

    X is 0-1, related to many factors X = the Quality factor
  5. 1. How much uncertainty does the project have? 2. Are

    you building what you *know* will be successful, or is it more of an experiment? 3. High Uncertainty => Low X (less quality, faster!) Uncertainty
  6. 1. Are you protecting bank data or patient records? 2.

    Or are you selling Halloween costumes for hamsters? 3. Mission Critical Features => High X (high quality, slower!) Mission Critical Features http://www.etsy.com/listing/111520104/superman-hamster-costume-hamster-pet
  7. 1. No budget? No choice, fast! 2. No budget =>

    low X (less quality, faster!) Budget
  8. 1. Shorten all the things 2. Routing 3. Querying for

    data 4. Rendering the template 5. Fixtures Speed up 6. Forms 7. Form theming 8. Service config 9. Security 10. Creating “special” services
  9. 1. Allows you to have a bundle called simply “App”

    2. Shortens many things 3. KnpRadBundle has a philosophy (optional) of only 1 bundle per project KnpRadBundle “App”
  10. 1. Automatic CRUD routes 2. Ability to remove/add more 3.

    FOSRestBundle does this well for REST controllers 4. SensioFrameworkExtraBundle allows for annotation routing KnpRadBundle Routing
  11. ! 1. Normally configured via a ParamConverter annotation 2. Optional

    if: A. You type-hint the argument B. The routing wildcard is “id” or matches the argument name SensioFrameworkExtraBundle
  12. 1. SensioFrameworkExtraBundle doesn’t work to query for an array of

    objects 2. “teams” variable can be used across all actions KnpRadBundle Resources
  13. 1. Finds the template and renders it 2. Creates it

    if it doesn’t exist 3. SensioFrameworkExtraBundle also does this, but requires an annotation KnpRadBundle
  14. Creates and binds the form Creates and binds the form

    Shortcut methods on KnpRadBundle base Controller
  15. 1. Form is created automatically for you based on the

    public getters/setters OR it finds a {ClassName}Type and uses it 2. Form is automatically bound (if PUT/ POST) KnpRadBundle Form Shortcuts
  16. 1. Uses custom form themes for Twitter Bootstrap 2. Install

    and it works 3. Comes with way too many other features, but can easily be used for *just* the form theming MopaBootstraBundle
  17. 1. Normally done with a services.yml or services.xml 2. KnpRadBundle

    automatically loads a Resources/config/services.yml Service Configuration
  18. 1. JmsDiExtraBundle saves you a little bit of time, but

    I don’t love it 2. Seems to have cache issues JmsDiExtraBundle?
  19. SensioFrameworkExtraBundle ! 1. Flexible by using voters to hold complex

    authorization logic 2. Easily add authorization and scan for it later
  20. What? Dir Doctrine Repo n/a Twig Extension Twig/ Form Type

    Form/ Form Type Extension Form/Extension/ Validation Constraint Validator/Constraints/ Security Voter Security/ Auto-Service Registration
  21. Auto-Service Registration 1. Implement ContainerAwareInterface to be passed the container

    2. Offload logic to another service to avoid bad practice of using the injected container
  22. 1 Error Notification 1. Be ok with errors, but *know*

    about them 2. Get emailed on errors (or something equivalent)* 3. Use NewRelic * http://symfony.com/doc/current/cookbook/logging/monolog_email.html
  23. 2 Preventing or Fixing Errors 1. Code safely, but not

    too safely 2. Respond to a bug with effort that is proportional to the pain it caused you 3. … so don’t freak out about every complaint
  24. 3 Behat 1. You already need to think about the

    behavior of a feature 2. Fast to write, especially “smoke screen” testing 3. Confidence that no core *behavior* is broken on each depot
  25. 4 CI / Travis 1. Develop quickly without worrying about

    tests 2. Always know if your app is in a deployable state
  26. 5 PHPStorm 1. Community-developed “Symfony” plugin 2. Autocompletion for service

    names, route names, template names, Twig functions, methods on services 3. Click directly into templates, classes behind a service
  27. 1. RADBundle developer 2. Professional nice guy 3. Helped with

    this presentation 6 Tips from Florian @docteur_klein
  28. 1. Library given you trouble? Based on the quality factor,

    consider abandoning it 2. KnpRADBundle has *many* features, not all are documented or are even a great idea. Use what works, move on quickly. 7 Abandon problems
  29. 1. Define your success metric A. How much uncertainty? B.

    Mission critical features C. Did we find any money? RAD
  30. 2. Choose your RAD Features • KnpRadBundle • SensioFrameworkExtraBundle •

    MopaBootstrapBundle • Alice+Faker • SonataAdminBundle • APYDataGridBundle • … RAD
  31. 3. Iterate Quickly and with Confidence • Error notification •

    Behat • CI / Travis • PHPStorm + Symfony Plugin • Avoid over-abstraction • Abandon failing solutions (quickly, but not too quickly) RAD