Slide 1

Slide 1 text

Status about Tuesday May 4th, 2015 – Helsinki – Finland

Slide 2

Slide 2 text

WHO AM I? • Head of • Trainer & Developer • Enjoying sharer • Contributor to

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

https://sensiolabs.com

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

1.  WHAT  IS  SYMFONY   2.  WHAT’S  NEW? 6 Summary

Slide 7

Slide 7 text

7

Slide 8

Slide 8 text

8

Slide 9

Slide 9 text

WHAT  IS  SYMFONY? 9 Round  1

Slide 10

Slide 10 text

Framework Philosophy Community

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Dependency Injection BrowserKit ClassLoader Config CssSelector Debug DomCrawler Filesystem Finder HttpFoundation HttpKernel Locale Intl Icu OptionsResolver Process PropertyAccess Serializer Stopwatch Templating Translation Validator ExpressionLanguage Console yaml EventDispatcher Routing Security Form

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

https://symfony.com/roadmap

Slide 17

Slide 17 text

INTRODUCING…  THE  COMMUNITY! 17 Round  1  -­‐  What  is  Symfony

Slide 18

Slide 18 text

+1,000 code contributors

Slide 19

Slide 19 text

+700 documentation contributors

Slide 20

Slide 20 text

+2,500 community bundles

Slide 21

Slide 21 text

And many open source projects!

Slide 22

Slide 22 text

SIMPLIFY  THE  DEVS’  LIFE:   IDE  INTEGRATION 22 Round  1  -­‐  What  is  Symfony

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

SIMPLIFY  THE  DEVS’  LIFE:   EASY  INSTALLATION 24 Round  1  -­‐  What  is  Symfony

Slide 25

Slide 25 text

Easy installation with Composer

Slide 26

Slide 26 text

Easy  installation 26

Slide 27

Slide 27 text

Easy  installation  with  the  installer 27

Slide 28

Slide 28 text

THE  PHILOSOPHY   28 Round  1  -­‐  What  is  Symfony

Slide 29

Slide 29 text

# web/app.php use Symfony\Component\HttpFoundation\Request; $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);

Slide 30

Slide 30 text

30 Separation of Concerns Implementation Controller View Model Modifies the model Returns model data Renders the view The Controller analyses the user request, calls the Model and passes data to the View. The View layer formats data in a dedicated format (html, json…) The Model stores the business logic and classes that manipulate data. R Router Response Request /hello/fabien

Slide 31

Slide 31 text

30 Separation of Concerns Implementation Controller View Model Modifies the model Returns model data Renders the view The Controller analyses the user request, calls the Model and passes data to the View. The View layer formats data in a dedicated format (html, json…) The Model stores the business logic and classes that manipulate data. R Router Response Request /hello/fabien

Slide 32

Slide 32 text

30 Separation of Concerns Implementation Controller View Model Modifies the model Returns model data Renders the view The Controller analyses the user request, calls the Model and passes data to the View. The View layer formats data in a dedicated format (html, json…) The Model stores the business logic and classes that manipulate data. R Router Response Request /hello/fabien

Slide 33

Slide 33 text

VC  Framework 31

Slide 34

Slide 34 text

namespace Acme\DemoBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\[…]\Route; use Symfony\Component\HttpFoundation\Response; class DefaultController { /** @Route("/hello/{name}") */ public function indexAction($name) { return new Response('Hello '.$name); } }

Slide 35

Slide 35 text

class DefaultController extends Controller { /** @Route("/hello/{name}") */ public function indexAction($name) { return $this->render( 'AcmeDemoBundle:Default:index.html.twig', [ 'name' => $name ] ); } }

Slide 36

Slide 36 text

class DefaultController { /** * @Route("/schedule") * @Template */ public function indexAction() { return [ 'title' => 'Schedule' ]; } }

Slide 37

Slide 37 text

35 Round  1  -­‐  What  is  Symfony GREAT  TOOL  TO  CODE  FASTER:   TWIG

