welcome to the symfony2 world - fosdem 2013
DESCRIPTION
Symfony2 is more then just another PHP framework. It's backed by a community of people working together to bring innovative solutions to solve customer needs. This talk will give you an introducing to Symfony2 describing commonly used components. It will further discuss the ecosystem around Symfony2 with projects such a Symfony CMF and Vespolina.TRANSCRIPT
![Page 1: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/1.jpg)
Daniel Kucharski @inspiran_be
Lukas Smith @lsmith
Welcome to the Symfony2 World
Saturday, February 2, 13
![Page 2: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/2.jpg)
• Developer at Liip AG in Switzerland
• PHP 5.3 co-release-manager,
• Contributing to Doctrine, Symfony, PHPCR ..
Speakers
Lukas Kahwe Smith
Saturday, February 2, 13
![Page 3: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/3.jpg)
• SAP Business Consultant by day
• PHP enthusiast at night since 2000
• Co-founder of the Vespolina Ecommerce Project
Speakers
Daniel Kucharski
Saturday, February 2, 13
![Page 4: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/4.jpg)
• Symfony2 is a set of standalone, decoupled and cohesive PHP
• Symfony2 is a full-stack framework
• MIT licensed (permissive, GPL compatible)
• Compliant with , PSR-1, PSR-2, PSR-3
• https://github.com/symfony/symfony
reusable
What is Symfony2?
components
also
PSR-0
Saturday, February 2, 13
![Page 5: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/5.jpg)
• Approaching
• Most popular PHP project on github.com
• First stable release in July 2011
• LTS release with in May 2013
• Used on many big sites: ted.com, lockerz.com, opensky.com, exercise.com, wetter.de, stern.de ..
What is Symfony2?
700 contributors
5 year support
Saturday, February 2, 13
![Page 6: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/6.jpg)
Components
Saturday, February 2, 13
![Page 7: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/7.jpg)
LocaleOptionsResolver
ProcessPropertyAccess
RoutingSecuritySerializerStopwatchTemplatingTranslationValidator
Yaml
BrowserKitClassLoader
ConfigConsole
CssSelectorDomCrawler
DependencyInjectionEventDispatcher
FilesystemFinderForm
HttpFoundationHttpKernel
Saturday, February 2, 13
![Page 8: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/8.jpg)
• Easily parse and write YAML files
• Implements most of the YAML 1.2 specuse Symfony\Component\Yaml\Parser;
$yaml = new Parser();
$string = file_get_contents('foo.yml')$data = $yaml->parse($string);
# data, inlining, indenting, invalid types, objects$string = $yaml->dump($data, 2, 4, false, true);file_put_contents('bar.yml', $string);
Yaml
Saturday, February 2, 13
![Page 9: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/9.jpg)
• OO API for HTTP Request + Response
• OO API for Session incl. “flash messages”
• Supports response
$request = Request::create('/?foo=bar', 'GET');echo $request->getPathInfo();
$resp = JsonResponse::create($data, 200);
$hdrs = array('Content-Type' => 'text/plain');$resp = new StreamingResponse($callback, 404, $hdrs);$resp->send();
Http Foundation
streaming
Saturday, February 2, 13
![Page 10: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/10.jpg)
• PHP level CGI interface
• Eases integration between Symfony2, Silex, Drupal8, ezPublish5, Laravel4 .. applications
HTTP Kernel
interface HttpKernelInterface{ const MASTER_REQUEST = 1; const SUB_REQUEST = 2;
public function handle( Request $request, $type = self::MASTER_REQUEST, $catch = true );}
Saturday, February 2, 13
![Page 11: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/11.jpg)
use Symfony\Component\HttpFoundation\Request;
// 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);
HTTP Kernel
Saturday, February 2, 13
![Page 12: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/12.jpg)
DoctrineAsseticGuzzle
PHPUnitBehat
GoutteJackalope
..
Drupal 8ezPublish 5Laravel 4phpBB 3.5
PPISilex
shopware..
Component usageFrameworks / Applications Libraries / Components
Saturday, February 2, 13
![Page 13: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/13.jpg)
• , MVC framework 2nd
• Very extensible due to processing and
• Inspired by Django, Spring, Ruby on Rails
• HTTP Caching / / Reversed proxy
• Extensive documentation + debugging tools
Symfony2 Framework
HTTP framework 1st
dependency injectionevent based request
ESI
Saturday, February 2, 13
![Page 14: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/14.jpg)
• Selection of bundles, a default directory / file structure and default configuration
• Symfony Standard edition
• Symfony CMF Standard edition
• Sonata standard edition
• KNP Rad Edition
Distributions
php composer.phar create-project symfony/framework-standard-edition your-dir
Saturday, February 2, 13
![Page 15: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/15.jpg)
What is a Bundle?
Ideally, the glue code necessary to
a with the symfony2 framework (ie. configure
the Dependency Injection Container) plus any required
and
minimal connect
library
controller routes
Saturday, February 2, 13
![Page 16: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/16.jpg)
FrameworkBundleMonologBundleAsseticBundle
WebProfilerBundleTwigBundle
SwiftmailerBundleSecurityBundle
..
Core bundles
Saturday, February 2, 13
![Page 17: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/17.jpg)
KNPbundles.com
Saturday, February 2, 13
![Page 18: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/18.jpg)
FOSUserBundleSonataAdminBundle
FOSRestBundleStofDoctrineExtensionBundle
KnpMenuBundle..
NelmioApiDocBundleJMSDebuggingBundle
LiipCacheControlBundleKnpRadBundle
..
Popular bundles
Saturday, February 2, 13
![Page 19: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/19.jpg)
AsseticMonolog
Doctrine / PropelTwig
SwiftmailerPHPUnit
ImagineBehat / PHPSpec / Atoum
Buzz / GuzzleGoutte
KnpMenuJMS Serializer
The ecosystem
Core Dependencies Popular Dependencies
Saturday, February 2, 13
![Page 20: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/20.jpg)
Ecosystem
Saturday, February 2, 13
![Page 21: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/21.jpg)
Composer
Saturday, February 2, 13
![Page 22: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/22.jpg)
curl -s https://getcomposer.org/installer | phpphp composer.phar installphp composer.phar require acme/lib:1.1.* --no-updatephp composer.phar update acme/lib
Composer
• Dependency manager for PHP
• Based on SUSE Linux dependency resolver
• Register on
• Setup your own package index with Satis
packagist.org
Saturday, February 2, 13
![Page 23: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/23.jpg)
Twig
Saturday, February 2, 13
![Page 24: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/24.jpg)
• 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
Twig
Saturday, February 2, 13
![Page 25: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/25.jpg)
{% 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 %}
Twig
Saturday, February 2, 13
![Page 26: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/26.jpg)
• Cleverly handle your JS/CSS web assets
• Inspired by the Python webassets lib
• : Combine, Less, Sass ...
• : Minify, YUICompressor, ..
• Provides ways to handle cache busting
• Build assets during development or dump to static files in production
Assetic
Assets
Filters
on the fly
Saturday, February 2, 13
![Page 27: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/27.jpg)
{% stylesheets '@AcmeFooBundle/Resources/public/css/*' %} <link rel="stylesheet" href="{{ asset_url }}" />{% endstylesheets %}
{% javascripts 'bundles/acme_foo/js/*' filter='yui_js' %} <script src="{{ asset_url }}"></script>{% endjavascripts %}
Assetic
# Assetic Configurationassetic: use_controller: false #java: /usr/bin/java filters: cssrewrite: ~ # closure: # jar: %kernel.root_dir%/java/compiler.jar # yui_css: # jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar
Saturday, February 2, 13
![Page 28: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/28.jpg)
• PSR-3 compliant logging library
• Inspired by the Python logbook lib
• Handlers
• StreamHandler, RotatingFileHandler, NativeMailHandler, MongoDBHandler, ...
• FingersCrossedHandler
• Channels, Formatters, Processors
Monolog
Saturday, February 2, 13
![Page 29: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/29.jpg)
// 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');
Monolog
Saturday, February 2, 13
![Page 30: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/30.jpg)
• Hibernate inspired data mapper API
• ORM Object Relational Mapper (SQL)
• Object Document Mapper (CouchDB, MongoDB, PHPCR, OrientDB, ..)
• DBAL / Migrations / Fixtures
• Annotations, Cache, Inflector, Lexer ..
Doctrine
Saturday, February 2, 13
![Page 31: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/31.jpg)
• (De)serializing on steroids
• Handles nested (recursive) object graphs
• Fully leverage XML/JSON/.. features
• for groups, versioning
• Ability to define custom exclusion strategies and events handlers
JMS Serializer
Exclusion strategies
Saturday, February 2, 13
![Page 32: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/32.jpg)
class BlogPost{ private $title; private $content; private $date; /* @XmlList(inline = true, entry = "tag") */ private $tags; /* @Groups({"admins"}) * @XmlAttribute * @Since("1.1.0") */ private $version; /* @VirtualProperty * @SerializedName("slug") * @XmlAttribute */ public function getSlug() { .. }
..}
JMS Serializer
Saturday, February 2, 13
![Page 33: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/33.jpg)
// 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');
JMS Serializer
Saturday, February 2, 13
![Page 34: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/34.jpg)
Bridges
Saturday, February 2, 13
![Page 35: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/35.jpg)
TwigBridgeSwiftmailerBridgeMonologBridgeDoctrineBridgePropel1Bridge
Bridges
Saturday, February 2, 13
![Page 36: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/36.jpg)
Applications
Saturday, February 2, 13
![Page 37: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/37.jpg)
The Symfony CMF project makes it easier for
to add to applications built with the
Symfony2 framework. Key development principles for the
provided are , ,
and .
Symfony CMF
developers
CMS functionality
sets of bundles scalability usability
documentation testing
Saturday, February 2, 13
![Page 38: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/38.jpg)
• Follows vision of the 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
Symfony CMF
decoupled CMS
Saturday, February 2, 13
![Page 39: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/39.jpg)
• 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
A decoupled CMS
Saturday, February 2, 13
![Page 40: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/40.jpg)
• 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
Vespolina Project
scalable
Saturday, February 2, 13
![Page 41: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/41.jpg)
Vespolina Project
vespolina/vespolinaCore
vespolina/vespolinaProduct
vespolina/vespolinaProductBundle
base classes & interfaces
manager & mappings
defining managers a DI service
Framework agnostic
Saturday, February 2, 13
![Page 42: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/42.jpg)
• http://fabien.potencier.org/article/49/what-is-symfony2
• http://fabien.potencier.org/article/50/create-your-own-framework-on-top-of-the-symfony2-components-part-1
• http://symfony.com/components
• http://cmf.symfony.com/slides/
• https://speakerdeck.com/hhamon/useful-php-librarieswhy_symfony_cmf.html
References
Saturday, February 2, 13
![Page 43: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/43.jpg)
Please rate this talk on
http://joind.in/talk/view/8074
Questions?
Saturday, February 2, 13
![Page 44: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/44.jpg)
• HTTP client & framework
• Restful web service clients
• Used by Amazon AWS SDK, Drupal 8, ...
• Uses Symfony Event dispatcher
• Service descriptions
Guzzle
Saturday, February 2, 13
![Page 45: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/45.jpg)
use Guzzle\Http\Client;$client = new Client('https://api.github.com');
$request = $client->get('/user')->setAuth('user', 'pass');// Send the request and get the response$response = $request->send();
Guzzle
Saturday, February 2, 13
![Page 46: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/46.jpg)
{ "name": "Foo", "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" },...
GuzzleService Description
Saturday, February 2, 13
![Page 47: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/47.jpg)
Guzzle... "GetUserOutput": { "type": "object", "properties": { "name": { "location": "json", "type": "string" }, "age": { "location": "json", "type": "integer"...
Service Description
Saturday, February 2, 13
![Page 48: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/48.jpg)
use Guzzle\Service\Description\ServiceDescription;
$description = ServiceDescription::factory('service_description.json');$client->setDescription($description);
$command = $client->getCommand('GetUser', array('id' => 123));
$responseModel = $client->execute($command);echo $responseModel['age'];
Guzzle
Saturday, February 2, 13
![Page 49: Welcome to the Symfony2 World - FOSDEM 2013](https://reader038.vdocuments.site/reader038/viewer/2022103111/54c69a9d4a795917528b4580/html5/thumbnails/49.jpg)
• Collection of bundles to quickly create an Admin interface
• Media, News, Notification, Formatter, I18N,
Sonata Project
Saturday, February 2, 13