Welcome to the Symfony2 World - FOSDEM 2013
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Welcome to the Symfony2 World - FOSDEM 2013

  • 5,158 views
Uploaded on

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......

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,158
On Slideshare
3,780
From Embeds
1,378
Number of Embeds
7

Actions

Shares
Downloads
104
Comments
0
Likes
6

Embeds 1,378

http://mrzepinski.pl 1,182
https://twitter.com 107
http://eventifier.co 71
http://eventifier.com 7
https://www.google.pl 6
http://www.eventifier.co 4
https://www.linkedin.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Welcome to the Symfony2 World Lukas Smith Daniel Kucharski @lsmith @inspiran_beSaturday, 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 ProjectSaturday, 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/symfonySaturday, 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
  • 6. ComponentsSaturday, February 2, 13
  • 7. BrowserKit Locale ClassLoader OptionsResolver Config Process Console PropertyAccess CssSelector Routing DomCrawler Security DependencyInjection Serializer EventDispatcher Stopwatch Filesystem Templating Finder Translation Form Validator HttpFoundation Yaml HttpKernelSaturday, February 2, 13
  • 8. Yaml • Easily parse and write YAML files • Implements most of the YAML 1.2 spec use SymfonyComponentYamlParser; $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);Saturday, February 2, 13
  • 9. Http Foundation • OO API for HTTP Request + Response • OO API for Session incl. “flash messages” • Supports streaming 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();Saturday, February 2, 13
  • 10. HTTP Kernel • PHP level CGI interface • Eases integration between Symfony2, Silex, Drupal8, ezPublish5, Laravel4 .. applications 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
  • 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
  • 12. Component usage Frameworks / Applications Libraries / Components Drupal 8 Doctrine ezPublish 5 Assetic Laravel 4 Guzzle phpBB 3.5 PHPUnit PPI Behat Silex Goutte shopware Jackalope .. ..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 toolsSaturday, 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 EditionSaturday, 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 routesSaturday, February 2, 13
  • 16. Core bundles FrameworkBundle MonologBundle AsseticBundle WebProfilerBundle TwigBundle SwiftmailerBundle SecurityBundle ..Saturday, February 2, 13
  • 17. KNPbundles.comSaturday, February 2, 13
  • 18. Popular bundles FOSUserBundle SonataAdminBundle FOSRestBundle StofDoctrineExtensionBundle KnpMenuBundle .. NelmioApiDocBundle JMSDebuggingBundle LiipCacheControlBundle KnpRadBundle ..Saturday, February 2, 13
  • 19. The ecosystem Core Dependencies Popular Dependencies Assetic Imagine Monolog Behat / PHPSpec / Atoum Doctrine / Propel Buzz / Guzzle Twig Goutte Swiftmailer KnpMenu PHPUnit JMS SerializerSaturday, February 2, 13
  • 20. EcosystemSaturday, February 2, 13
  • 21. ComposerSaturday, 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 SatisSaturday, February 2, 13
  • 23. TwigSaturday, 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 availableSaturday, 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 productionSaturday, February 2, 13
  • 27. Assetic {% 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 Configuration assetic: 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.jarSaturday, February 2, 13
  • 28. Monolog • PSR-3 compliant logging library • Inspired by the Python logbook lib • Handlers • StreamHandler, RotatingFileHandler, NativeMailHandler, MongoDBHandler, ... • FingersCrossedHandler • Channels, Formatters, ProcessorsSaturday, 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
  • 30. Doctrine • Hibernate inspired data mapper API • ORM Object Relational Mapper (SQL) • Object Document Mapper (CouchDB, MongoDB, PHPCR, OrientDB, ..) • DBAL / Migrations / Fixtures • Annotations, Cache, Inflector, Lexer ..Saturday, February 2, 13
  • 31. JMS Serializer • (De)serializing on steroids • Handles nested (recursive) object graphs • Fully leverage XML/JSON/.. features • Exclusion strategies for groups, versioning • Ability to define custom exclusion strategies and events handlersSaturday, February 2, 13
  • 32. JMS Serializer 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() { .. } .. }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
  • 34. BridgesSaturday, February 2, 13
  • 35. Bridges TwigBridge SwiftmailerBridge MonologBridge DoctrineBridge Propel1BridgeSaturday, February 2, 13
  • 36. ApplicationsSaturday, 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.chSaturday, 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-LDSaturday, 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.orgSaturday, February 2, 13
  • 41. Vespolina Project vespolina/vespolinaProductBundle defining managers a DI service vespolina/vespolinaProduct manager & mappings vespolina/vespolinaCore base classes & interfaces Framework agnosticSaturday, February 2, 13
  • 42. References • 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.htmlSaturday, February 2, 13
  • 43. Questions? Please rate this talk on http://joind.in/talk/view/8074Saturday, February 2, 13
  • 44. Guzzle • HTTP client & framework • Restful web service clients • Used by Amazon AWS SDK, Drupal 8, ... • Uses Symfony Event dispatcher • Service descriptionsSaturday, 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
  • 47. Guzzle ... "GetUserOutput": { Service Description "type": "object", "properties": { "name": { "location": "json", "type": "string" }, "age": { "location": "json", "type": "integer" ...Saturday, February 2, 13
  • 48. Guzzle use GuzzleServiceDescriptionServiceDescription; $description = ServiceDescription::factory(service_description.js on); $client->setDescription($description); $command = $client->getCommand(GetUser, array(id => 123)); $responseModel = $client->execute($command); echo $responseModel[age];Saturday, February 2, 13
  • 49. Sonata Project • Collection of bundles to quickly create an Admin interface • Media, News, Notification, Formatter, I18N,Saturday, February 2, 13