This document provides an overview of a presentation about Symfony2. It introduces the two speakers, Lukas Smith and Daniel Kucharski, and discusses what Symfony2 is, its components, frameworks, distributions, ecosystem, and popular bundles. Key applications and libraries that integrate with Symfony2 are also summarized, such as Twig, Assetic, Monolog, Doctrine, JMSSerializer, Guzzle, and the Sonata Project.
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Welcome to the Symfony2 World - FOSDEM 2013
1. Welcome to the
Symfony2 World
Lukas Smith Daniel Kucharski
@lsmith @inspiran_be
Saturday, February 2, 13
2. Speakers
Lukas Kahwe Smith
• Developer at Liip AG in Switzerland
• PHP 5.3 co-release-manager,
• Contributing to Doctrine, Symfony,
PHPCR ..
Saturday, February 2, 13
3. Speakers
Daniel Kucharski
• SAP Business Consultant by day
• PHP enthusiast at night since 2000
• Co-founder of the Vespolina Ecommerce
Project
Saturday, February 2, 13
4. What is Symfony2?
• Symfony2 is a reusable set of standalone,
decoupled and cohesive PHP components
• Symfony2 is also a full-stack framework
• MIT licensed (permissive, GPL compatible)
• Compliant with PSR-0 , PSR-1, PSR-2, PSR-3
• https://github.com/symfony/symfony
Saturday, February 2, 13
5. What is Symfony2?
• Approaching 700 contributors
• Most popular PHP project on github.com
• First stable release in July 2011
• LTS release with 5 year support in May 2013
• Used on many big sites: ted.com,
lockerz.com, opensky.com, exercise.com,
wetter.de, stern.de ..
Saturday, February 2, 13
11. HTTP Kernel
use SymfonyComponentHttpFoundationRequest;
// env: prod, debug: false
$kernel = new AppKernel('prod', false);
// wrap the kernel for ESI enabled HTTP caching
$kernel = new AppCache($kernel);
// create the request from the super globals
$request = Request::createFromGlobals();
// convert request into a response
$response = $kernel->handle($request);
// send response content to the client
$response->send();
// event fired after browser has received response
$kernel->terminate($request, $response);
Saturday, February 2, 13
13. Symfony2 Framework
• HTTP framework 1st , MVC framework 2nd
• Very extensible due to event based request
processing and dependency injection
• Inspired by Django, Spring, Ruby on Rails
• HTTP Caching / ESI / Reversed proxy
• Extensive documentation + debugging tools
Saturday, February 2, 13
14. Distributions
• Selection of bundles, a default directory / file
structure and default configuration
• Symfony Standard edition
php composer.phar create-project symfony/
framework-standard-edition your-dir
• Symfony CMF Standard edition
• Sonata standard edition
• KNP Rad Edition
Saturday, February 2, 13
15. What is a Bundle?
Ideally, the minimal glue code necessary to connect
a library with the symfony2 framework (ie. configure
the Dependency Injection Container) plus any required
controller and routes
Saturday, February 2, 13
22. Composer
• Dependency manager for PHP
• Based on SUSE Linux dependency resolver
curl -s https://getcomposer.org/installer | php
php composer.phar install
php composer.phar require acme/lib:1.1.* --no-update
php composer.phar update acme/lib
• Register on packagist.org
• Setup your own package index with Satis
Saturday, February 2, 13
24. Twig
• Template language implemented in PHP
• Fast: Compiles to PHP and Javascript
• Template inheritance
• Secure: sandbox mode, output escaping
• Easily create new tags, filters and functions
• Many community extensions are available
Saturday, February 2, 13
25. Twig
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
{{ parent() }}
<style type="text/css">
.important { color: #336699; }
</style>
{% endblock %}
{% block content %}
{% if users|length > 0 %}
<ul>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
Saturday, February 2, 13
26. Assetic
• Cleverly handle your JS/CSS web assets
• Inspired by the Python webassets lib
• Assets : Combine, Less, Sass ...
• Filters : Minify,YUICompressor, ..
• Provides ways to handle cache busting
• Build assets on the fly during development
or dump to static files in production
Saturday, February 2, 13
29. Monolog
// create a log channel
$log = new Logger('name');
$fileName = 'path/to/your.log';
$handler = new StreamHandler($fileName, Logger::WARNING);
// log everything if there is at least one warning or higher
$log->pushHandler(new FingersCrossedHandler($handler);
$logger->pushHandler(new FirePHPHandler());
$socketName = 'unix:///var/log/httpd_app_log.socket';
$handler = new SocketHandler($socketName);
$handler->setPersistent(true);
$logger->pushHandler($handler, Logger::DEBUG);
// add records to the log
$log->addWarning('Foo');
$log->log(Logger::ERROR, 'Bar');
Saturday, February 2, 13
33. JMS Serializer
// sets the group exclusion strategy
$serializer->setGroups(array(‘admins’));
// sets the version exclusion strategy
// this overrides the group exclusion strategy
// need to define your own class to combine the two
$serializer->setVersion(‘1.2.0’);
$blogPost = new BlogPost($data);
$serializer->serialize($blogPost, 'json');
Saturday, February 2, 13
37. Symfony CMF
The Symfony CMF project makes it easier for developers
to add CMS functionality to applications built with the
Symfony2 framework. Key development principles for the
provided sets of bundles are scalability , usability ,
documentation and testing .
Saturday, February 2, 13
38. Symfony CMF
• Follows vision of the decoupled CMS on top of
Symfony2, PHPCR, Create.js
• CMF as target audience are CMS builders:
Drupal 8, ezPublish 5, Symfony2 devs, ..
• Stable release planned for May 2013
• http://cmf.symfony.com
• Demo at http://cmf.liip.ch
Saturday, February 2, 13
39. A decoupled CMS
• Decoupled storage, business logic, UI layers
• PHPCR is a storage API for CMS, essentially
a tree + versioning enabled document DB
• Symfony2 handles the business logic
• create.js is a glue layer that ties together
RDFa, backbone.js, inline edit + JSON-LD
Saturday, February 2, 13
40. Vespolina Project
• scalable Ecommerce application
• from a single person store
• to a multi national store.
• Decoupled components which can be used
independently of Symfony2
• Several components will go stable in Q2
• http://www.vespolina-project.org
Saturday, February 2, 13
41. Vespolina Project
vespolina/vespolinaProductBundle
defining managers a DI service
vespolina/vespolinaProduct
manager & mappings
vespolina/vespolinaCore
base classes & interfaces
Framework agnostic
Saturday, February 2, 13
43. Questions?
Please rate this talk on
http://joind.in/talk/view/8074
Saturday, February 2, 13
44. Guzzle
• HTTP client & framework
• Restful web service clients
• Used by Amazon AWS SDK, Drupal 8, ...
• Uses Symfony Event dispatcher
• Service descriptions
Saturday, February 2, 13
45. Guzzle
use GuzzleHttpClient;
$client = new Client('https://api.github.com');
$request = $client->get('/user')->setAuth('user',
'pass');
// Send the request and get the response
$response = $request->send();
Saturday, February 2, 13
46. Guzzle
{
"name": "Foo", Service Description
"apiVersion": "2012-10-14",
"baseUrl": "http://api.foo.com",
"description": "Foo is an API",
"operations": {
"GetUsers": {
"httpMethod": "GET",
"uri": "/users",
"summary": "Gets a list of users",
"responseClass": "GetUsersOutput"
},
...
Saturday, February 2, 13