LAMP Meetup - Symfony & YUI3
Upcoming SlideShare
Loading in...5

LAMP Meetup - Symfony & YUI3






Total Views
Views on SlideShare
Embed Views



14 Embeds 174 51 46 38 14 10 3
http://localhost 2 2 2 2
http://localhost:3000 1 1 1 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    LAMP Meetup - Symfony & YUI3 LAMP Meetup - Symfony & YUI3 Presentation Transcript

    • Dustin Whittle -
    • 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!
    • |
    • 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
    • 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
    • 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
    • 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.
    • 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
    • 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
    • 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 /
    • Open Source Communities
    • Who uses ysymfony/yui?
    • symfony is a cohesive and decoupled set of PHP classes
    • symfony Platform
    • The symfony framework is based on the symfony platform
    • symfony Framework
    • Model-View-Controller
    • Some people think frameworks are slow and trap you in a box.
    • Performance?
    • 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
    • Symfony vs ? Make your choice based on the requirements of the project Pick a framework or just a component
    • 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
    • symfony CLI + Tasks
    • 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
    • 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
    • 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();
    • 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
    • homepage: url: / param: { module: common, action: homepage } item_get: url: /api/v1/item/:id param: { module: item, action: get} requirements: { id: ‘d’ }
    • 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; ?>
    • 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
    • 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]'); } }
    • <form action=“<?php echo url_for(‘user/signin’);” method=“post”> <?php echo $form; ?> </form>
    • $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']); } }
    • symfony / YUI YUI integration is provided in the form of template helpers AJAX Buttons Tabs Overlays Debug Toolbar Integration
    • Debugging Tools
    • 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
    • LIME Unit Testing ./symfony test:unit
    • $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.');
    • LIME Functional Testing ./symfony test:functional backend
    • $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();
    • YUI Unit Testing
    • 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);; });
    • 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
    • 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.
    • Support Forums IRC Mailing List
    • YUI Documentation 128 Functional Examples API Documentation
    • A  Query  Language  for  the  Web SELECT    *  FROM  INTERNET
    • 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.
    • 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.
    • YQL – Open Tables Twitter Google Facebook Friendfeed Wesabe Whitepages Zillow On github -
    • Y! Developer Network – Documentation More than 275 functional examples YSlow + Performance Rules YUI Blog Mailing List @ Yahoo! Groups