LAMP Meetup - Symfony & YUI3

58
Dustin Whittle - [email protected]

Transcript of LAMP Meetup - Symfony & YUI3

Page 2: LAMP Meetup - Symfony & YUI3

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!

Page 3: LAMP Meetup - Symfony & YUI3

symfony-project.com | developer.yahoo.com/yui

Page 4: LAMP Meetup - Symfony & YUI3

Users

Load Balancers

Frontend

PHPAPC, PEAR, PECL, Custom Extensions

FreeBSD 4.x/6.x, Linux 2.6.x

ysymfony / YUIApacheCustom Modules

Backend

MySQL/Oracle Web Services Ad API User API

Page 5: LAMP Meetup - Symfony & YUI3

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

Page 6: LAMP Meetup - Symfony & YUI3

Why use a framework?

Another software layer (symfony, php, apache)

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

Page 7: LAMP Meetup - Symfony & YUI3
Page 8: LAMP Meetup - Symfony & YUI3

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.

Page 9: LAMP Meetup - Symfony & YUI3

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

Page 10: LAMP Meetup - Symfony & YUI3

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

What is symfony?

Page 11: LAMP Meetup - Symfony & YUI3

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 /

Page 12: LAMP Meetup - Symfony & YUI3

Open Source Communities

Page 13: LAMP Meetup - Symfony & YUI3

Who uses ysymfony/yui?

Page 14: LAMP Meetup - Symfony & YUI3

symfony is a cohesive and decoupled set of PHP

classes

Page 15: LAMP Meetup - Symfony & YUI3

symfony Platform

Page 16: LAMP Meetup - Symfony & YUI3

The symfony framework is based on the symfony

platform

Page 17: LAMP Meetup - Symfony & YUI3

symfony Framework

Page 18: LAMP Meetup - Symfony & YUI3

Model-View-Controller

Page 19: LAMP Meetup - Symfony & YUI3
Page 20: LAMP Meetup - Symfony & YUI3

Some people think frameworks are slow and

trap you in a box.

Page 21: LAMP Meetup - Symfony & YUI3

Performance?

Page 22: LAMP Meetup - Symfony & YUI3
Page 23: LAMP Meetup - Symfony & YUI3
Page 24: LAMP Meetup - Symfony & YUI3

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

Page 25: LAMP Meetup - Symfony & YUI3

Make your choice based on the requirements of the project

Pick a framework or just a component

Symfony vs ?

Page 26: LAMP Meetup - Symfony & YUI3

Getting Started

pear channel-discover pear.symfony-project.org

pear install symfony/symfony

mkdir ~/dev/ysfproject;

cd ~/dev/ysfproject

symfony generate:project ysfproject

symfony generate:app frontend

symfony generate:app frontend

Page 27: LAMP Meetup - Symfony & YUI3

symfony CLI + Tasks

Page 28: LAMP Meetup - Symfony & YUI3

sfEventDispatcher

sfPatternRouting and sfWebRequest are decoupled

« Anybody » can listen to any event

// sfPatternRouting$callback = array($this, ’filterParameters‘);$dispatcher->connect(’request.filter_parameters‘, $callback);

// sfWebRequest$event = new sfEvent($this, ‘request.filter_parameters’);$dispatcher->filter($event, $parameters);

Page 29: LAMP Meetup - Symfony & YUI3

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

Page 30: LAMP Meetup - Symfony & YUI3

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();

Page 31: LAMP Meetup - Symfony & YUI3

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

Page 32: LAMP Meetup - Symfony & YUI3

homepage: url: / param: { module: common, action: homepage }

item_get: url: /api/v1/item/:id param: { module: item, action: get} requirements: { id: ‘\d’ }

Page 33: LAMP Meetup - Symfony & YUI3

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; ?>

Page 34: LAMP Meetup - Symfony & YUI3

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

Page 35: LAMP Meetup - Symfony & YUI3

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]'); }}

Page 36: LAMP Meetup - Symfony & YUI3

<form action=“<?php echo url_for(‘user/signin’);” method=“post”><?php echo $form; ?></form>

Page 37: LAMP Meetup - Symfony & YUI3

$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']); }}

Page 38: LAMP Meetup - Symfony & YUI3

symfony / YUI

YUI integration is provided in the form of template helpers

AJAX

Buttons

Tabs

Overlays

Debug Toolbar Integration

Page 39: LAMP Meetup - Symfony & YUI3

Debugging Tools

Page 40: LAMP Meetup - Symfony & YUI3

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

Page 41: LAMP Meetup - Symfony & YUI3

LIME Unit Testing

./symfony test:unit

Page 42: LAMP Meetup - Symfony & YUI3

$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.');

Page 43: LAMP Meetup - Symfony & YUI3

LIME Functional Testing

./symfony test:functional backend

Page 44: LAMP Meetup - Symfony & YUI3

$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();

Page 45: LAMP Meetup - Symfony & YUI3

YUI Unit Testing

Page 46: LAMP Meetup - Symfony & YUI3

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() { Y.Assert.fail("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);

Y.Test.Runner.run();});

Page 47: LAMP Meetup - Symfony & YUI3
Page 48: LAMP Meetup - Symfony & YUI3

symfony Documentation

http://www.symfony-project.org/doc/

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

Page 49: LAMP Meetup - Symfony & YUI3

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.

http://www.jobeet.org/

http://www.symfony-project.org/jobeet/1_2/

Page 50: LAMP Meetup - Symfony & YUI3

Forums

http://www.symfony-project.com/forum

IRC

irc.freenode.net/#symfony

Mailing List

[email protected]

Support

Page 51: LAMP Meetup - Symfony & YUI3
Page 52: LAMP Meetup - Symfony & YUI3

YUI Documentation

http://developer.yahoo.com/yui/3/

128 Functional Examples

API Documentation

Page 53: LAMP Meetup - Symfony & YUI3

A  Query  Language  for  the  Web

SELECT    *  FROM  INTERNET

Page 54: LAMP Meetup - Symfony & YUI3

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.

Before YQL

Page 55: LAMP Meetup - Symfony & YUI3

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.

Y! Open Stack – YQL

Page 56: LAMP Meetup - Symfony & YUI3
Page 57: LAMP Meetup - Symfony & YUI3

YQL – Open TablesTwitter

Google

Facebook

Friendfeed

Wesabe

Whitepages

Zillow

On github - http://github.com/yql/yql-tables/

Page 58: LAMP Meetup - Symfony & YUI3

More than 275 functional examples

http://developer.yahoo.com/yui/examples/

YSlow + Performance Rules

http://developer.yahoo.com/performance

YUI Blog

http://yuiblog.com/

Mailing List @ Yahoo! Groups

Y! Developer Network – Documentation