Slide 38

Slide 38 text

{% extends "SensioConferenceBundle::layout.html.twig" %} {% block content %}

{{ title }}

  • HTTP Caching, by Fabien Potencier
  • HipHop for PHP, by Scott Mac Vicar
  • XDebug, by Derick Rethans
  • ...
{% endblock %}

Slide 39

Slide 39 text

{% extends "SensioConferenceBundle::layout.html.twig" %} {% block title 'Conference Schedule' %} {% block content %}

{{ title }}

  • HTTP Caching, by Fabien Potencier
  • HipHop for PHP, by Scott Mac Vicar
  • XDebug, by Derick Rethans
  • ...
{% endblock %} index.html.twig

Slide 40

Slide 40 text

{% extends "::base.html.twig" %} {% block body %} {% block content '' %} {% endblock %} layout.html.twig

Slide 41

Slide 41 text

{% block title 'Welcome!' %} {% block body '' %} base.html.twig

Slide 42

Slide 42 text

base.html.twig layout.html.twig index.html.twig

Slide 43

Slide 43 text

Twig is a modern template engine for PHP ▪ Fast ▪ Concise and rich syntax ▪ Automatic output escaping ▪ Modern features ▪ Extensible

Slide 44

Slide 44 text

Twig is a modern template engine for PHP ▪ Fast ▪ Concise and rich syntax ▪ Automatic output escaping ▪ Modern features ▪ Extensible twig.sensiolabs.org

Slide 45

Slide 45 text

SIMPLIFY  THE  DEVS’  LIFE:   DEVELOPMENT  TOOLS 42 Round  1  -­‐  What  is  Symfony

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

SIMPLIFY  THE  DEVS’  LIFE:   CODE  GENERATORS 47 Round  1  -­‐  What  is  Symfony

Slide 51

Slide 51 text

$ php app/console generate:bundle

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

$ php app/console generate:doctrine:crud

Slide 54

Slide 54 text

GREAT  TOOL  TO  CODE  FASTER:   ROUTING  COMPONENT 51 Round  1  -­‐  What  is  Symfony

Slide 55

Slide 55 text

The router maps a url pattern to a set of internal parameters.

Slide 56

Slide 56 text

The router maps a url pattern to a set of internal parameters. It’s about matching a request to a callable => action

Slide 57

Slide 57 text

