SYMFONY 2
FRAMEWORK
INTRODUCTION
Artjom Kurapov
5th April of 2013
Major PHP frameworks
 Zend
 Symfony 1  2
 Code igniter  Kohana
 CakePHP
 Yii 2
Motivation
 Singleton
 Tight coupling
 Untestable
 Premature optimized
 Indescriptive names
 Duplication
 Single responsibility
 Open for extension,
Closed for modification
 LSP
http://phpmaster.com/liskov-substitution-principle/
 Interface segregation
 Dependency inversion
Functional vs fast
http://docs.phalconphp.com/en/latest/reference/benchmark/hello-world.html
Used with
 Similar to Zend - a collection of components,
which can be a full-stack framework
 Drupal 8 is using only some of the components
 eZ Publish 5 is using a full-stack
 PHPUnit, Propel, Doctrine - use Yaml, Console
 composer = package & dependency manager
 PSR-0..3 standards affect autoloading
COMPONENTS
As seen on the web
Components & Drupal 8
HttpFoundation Request
HttpFoundation Response
HttpFoundation Session
HttpKernel
Custom HttpKernel
FULL STACK
Setup
 Download or install with composer:
composer create-project symfony/framework-standard-edition symfony/ 2.2.0
 Check for directory permissions & requirements
php ./app/check.php
 Open it in browser, get a 20mb wow effect
http://localhost/symfony/web/app_dev.php/
Still, awesome profiler
Stylish error reports
Directory structure
(Confusingasalways)
appenvironmentconfiguration
cache
config
logs
bin
src ourapplicationcode
Exove
CalendarBundle
Controller
Resourcesviews,css,imagesgohere
vendor externallibraries,usuallyincompany/projectstructure
symfony
doctrine
twig
web publicwillseeonlythispart
IDE support
High-level request flow
Low-level request flow
 Frontend bootstrap (web/app_dev.php) adds
autoloader, boots kernel, creates Request
 Kernel loads config, resolves URLto controller
 Controller loads model & view, can make a
subrequest and returns a Response
 Views usually use twig
 Models usually use doctrine
Routing with YAML
 app/config/routing.yaml
Routing with PHP
Routing with annotations
Routing - URL generation
AlsoaccessibleinviewsifyouuseTwig:
Controller
You don’t have toinherit base Controller
VIEW
Controller + direct View
Controller + View
@Template uses Controller name to figure out template path..
src/Exove/DemoBundle/Resources/views/Demo/hello.html.twig
Twig - variables
Twig - inheritance
Assetic - resource links
Might not be a good idea if you use custom less / require.js
DATABASE
Doctrine
 ORM - different headache (due to abstraction)
 multiple db engine support
 Mostly, no direct SQLs, instead - chaining
 Alternative - DoctrineQL
 Migration support
 app/config/parameters.yml
Doctrine chained select
Entity
An abstract object that gets extended with saving,
retrieving, searching interfaces…
It should not know how it is used or stored
Annotation type mapping
Getter/Setter generation
Schema generation
Controller + Model
DoctrineMigrationsBundle
Testing
 Config@app/config/config_test.yml
 Filesinsrc/*/*/Bundle/Tests
 abstractclassWebTestCaseextendsPHPUnit_Framework_TestCase
Conclusion
 Heavy and extensive
 Twig / Doctrine
 Functional with growing community

Symfony

Editor's Notes

  • #9 Rewrites globals to be testable
  • #12 Binds Request and Response together
  • #13 For legacy applications