Symfony Framework




David Buchmann

Confoo Vancouver, December 6, 2016

David Buchmann


Twitter: @dbu

Outline

Full HTTP framework with MVC integration and bundles

A RAD framework

A microframework

Base for Drupal 8, eZ publish, oroCRM, Silex, Laravel and other frameworks

When to use Symfony

Symfony Ecosystem

https://symfony.com/doc/current/contributing/community/releases.html#schedule

Lets get technical!

Symfony full stack framework

Directory Layout

Web

Flow

Controller

Controller

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Response;

class HelloController
{
    public function greetAction($name)
    {
        return new Response("Hello $name");
    }
}
            

Routing: Map request to controller

                # app/config/routing.yml

                hello:
                    path: /hello/{name}
                    defaults:
                        _controller: AppBundle:Hello:greet
            

View

Symfony Twig integration

$this->render(
    'AppBundle:Hello:greet.html.twig',
    array('name' => $name)
);

src/AppBundle/Resources/Views/Hello/greet.html.twig

<!DOCTYPE html>
<html>
  <head>
    <title>Welcome to ConFoo!</title>
  </head>
  <body>
    <h1>Hello: {{ name }}</h1>
  </body>
</html>
            

Reuse: There is a bundle for that!

Find existing code

Integrate KnpMarkdownBundle

composer require "knplabs/knp-markdown-bundle"
            

Add to app/AppKernel.php

$bundles = array(
    // ...
    new Knp\MarkdownBundle\KnpMarkdownBundle(),
);
            

Use it in template

{{ page.mainText|markdown }}
            

Lets talk about


Dependeny Injection

Dependeny Injection

class MyClass
{
    public function doStuff()
    {
        global $repositoy;

        return $repository->findStuff();
    }
}
            

NO!

Dependeny Injection

class MyClass
{
  public function doStuff()
  {
    return Registry::instance()
        ->get('repository')
        ->findStuff();
  }
}
            

Meh. A bit better but not good.

Dependeny Injection

class MyClass
{
    private $repository;

    public function __construct($repository)
    {
        $this->repository = $repository;
    }
    public function doStuff()
    {
        return $this->repository->findStuff();
    }
}
            

This is dependency injection!

Dependeny Injection

Symfony Dependeny Injection

Outlook

Lots of interesting components

Console, Finder, Config, Form and Validator, DomCrawler and CssSelector, EventDispatcher, Process

Major Version Changes

Thank you!



Questions / Input / Feedback ?



@dbu