/** * @Route( * "/{year}/talk/{month}/{day}/{slug}", * requirements={ * "year"="\d{4}", * "month"="\d{2}", * "day"="\d{2}" * } * ) */ public function showAction($slug, $day, $month, $year) { // ... }

Slide 58

Slide 58 text

acme_blog_show: path: /{year}/talk/{month}/{day}/{slug} defaults: { _controller: AcmeBlogBundle:Blog:blog } requirements: year: "\d{4}" month: "\d{2}" day: "\d{2}" schemes: https methods: GET host: blog.my-domain.com condition: "request.headers.get('User-Agent') matches '/firefox/i'" YAML Configuration

Slide 59

Slide 59 text

AcmeBlogBundle:Blog:show \d{4} \d{2} \d{2} request.headers.get('User-Agent') matches '/firefox/i' XML Configuration

Slide 60

Slide 60 text

/** @Route("/talk/{id}") */ function showAction(Talk $talk) { // ... } Automatic Arguments Discovery

Slide 61

Slide 61 text

GREAT  TOOL  TO  CODE  FASTER:   DATABASE  HANDLING 57 Round  1  -­‐  What  is  Symfony

Slide 62

Slide 62 text

▪ Database Abstraction Layer on top of PDO ▪ Object Relational Mapper ▪ Migrations support ▪ Object Document Mapper (MongoDB) Doctrine2 Support

Slide 63

Slide 63 text

/** @ORM\Entity */ class Talk { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** @ORM\Column(length=80) */ private $title; /** @ORM\Column(type="text") */ private $synopsis; /** @ORM\Column(type="datetime") */ private $schedule; /** @ORM\ManyToMany(targetEntity="Speaker", mappedBy="talks") */ private $speakers; }

Slide 64

Slide 64 text

GREAT  TOOL  TO  CODE  FASTER:   SERVICE  CONTAINER 60 Round  1  -­‐  What  is  Symfony

Slide 65

Slide 65 text

Service != Domain object has  a  state makes  something  for  the   application

Slide 66

Slide 66 text

The service container manages initialization of objects.

Slide 67

Slide 67 text

services: user_manager: class: Acme\UserManager arguments: - "@event_dispatcher" - "@security.encoder_factory" - "@doctrine.orm.entity_manager" - "@security.context" YAML Configuration

Slide 68

Slide 68 text

XML Configuration

Slide 69

Slide 69 text

class appProdProjectContainer extends Container { protected function getUserManagerService() { $instance = new Acme\UserManager( $this->get('debug.event_dispatcher'), $this->get('security.encoder_factory'), $this->get('doctrine.orm.default_entity_manager'), $this->get('security.context') ); $this->services['user_manager'] = $instance; return $instance; } } Service Factory Method

Slide 70

Slide 70 text

$manager = $this ->container ->get('user_manager') ; Service Lazy Loading

Slide 71

Slide 71 text

GREAT  TOOL  TO  CODE  FASTER:   DATA  VALIDATION 67 Round  1  -­‐  What  is  Symfony

Slide 72

Slide 72 text

The validator component validates objects against a set of constraints.

Slide 73

Slide 73 text

/** @Assert\UniqueEntity("username") */ class User { /** * @Assert\NotBlank * @Assert\Email */ private $username; /** * @Assert\NotBlank * @Assert\Length(min = 8, max = 32) */ private $password; // ... }

Slide 74

Slide 74 text

$user = new User(); $user->setUsername('[email protected]'); $user->setPassword('changeme'); $validator = $this->get('validator'); $errors = $validator->validate($user); Validating an Object

Slide 75

Slide 75 text

GREAT  TOOL  TO  CODE  FASTER:   FORM  MANAGEMENT 71 Round  1  -­‐  What  is  Symfony

Slide 76

Slide 76 text

namespace Sensio\UserBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class UserType extends AbstractType { function buildForm(FormBuilderInterface $builder, …) { $builder ->add('username', 'email') ->add('password', 'password') ->add('submit', 'submit') ; } }

Slide 77

Slide 77 text

public function userAction(Request $request) { $user = new User(); $user->setUsername('[email protected]'); $form = $this->createForm(new UserType(), $user); $form->handleRequest($request); if ($form->isValid()) { // ... } return ['form' => $form->createView() ]; }

Slide 78

Slide 78 text

{{ form(form) }} Displaying the form

Slide 79

Slide 79 text

GREAT  TOOL  TO  CODE  FASTER:   AUTOMATED  TESTS 75 Round  1  -­‐  What  is  Symfony

Slide 80

Slide 80 text

UNIT TESTING

Slide 81

Slide 81 text

FUNCTIONAL TESTING

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

GREAT  TOOL  TO  CODE  FASTER:   HTTP  CACHING 79 Round  1  -­‐  What  is  Symfony

Slide 84

Slide 84 text

RFC2616

Slide 85

Slide 85 text

Expiration   Validation

Slide 86

Slide 86 text

class DefaultController { /** * @Template * @Cache(expires="tomorrow") */ public function indexAction() { return [ 'title' => 'Schedule' ]; } }

Slide 87

Slide 87 text

class DefaultController { /** * @Template * @Cache(maxage=120) */ public function indexAction() { return [ 'title' => 'Schedule' ]; } }

Slide 88

Slide 88 text

HTTP Reverse Proxy Caching

Slide 89

Slide 89 text

varnish-cache.org

Slide 90

Slide 90 text

Edge Side Includes

Slide 91

Slide 91 text

No ESI

Slide 92

Slide 92 text

With ESI

Slide 93

Slide 93 text

GREAT  TOOL  TO  CODE  FASTER:   INTERNATIONALISATION  /  LOCALISATION 89 Round  1  -­‐  What  is  Symfony

Slide 94

Slide 94 text

Symfony2 is great J'aime Symfony2

Slide 95

Slide 95 text

{% set message = 'Symfony2 is great' %} {{ message|trans }} {% set message = 'My name is %name%!' %} {{ message|trans({'%name%': 'Hugo'}, "hello") }}

Slide 96

Slide 96 text

GREAT  TOOL  TO  CODE  FASTER:   AUTHENTICATION  /  AUTHORIZATION 92 Round  1  -­‐  What  is  Symfony

Slide 97

Slide 97 text

Built-in authentication means •Form login/password •X509 certificate •HTTP Basic •HTTP Digest authentication

Slide 98

Slide 98 text

•FOSUserBundle •HWIOAuthBundle (Oauth) •… authentication Third party library

Slide 99

Slide 99 text

/** * @Security("has_role('ROLE_ADMIN')") */ public function editAction($id) { // granted to perform an action... } Using annotations to secure an action authorization

Slide 100

Slide 100 text

Advanced authorization method: Voters

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

WHAT’S  NEW? 98 Round  2

Slide 104

Slide 104 text

SYMFONY  3.0 99 Round  2  -­‐  What  is  new?

Slide 105

Slide 105 text

100

Slide 106

Slide 106 text

100

Slide 107

Slide 107 text

3.0

Slide 108

Slide 108 text

What  is  it  going  to  be? • Compared to 2.x? => No new feature • Removal of descending compatibility layer • Keeping the compatibility when possible • >= PHP 5.5.9

Slide 109

Slide 109 text

Symfony  2.8  LTS? • Last refactoring of the 2.X branch • Last deprecations • New features • It will be the 3.0 + descending layers of compatibility • >= PHP 5.3.9

Slide 110

Slide 110 text

How  to  handle  the  migration? • UPGRADE.md • Do not ignore the deprecation notices • grep/ack ;) • PHPStorm • • error_reporting(E_ALL–E_USER_DEPRECATED) https://knpuniversity.com/blog/upgrading-­‐symfony-­‐2.7

Slide 111

Slide 111 text

WHAT  IS  GOING  TO  CHANGE  IN   YOUR  APPLICATIONS? 105 Round  2  -­‐  What  is  new?

Slide 112

Slide 112 text

Deprecated  constants • UuidValidator::STRICT_PATTERN   • UuidValidator::LOOSE_PATTERN   • UuidValidator::STRICT_UUID_LENGTH   • FormEvents::BIND   • FormEvents::PRE_BIND   • FormEvents::POST_BIND   • Unescaper::ENCODING

Slide 113

Slide 113 text

Configuration  variables • `twig.form.resources`  becomes`twig.form_themes`   • Removal  of  `framework.csrf_protection.field_name`   • `pattern`  becomes  `path`  for  the  routes

Slide 114

Slide 114 text

Twig  templates • Removal  of  the  {% render %} tag   • Removal  of  the  {% include %} tag   • Removal  of  the  global  variable  `app.security`

Slide 115

Slide 115 text

ClassLoader • Removal  of  the  ApcUniversalClassLoader • Removal  of  the  DebugClassLoader  (use  the  Debug’s  one)   • Removal  of  the  DebugUniversalClassLoader • Removal  of  the  UniversalClassLoader  (use  Composer)

Slide 116

Slide 116 text

Dependency  Injection  Component • No  more  «  scopes  ».   • «  synchronized  »  services  disappear.   • «  factory-­‐*  »  attributes  become  «  factory  »  tags.

Slide 117

Slide 117 text

Routing • Attribut  Route::$pattern becomes  Route::$path • ApacheUrlMatcher  disappears  (mind  to  remove  it  in  your  front   controllers)

Slide 118

Slide 118 text

Console • DialogHelper  replaced  by  Question   • ProgressBarHelper  replaced  by  ProgressBar   • TableHelper  replaced  by  Table   • Removal  of  the  Application::asText()  and::asXml()   • Removal  of  the  Command::asText()  and  ::asXml()   • Removal  of  the  InputDefinition::asText()  and  ::asXml()

Slide 119

Slide 119 text

Event  Dispatcher • Removal  of  methods   • Event::setName()   • Event::getName()   • Event::getDispatcher()   • Event::setDispatcher()

Slide 120

Slide 120 text

HTTP  Kernel • Removal  of  the  leagcy  LoggerInterface • Kernel::init() disappears  for  the  __construct() • HttpCache::getEsi()replaced  by   HttpCache::getSurrogate()

Slide 121

Slide 121 text

Form  component • Form::bind()  -­‐>  Form::submit()  /  Form::handleRequest()   • No  more  Form::isBound()  neither  Form::getErrorsAsString()   • AbstractType::setDefaultOptions()   -­‐>  AbstractType::configureOptions()   • AbstractTypeExtension::setDefaultOptions()   -­‐>  AbstractTypeExtension::configureOptions()   • No  more  of  the  «  virtual  »  option

Slide 122

Slide 122 text

Locale  component • The  component  is  removed.   • Use  the  Intl  component  instead.

Slide 123

Slide 123 text

OptionsResolver  component • Removal  /  renaming  of  several   methods  of  the  OptionsResolver   class.

Slide 124

Slide 124 text

Process  component • Removal  of  the  Process::getStdin()   and  Process::setStdin()   • Refactoring  coming  up  in  2.8

Slide 125

Slide 125 text

119

Slide 126

Slide 126 text

119

Slide 127

Slide 127 text

Property  Access  component • Removal  of  the   PropertyAccess::getPropertyAccessor()

Slide 128

Slide 128 text

FrameworkBundle • Controller::getRequest() disappears.   • $this->get('request’) disappears.   • Use  the  RequestStack.

Slide 129

Slide 129 text

Security • security.context  service  disappears   • Use  the  security.token_storage
                          &  security.authorization_checker • Removal  of  the  app.security  in  Twig          -­‐>  use  is_granted()

Slide 130

Slide 130 text

Serializer • Removal  of  the  JsonDecode::getLastError()   • Removal  of  the  JsonEncode::getLastError()   • Removal  of  the  JsonEncoder::getLastError()

Slide 131

Slide 131 text

Translation • Removal  of  the   Translator::setFallbackLocale()

Slide 132

Slide 132 text

Validator • ViolationBuilder  /  ExecutionContext   -­‐>  addViolation()  replaced  by  buildViolation().   • API  BC  (use  of  the  2.5  version).   • Function  Twig  form_enctype()  disappears.   • No  more  «  type  »  option  in  the  ISBN  constraint.   • No  more  «  methods  »  option  in  the  Callback  constraint.   • No  more  «  deep  »  option    in  the  Valid  constraint.   • The  constraints  Optional  &  Required  disappear.

Slide 133

Slide 133 text

126

Slide 134

Slide 134 text

126

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

The point is to keep everyone on the road. Smooth migration!

Slide 138

Slide 138 text

128 One more thing!

Slide 139

Slide 139 text

129

Slide 140

Slide 140 text

130

Slide 141

Slide 141 text

131

Slide 142

Slide 142 text

132

Slide 143

Slide 143 text

132

Slide 144

Slide 144 text

Useful  links • http://symfony.com/roadmap   • http://symfony.com/blog/   • https://insight.sensiolabs.com/ 133

Slide 145

Slide 145 text

Thank you! @saro0h speakerdeck.com/saro0h/ This is a zero guys!