LAMP Meetup - Symfony & YUI3


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

LAMP Meetup - Symfony & YUI3

  1. 1. Dustin Whittle -
  2. 2. Who am I? Yahoo! – Application Platform + Dev Network Worked with Y! Answers, Delicious, Y! Bookmarks, Y! Widgets, Yahoo! Application Platform Working with symfony since open source symfony Core Team Member Responsible for symfony at Yahoo!
  3. 3. |
  4. 4. Users Load Balancers Frontend Apache PHP ysymfony / YUI Custom Modules APC, PEAR, PECL, Custom Extensions Backend MySQL/Oracle Web Services Ad API User API FreeBSD 4.x/6.x, Linux 2.6.x
  5. 5. Why use a frontend platform? Rasmus says “frameworks are not well suited for Y!” Build applications to requirements Do exactly what you need: no more, no less Understand that frameworks add overhead Choosing functional components is a better fit Despite choosing open source or building your own Everyone uses a framework If you use open source, you get maintenance for free
  6. 6. Why use a framework? Another software layer (ysymfony, yphp, yapache) Factors out common patterns Code Layout, Configuration, URL Routing ORM / Data Access Authentication / Security (XSS/CSRF) Form Widgets / Validation / Repopulation Internationalization / Localization Debugging and Testing utilities Encourages good design Abstraction > Consistency > Maintainability
  7. 7. YUI3 The syntax is more terse, allowing you to write more compact code using techniques like chaining. The API is selector-driven, which allows you to target page elements flexibly. The library is even more modular and granular than before, so you only put code on the page for features you need.
  8. 8. YUI3 Lighter Don't load what you don't need Don't write code more than once, use it again Easier Consistent API Base, Selector, Widget, IO/Get/DataSource Convenience each, bind, nodelist, queue, chainability, general sugar Faster Opportunity to re-factor core performance pain points
  9. 9. What is symfony? A full stack MVC Framework Written in OOP PHP5 Developed by a French company, Sensio Labs Released open source in October 2005 Licensed under MIT license A large community of active developers A unit + functional testing library, LIME
  10. 10. The Big Picture A complete platform for building web applications from frameworks PHP Framework JavaScript Framework CSS Framework UI Design Patterns + Best Practices Development Tools (logger, profiler, debugger, docs) Unit + Functional Testing Frameworks (LIME /
  11. 11. Open Source Communities
  12. 12. Who uses ysymfony/yui?
  13. 13. symfony is a cohesive and decoupled set of PHP classes
  14. 14. symfony Platform
  15. 15. The symfony framework is based on the symfony platform
  16. 16. symfony Framework
  17. 17. Model-View-Controller
  18. 18. Some people think frameworks are slow and trap you in a box.
  19. 19. Performance?
  20. 20. symfony in features MVC Design + Project/Application Structure Cascading Configuration System (YAML -> PHP) Environments – Dev, Prod, Test, QA, Staging Flexible view layer – layouts, partials, components Task/CLI System Internationalization + Localization Support Form / Widget / Validation System Security – CSRF + XSS Protection + User Management Caching – APC, Memcache, File, Database Testing Framework – LIME Unit + Functional Testing
  21. 21. Symfony vs ? Make your choice based on the requirements of the project Pick a framework or just a component
  22. 22. Getting Started pear channel-discover pear install symfony/symfony mkdir ~/dev/ysfproject; cd ~/dev/ysfproject symfony generate:project ysfproject symfony generate:app frontend symfony generate:app frontend
  23. 23. symfony CLI + Tasks
  24. 24. sfEventDispatcher // sfPatternRouting $callback = array($this, ’filterParameters‘); $dispatcher->connect(’request.filter_parameters‘, $callback); // sfWebRequest $event = new sfEvent($this, ‘request.filter_parameters’); $dispatcher->filter($event, $parameters); sfPatternRouting and sfWebRequest are decoupled « Anybody » can listen to any event
  25. 25. application.log application.throw_exception context.load_factories request.filter_parameters user.change_culture controller.page_not_found response.filter_content view.cache.filter_content *.method_not_found
  26. 26. require '/home/y/share/pear/symfony/autoload/ sfCoreAutoload.class.php'; sfCoreAutoload::register(); $dispatcher = new sfEventDispatcher(); $routing = new sfPatternRouting($dispatcher); $routing->connect(new sfRoute('hello', '/hello/:name')); $request = new sfWebRequest($dispatcher); $response = new sfWebResponse($dispatcher); $content = 'Hello '.$request->getParameter('name', 'World'); $response->setContent($content); $response->send();
  27. 27. symfony Configuration Based on YAML Support for environments prod, dev, test, qa, staging, ... Dimension System Allows easy customization of any configuration files and templates Anything can be a dimension Intl, Brand, Host, Data center Dimensions are Flexible Inheritance = Override only what you need to Dimensions can be chained together
  28. 28. homepage: url: / param: { module: common, action: homepage } item_get: url: /api/v1/item/:id param: { module: item, action: get} requirements: { id: ‘d’ }
  29. 29. frontend/modules/common/actions/actions.class.php class commonActions extends sfActions { public function executeHomepage($request) { $this->templateFooVar = ‘Hello World’; } } frontend/modules/common/templates/homepageSuccess.php <?php echo $templateFooVar; ?>
  30. 30. symfony view layer Actions can render different views, a partial, or a component (think: same controller for ajax/full view) View.yml Configures css, js, meta, layout (app/module/action) Layouts – Most web apps consist of full page and popup layout A partial is a static template fragment
  31. 31. class SigninForm extends sfForm { public function configure() { $this->setWidgets(array( 'username' => new sfWidgetFormInput(), 'password' => new sfWidgetFormInput(array('type' => 'password')), 'remember' => new sfWidgetFormInputCheckbox(), )); $this->setValidators(array( 'username' => new sfValidatorString(), 'password' => new sfValidatorString(), 'remember' => new sfValidatorBoolean(), )); $this->validatorSchema->setPostValidator(new UserValidator()); $this->widgetSchema->setNameFormat(’user[%s]'); } }
  32. 32. <form action=“<?php echo url_for(‘user/signin’);” method=“post”> <?php echo $form; ?> </form>
  33. 33. $this->form = new SigninForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('user')); if ($this->form->isValid()) { $values = $this->form->getValues(); $this->getUser()->signin($values['user']); } }
  34. 34. symfony / YUI YUI integration is provided in the form of template helpers AJAX Buttons Tabs Overlays Debug Toolbar Integration
  35. 35. Debugging Tools
  36. 36. Deployment Tools Aggregate and minify stylesheets and javascripts Rewrite templates, css, js for CDN (YCS) Generate translations for configurations + templates + js Aggregate core classes + hardcode paths + remove debug Run lint, unit, functional tests Deployment via rsync
  37. 37. LIME Unit Testing ./symfony test:unit
  38. 38. $t = new lime_test(9, new lime_output_color()); // create configuration $t->comment('check configuration'); $frontendConfiguration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true); $t->isa_ok($frontendConfiguration, 'frontendConfiguration', 'ProjectConfiguration::getApplicationConfiguration() returns a valid frontend application configuration instance.'); // check plugins enabled $t->comment('check application plugins'); $t->is_deeply($frontendConfiguration->getPlugins(), array(1 => 'sfDoctrineGuardExtraPlugin', 2 => 'sfDoctrineGuardPlugin', 3 => 'sfDoctrineManagerPlugin', 4 => 'sfDoctrinePlugin', 5 => 'sfDoctrineViewCachePlugin', 6 => 'sfFacebookPlugin', 7 => 'sfFormExtraPlugin', 10 => 'sfTaskExtraPlugin', 11 => 'ysfOpenPlugin', 12 => 'ysfYUIPlugin'), 'frontendConfiguration->getPlugins() returns a valid list of application plugins.'); // create instance $t->comment('check context instance'); $frontendContext = sfContext::createInstance($frontendConfiguration); $t->isa_ok($frontendContext, 'sfContext', 'sfContext::createInstance() returns a valid context instance from configuration.');
  39. 39. LIME Functional Testing ./symfony test:functional backend
  40. 40. $browser = new frontendTestFunctional(new sfBrowser()); $browser->get('/')-> with('view_cache')->begin()-> isCached(false)-> end()-> with('user')->begin()-> isCulture('en')-> end()-> with('request')->begin()-> isParameter('module', 'stream')-> isParameter('action', 'activity')-> end()-> with('response')->begin()-> isStatusCode(200)-> isHeader('Content-Type', 'text/html; charset=utf-8')-> checkElement('style[type="text/css"]')-> checkElement('div#y-doc')-> checkElement('div.yui-skin-sam')-> checkElement('div#y-doc div#hd')-> checkElement('div#y-doc div#hd div#nav')-> checkElement('div#y-doc div#bd')-> checkElement('div#y-doc div#bd div#y-content')-> checkElement('div#y-doc div#ft')-> checkElement('script[type="text/javascript"]')-> end();
  41. 41. YUI Unit Testing
  42. 42. YUI({combine: true, timeout: 10000}).use("node", "console", "test",function (Y) { Y.namespace("example.test"); Y.example.test.AdvancedOptionsTestCase = new Y.Test.Case({ name: "Advanced Options Tests", _should: { fail: { testFail: true }, error: { testGenericError: true }, ignore : { testIgnore: true } }, testFail : function() {"Something bad happened."); }, testGenericError : function() { throw new Error("Generic error"); }, testIgnore : function () { alert("You'll never see this."); } }); var r = new Y.Console({ verbose : true, newestOnTop : false }); r.render('#testLogger'); Y.Test.Runner.add(Y.example.test.AdvancedOptionsTestCase);; });
  43. 43. symfony Documentation Practical symfony - Jobeet The Definitive Guide to symfony The symfony Reference Guide symfony Forms in Action Doctrine ORM for PHP Cookbooks + Cheat sheets + Wiki API Documentation
  44. 44. 1_2/ A set of 24 tutorials Each tutorial is meant to last one hour, and explains the step by step development of a web application with symfony, from A to Z.
  45. 45. Support Forums IRC Mailing List
  46. 46. YUI Documentation 128 Functional Examples API Documentation
  47. 47. A  Query  Language  for  the  Web SELECT    *  FROM  INTERNET
  48. 48. Before YQL Thousands of web services that provide valuable data Require developers to read documentation and form URLs/queries. Data is isolated and can not be combined Needs combining, tweaking, shaping even after it gets to the developer.
  49. 49. Y! Open Stack – YQL SQL-Like Language Synonymous with Data access Familiar to developers Expressive enough to get the right data Self Describing - show, desc table Allows you to query, filter and join data across Web Services.
  50. 50. YQL – Open Tables Twitter Google Facebook Friendfeed Wesabe Whitepages Zillow On github -
  51. 51. Y! Developer Network – Documentation More than 275 functional examples YSlow + Performance Rules YUI Blog Mailing List @ Yahoo! Groups