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

Best Practices in Symfony2

Best Practices in Symfony2

Andreas Hucks

October 09, 2013
Tweet

More Decks by Andreas Hucks

Other Decks in Programming

Transcript

  1. Naming Things in Symphony • Follow PSR-0, PSR-1, PSR-2 •

    Find a common scheme for your team • Be explicit • Be consistent Sonntag, 6. Oktober 13
  2. Care about your coding style • Again - follow PSR-0,

    PSR-1, PSR-2 • Use PHPCSFixer http://goo.gl/tEK4y Sonntag, 6. Oktober 13
  3. FAIL a.k.a. „because I can“ • MyCompleteAppBundle (ok for small

    projects) • MyAppNeedingGlobalResourcesBundle • MyBundleInsideAnotherBundleBundle Sonntag, 6. Oktober 13
  4. What should go into a Bundle • Bundles should be

    self-contained • Sets of Features • Examples: Forum, AdminPanel... • Configured in /app/config Sonntag, 6. Oktober 13
  5. Your config options • YAML • XML • Annotations •

    INI • PHP meh. Sonntag, 6. Oktober 13
  6. Your config options • YAML • XML • Annotations •

    INI • PHP special use cases Sonntag, 6. Oktober 13
  7. Your config options • YAML • XML • Annotations •

    INI • PHP not for everything Sonntag, 6. Oktober 13
  8. Your config options • YAML • XML • Annotations •

    INI • PHP Routing, Bundle Config, Parameters Services Validators, ORM/ODM Sonntag, 6. Oktober 13
  9. Miscellaneous • Use XML for Service Definitions • Remember you

    can use Environment Variables (Apache, Nginx, ...) • Use %kernel.root_dir% as a reference Sonntag, 6. Oktober 13
  10. PHP • Use 5.4/5.5, it‘s faster • Use APC (or

    one of the alternatives) Sonntag, 6. Oktober 13
  11. Doctrine • Activate Metadata Cache • Activate Query Cache •

    Use factory-service to register Repositories & ObjectManagers as Services • Do NOT inject the EntityManager into your entities Sonntag, 6. Oktober 13
  12. Security • Make sure there are no leaks in the

    security.yml access_control section! • Better: Check Authorization in Controller, possibly use JMSSecurityExtraBundle Sonntag, 6. Oktober 13
  13. Translation • Work with translation keys instead of full text

    to avoid breaking translations Sonntag, 6. Oktober 13