@wadearnold
      wadearnold.com
wade.arnold@t8webware.com
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
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
Digg, Wikipedia, Facebook, Stumble Upon, Flicker, Tagged,
Vimeo, iStockPhoto, FeedBurner, TechCrunch,YouTube*

                     Written in PHP

               Wordpress, Drupal, Joomla

                     Written in PHP
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
sudo apt-get install zend-framework
Why ZF?
•   Use-at-will Framework

•   Coding Standards / Testing Standards

•   BSD License (Enterprise Friendly)

•   Well Documented

•   Large Community

•   Plenty to integrate!
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.
Zend_Amf works?


•   It’s a basic RPC model

    •   SOAP, XML-RPC, REST, etc

•   Call & Response
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
Omar Gonzalez @s9tpepper
Files: Root

app/

lib/

log/

pub/

tmp/
Files: lib/

Zend/
  Acl.php
  ACL/
  Auth/
  Amf/
  ....etc.....
Files: pub/
css/
img/
js/
swf/
  main.swf

xml/
  crossdomain.xml
  gateway-config.xml

.htaccess
index.php
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
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);
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.}
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;
	 }
}
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
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.}
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.}
Object-relational mapping




Working with Doctrine, Zend Framework, and Flex
                                           Mihai Corlan
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;
}
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.  }
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();
Authentication
public function ServiceDelegateAmf(responder:IResponder):void {
	 this.responder = responder;
	 this.service =
ServiceLocator.getInstance().getRemoteObject("zendamf");
	 this.service.setCredentials("wade", "arnold");
}
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);
    }
}
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);
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;
    }
}
More Auth & ACL!

• Open ID
• Ldap
• Database
• Conditional rules
• OAuth
What’s Next?
• Better Class Loader, AMF0 complete
• Documentation
 • Adobe Evangalist, Adobe TV, DZone
• HTTP Long Pulling
• Speed
 • cache reflection
 • AMFEXT
Help?


 Issue tracker
   Mailing list
Documentation
twitter.com/wadearnold
      wadearnold.com
wade.arnold@t8webware.com

Fatc

  • 1.
    @wadearnold wadearnold.com wade.arnold@t8webware.com
  • 2.
    me? • PHP developerwho 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'veever 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
  • 5.
    Digg, Wikipedia, Facebook,Stumble Upon, Flicker, Tagged, Vimeo, iStockPhoto, FeedBurner, TechCrunch,YouTube* Written in PHP Wordpress, Drupal, Joomla Written in PHP
  • 6.
    Some of thelargest 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
  • 10.
    sudo apt-get installzend-framework
  • 13.
    Why ZF? • Use-at-will Framework • Coding Standards / Testing Standards • BSD License (Enterprise Friendly) • Well Documented • Large Community • Plenty to integrate!
  • 14.
    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.
  • 15.
    Zend_Amf works? • It’s a basic RPC model • SOAP, XML-RPC, REST, etc • Call & Response
  • 16.
    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
  • 17.
  • 19.
  • 20.
    Files: lib/ Zend/ Acl.php ACL/ Auth/ Amf/ ....etc.....
  • 21.
    Files: pub/ css/ img/ js/ swf/ main.swf xml/ crossdomain.xml gateway-config.xml .htaccess index.php
  • 22.
    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
  • 23.
    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);
  • 24.
    Hybrid site 1.<?php 2.class GatewayControllerextends 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.}
  • 30.
    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; } }
  • 31.
    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
  • 32.
    Zend_Db_Table_Abstract 1.class Model_DbTable_Census extendsZend_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.}
  • 33.
    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.}
  • 34.
    Object-relational mapping Working withDoctrine, Zend Framework, and Flex Mihai Corlan
  • 35.
    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; }
  • 36.
    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.  }
  • 37.
    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();
  • 38.
    Authentication public function ServiceDelegateAmf(responder:IResponder):void{ this.responder = responder; this.service = ServiceLocator.getInstance().getRemoteObject("zendamf"); this.service.setCredentials("wade", "arnold"); }
  • 39.
    Create Auth Adapter classRemoteUser 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); } }
  • 40.
    bootstrap $this->_server = newZend_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);
  • 41.
    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; } }
  • 42.
    More Auth &ACL! • Open ID • Ldap • Database • Conditional rules • OAuth
  • 43.
    What’s Next? • BetterClass Loader, AMF0 complete • Documentation • Adobe Evangalist, Adobe TV, DZone • HTTP Long Pulling • Speed • cache reflection • AMFEXT
  • 44.
    Help? Issue tracker Mailing list Documentation
  • 45.
    twitter.com/wadearnold wadearnold.com wade.arnold@t8webware.com