Fatc

  • 1,410 views
Uploaded on

Slides for my may 2010 presentation at Flash in the City in NYC.

Slides for my may 2010 presentation at Flash in the City in NYC.

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
1,410
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
5

Embeds 0

No embeds

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. @wadearnold wadearnold.com wade.arnold@t8webware.com
  • 2. me? • PHP developer who became a flash’er MX • Wrote majority of Zend Amf & lots of AMFPHP • Flash Builder 4 PHP data services • Currently • Scala: Akka STM • Thrift: PHP • Hadoop: HBase, HDFS, Hive
  • 3. Every solution I've ever seen or developed in PHP feels clunky and bulky, there is no elegance or grace. Working with PHP is a bit like throwing a 10 pound concrete cube from a ten story building: You'll get where you're going fast, but it's not very elegant. ... I love PHP, and it's the right tool for some jobs. It's just an ugly, cumbersome tool that makes me cry and have nightmares. It's the new VB6 in a C dress. Fredrik Holmstrm
  • 4. Digg, Wikipedia, Facebook, Stumble Upon, Flicker, Tagged, Vimeo, iStockPhoto, FeedBurner, TechCrunch,YouTube* Written in PHP Wordpress, Drupal, Joomla Written in PHP
  • 5. Some of the largest sites on the internet -- sites you probably interact with on a daily basis -- are written in PHP. If PHP sucks so profoundly, why is it powering so much of the internet? The only conclusion I can draw is that building a compelling application is far more important than choice of language. While PHP wouldn't be my choice, and if pressed, I might argue that it should never be the choice for any rational human being sitting in front of a computer, I can't argue with the results. Jeff Atwood Coding Horror
  • 6. sudo apt-get install zend-framework
  • 7. Why ZF? • Use-at-will Framework • Coding Standards / Testing Standards • BSD License (Enterprise Friendly) • Well Documented • Large Community • Plenty to integrate!
  • 8. Why us Zend_Amf? • It handles the conversion of data types between ActionScript and PHP • Converts complex objects and supports class mapping • Access Control, Authentication, ORM, Logging, PHP controllers, another SOA endpoint.
  • 9. Zend_Amf works? • It’s a basic RPC model • SOAP, XML-RPC, REST, etc • Call & Response
  • 10. 1 1/2 year’s..... • Zend Amf Beta was released Oct ‘08 • 226 bugs fixed w/ test cases • 8 Features added • 84 outstanding features / bugs • 89% code coverage 100% method • 14 SVN committers • 3 Major refactors
  • 11. Omar Gonzalez @s9tpepper
  • 12. Files: Root app/ lib/ log/ pub/ tmp/
  • 13. Files: lib/ Zend/ Acl.php ACL/ Auth/ Amf/ ....etc.....
  • 14. Files: pub/ css/ img/ js/ swf/ main.swf xml/ crossdomain.xml gateway-config.xml .htaccess index.php
  • 15. Files: pub/.htaccess 1.RewriteEngine on 2.RewriteEngine ^(crossdomain.xml)$ pub/xml/crossdomain.xml 3.RewriteEngine ^(gateway-config.xml)$ pub/xml/gateway- config.xml 4.RewriteEngine ^.(js|ico|gif|jpg|png|xml|swf)$ index.php 5.  6.php_flag magic_quotes_gpc off 7.php_flag register_globals off 8.php_flag display_errors on 9.  10.php_value session.auto_start 0
  • 16. Files: pub/index.php 1.require_once './app/models/HelloWorld.php'; 2./** Bootstrap */ 3.  4.// Instantiate server 5.$server = new Zend_Amf_Server(); 6.$server->setProduction(false); 7.Zend_Session::start(); 8.$server->setSession(); 9.  10.$server->addDirectory(dirname(__FILE__) .'/app/models/'); 11.  12.// Add class to be reflected 13.$server->setClass('HelloWorld'); 14.$server->setClass('contact.ContactDAO'); 15.$server->setClass('contact.events.ContactDispatch'); 16.$server->setClassMap('ContactVo',"Contact"); 17.  18.// Handle request 19.$request = $server->handle(); 20.echo($request);
  • 17. Hybrid site 1.<?php 2.class GatewayController extends Zend_Controller_Action 3.{ 4.   public function indexAction() 5.   { 6.      $this->getHelper('ViewRenderer')->setNoRender();       7.      $server = new Zend_Amf_Server(); 8.      $server->addDirectory( dirname(__FILE__) . '/../ services/' ); 9.      echo($server->handle());   10.   } 11.}
  • 18. Model package com.t8.census.vo <?php { class Person [Bindable] { [RemoteClass(alias="Person")] public $id = 0; public class PersonVO public $age = ""; { public $classofworker = ""; public var id:int = 0; public $education = ""; public var age:int; public $maritalstatus = ""; public var classofworker:String; public $race = ""; public var education:String; public $sex = ""; public var maritalstatus:String; } public var race:String; public var sex:String; } }
  • 19. SQL 1.CREATE TABLE `census` ( 2.  `age` varchar(3) DEFAULT NULL, 3.  `classofworker` varchar(255) DEFAULT NULL, 4.  `education` varchar(255) DEFAULT NULL, 5.  `maritalstatus` varchar(255) DEFAULT NULL, 6.  `race` varchar(255) DEFAULT NULL, 7.  `sex` varchar(255) DEFAULT NULL, 8.  `id` int(11) NOT NULL AUTO_INCREMENT, 9.  PRIMARY KEY (`id`) 10.) ENGINE=InnoDB DEFAULT CHARSET=utf-8
  • 20. Zend_Db_Table_Abstract 1.class Model_DbTable_Census extends Zend_Db_Table_Abstract 2.{ 3.    protected $_rowClass = 'Model_Census'; 4.    protected $_name = 'census'; 5.} 1.class Model_DbTable_Census extends Zend_Db_Table_Abstract 2.{ 3.    protected $_rowClass = 'Model_Census'; 4.    protected $_name = 'census'; 5.}
  • 21. Active Record 1.class CensusService { 2.    public function getAllCensus() { 3.        $tbl = new Model_DbTable_Census(); 4.        return $tbl->fetchAll()->toArray(); 5.    } 6.  7.    public function getCensusByID( $itemID ) {     8.        $tbl = new Model_DbTable_Census(); 9.        return $tbl->find($itemID)->current(); 10.    } 11.  12.    public function createCensus( $item ) { 13.        $tbl = new Model_DbTable_Census(); 14.        $row = $tbl->fetchNew(); 15.        $row->setFromArray((array)$item); 16.        $row->save(); 17.        return $row->id; 18.    } 19.}
  • 22. Object-relational mapping Working with Doctrine, Zend Framework, and Flex Mihai Corlan
  • 23. DB Resource Plugin • Mysqli Result • Mysql Result public function getArrayCollection() { $this -> connect(); $sql = "SELECT * FROM census " . "LIMIT 100"; $result = mysql_query( $sql ) or die( "Query failed: " . mysql_error() ); return $result; }
  • 24. DUDE IT’s PHP 1.  public function getAllItems()  { 2.     $this -> connect(); 3.     $sql = "SELECT * FROM census"; 4.     $result = mysql_query( $sql ) or die( "Query failed: " . 5.       mysql_error() ); 6.   7.     $census = array(); 8.   9.     while( $row = mysql_fetch_assoc( $result ) ) { 10.      $person = new Person(); 11.      $person -> id = $row["id"]; 12.      $person -> age = $row["age"]; 13.      $person -> classofworker = $row["classofworker"]; 14.      $person -> education = $row["education"]; 15.      $person -> maritalstatus = $row["maritalstatus"];   16.      $person -> race = $row["race"]; 17.      $person -> sex = $row["sex"];   18.      19.      array_push( $census, $person ); 20.    } 21.    return $census; 22.  }
  • 25. Simple Rest spl_autoload_register(); // don't load our classes unless we use them $mode = 'debug'; // 'debug' or 'production' $server = new RestServer($mode); // $server->refreshCache(); // uncomment momentarily to clear the cache if classes change in production mode $server->addClass('TestController'); $server->addClass('ProductsController', '/products'); // adds this as a base to all the URLs in this class $server->handle();
  • 26. Authentication public function ServiceDelegateAmf(responder:IResponder):void { this.responder = responder; this.service = ServiceLocator.getInstance().getRemoteObject("zendamf"); this.service.setCredentials("wade", "arnold"); }
  • 27. Create Auth Adapter class RemoteUser extends Zend_Amf_Auth_Abstract { public function __construct($name, $role) { $this->_name = $name; $this->_role = $role; } public function authenticate() { $id = new stdClass(); $id->role = $this->_role; $id->name = $this->_name; return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $id); } }
  • 28. bootstrap $this->_server = new Zend_Amf_Server(); $this->_acl = new Zend_Acl(); $this->_server->setAuth(new RemoteUser("wade", "testrole")); $this->_acl->addRole(new Zend_Acl_Role("testrole")); $this->_acl->allow("testrole", null, null); $this->_server->setAcl($this->_acl);
  • 29. Basic Service class demo { function hello() { return "hello!"; } function hello2() { return "hello2!"; } function initAcl(Zend_Acl $acl) { $acl->allow("testrole", null, "hello"); $acl->allow("testrole2", null, "hello2"); return true; } }
  • 30. More Auth & ACL! • Open ID • Ldap • Database • Conditional rules • OAuth
  • 31. What’s Next? • Better Class Loader, AMF0 complete • Documentation • Adobe Evangalist, Adobe TV, DZone • HTTP Long Pulling • Speed • cache reflection • AMFEXT
  • 32. Help? Issue tracker Mailing list Documentation
  • 33. twitter.com/wadearnold wadearnold.com wade.arnold@t8webware.com