Flex and PHP For the Flash Folks


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

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

No notes for slide

Flex and PHP For the Flash Folks

  1. 1. Flex and PHP – For the Flash Folks<br />Kevin Schroeder<br />Zend Technologies<br />
  2. 2. Join us at ZendConThe premier PHP conference!October 17-19, 2011 – Santa Clara, CA<br />Conference Themes<br />Cloud Computing<br />Learn about the latest developments in PHP Cloud infrastructure, management and application services<br />Mobile and User Experience<br />Learn how to build engaging mobile apps with the latest PHP technologies and tools<br />Enterprise and Professional PHPExplore PHP best practices, new technologies and practical tips with industry experts<br />Conference Highlights<br /><ul><li>Sessions focused on how to best develop and deploy PHP
  3. 3. Sessions designed for all knowledge levels
  4. 4. Intensive tutorials for accelerated learning
  5. 5. PHP Certification crash courses and testing
  6. 6. Exhibit hall showcasing the latest products
  7. 7. Special networking opportunities during meals and events</li></ul>www.zendcon.com<br />
  8. 8. About self::$me<br /> Past: Programming/Sys Admin<br /> Current: Technology Evangelist/Author/Composer<br /> @kpschrade<br />
  9. 9. Assumptions (rightly or wrongly)<br />You know Flash<br />You know about Flash Builder <br />You have heard about Flash Builder for PHP<br />You don’t know, or think you know, PHP <br />You do not know Zend Framework<br />
  10. 10. PHP is written in C and written for the web<br />If you wonder why PHP does something a certain way the answer will probably be found in one of those two places<br />
  11. 11. PHP<br />Dynamically typed language (not un-typed/typeless)<br />Variable values may be modified base on context<br />$data = “1two3four5”; can be worked upon as a string, integer, float or boolean.<br />Isn’t that kind of weird? Nope. See any integers?<br />GET /?data=1two3four5&data2=1 HTTP/1.1<br />Host: corp<br />Connection: keep-alive<br />Content-Length: 0<br />User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24<br />Accept-Encoding: gzip,deflate,sdch<br />Accept-Language: en-US,en;q=0.8<br />Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3<br />
  12. 12. Data types<br />String<br />Integer<br />Float<br />Boolean<br />Object<br />Resource<br />Array<br />NULL<br />
  13. 13. Language Features<br />Object Oriented Programming or Procedural (or both)<br />Namespaces<br />Exceptions<br />Reflection<br />A dozen protocols or wrappers accessible to FS ops<br />Wide range of APIs<br />Web Services<br />XML Processing (DOM & Expat)<br />Databases<br />Huge number of frameworks<br />Huge number of applications<br />
  14. 14. Functions<br /><ul><li>If you are building only a service layer, best to stick with classes and objects over procedural code</li></ul>* Only objects or arrays<br />Declaration (no return type)<br />Required parameter<br />Optional parameter<br />Parameter class type *<br />Returning a value<br />
  15. 15. Objects/Classes<br />Namespace Separator is <br />Namespace Declaration (PHP 5.3+)<br />Extending a class<br />Class Properties<br />Magic/reserved method names<br />Static Context<br />No return type<br />Calling a static element<br />
  16. 16. Application Structure/Behavior (Autoloading)<br />Class files need to be explicitly require()d unless you use an autoloader<br />Use an autoloader<br />Registered with the __autoload() method <br />If a class does not exist in the current request, it will be called to load the class file<br />Will equal “MyClass1”<br />
  17. 17. Application Structure/Behavior (Autoloading)<br />Don’t bother writing your own.<br />FBPHP already includes Zend Framework which has one<br />MyClass1.php needs to be in the include_path<br />
  18. 18. Application Structure/Behavior (Autoloading)<br />Mapping class names to files<br />Class files must be in the include_path<br />Both map to Zend/Lib/MyClass.php<br />PHP 5 Pseudo namespaces<br />PHP 5.3+ Namespaces<br />
  19. 19. Database Access<br />Extensions (mysql, mysqli, sqlsrv, oci8, etc.)<br />PDO (pdo_mysql, pdo_sqlite, pdo_ibm, etc.)<br />Don’t create a DB connection in your general purpose classes<br />Use dependency injection<br />Use a singleton/factory/adapter<br />
  20. 20. Deployment<br />PHP does not have a “required” binary distribution format like SWF, APK, IPA, etc.<br />Zend Server 5.5 beta has a new deployment feature w/ package format<br />Application is deployed as source code<br />Deployed source files should generally be kept out of the public document root<br />Configuration files should definitely be kept out of the document root<br />
  21. 21. Flash/Flex Projects<br />
  22. 22. Creating a project ( w/ PHP )<br />
  23. 23. Tie two projects together<br />Enable support<br />Set your directories<br />Select the PHP project<br />
  24. 24. Remoting<br />
  25. 25. Zend Framework<br />PHP-based framework managed by Zend Technologies<br />Framework/Component library<br />DB access/modeling<br />Service layer<br />Authentication/ACLs<br />MVC<br />A TON more<br />Used as the supported mechanism for access PHP-based services in Flash Builder for PHP<br />
  26. 26. Action Message Format<br />Protocol for serializing objects to/from a Flash player<br />Supports strong typing of data<br />Support in multiple languages<br />Support for any binary transport that ActionScript supports<br />Two versions<br />AMF0<br />AMF3<br />
  27. 27. Zend_Amf<br />A Zend Framework based component to facilitate connections to Flash<br />Two mechanisms<br />Direct Serializer<br />Used for non-service endpoints (SMTP, Stomp, File System)<br />Generally not what you will use<br />Zend_Amf_Server<br />Used for service-based endpoints<br />Manages calls to service classes similar to MVC<br />Generally what you will use<br />
  28. 28. Direct Serializer<br />Create an object<br />Create the output stream<br />Create the serializer<br />Write the object<br />Get the output from the stream<br />Weird, <br />but required<br />
  29. 29. Reading the (PHP) serialized object<br />Not just for PHP!<br />Regular binary data<br />Magic!<br />
  30. 30. PHP Application<br />Building a Service Oriented Architecture<br />Flash Application<br />Service Call 1<br />Service Call 3<br />HTTP<br />Gateway<br />Service Class 1<br />Service Class 2<br />Service Class 3<br />Service Class 4<br />
  31. 31. Steps<br />Create value object classes to represent data<br />Use PHPDoc to document data types<br />Create a service class to provide access<br />Use PHPDoc to document return types<br />Create the service in Flash Builder<br />Drag-n-drop services onto bindable components or create them directly using ActionScript<br />Profit!<br />
  32. 32. A Simple Architecture<br />Libraries and Value Objects*<br />Document Root<br />Services to expose<br />*/services is not in the include_path, otherwise value objects would go there<br />
  33. 33. Integrating into your own application<br />Define service classes <br />Bootstrap your application<br />Call Zend_Amf_Server<br />
  34. 34. Handling authentication<br />Implements Zend_Auth_Adapter_Interface<br />Create a simple auth adapter<br />Generic identity class<br />Add to gateway<br />Add role to server ACL<br />Allow only the logged in role<br />Identity object requires “role” property<br />
  35. 35. Handling Authentication (in Flash)<br />Set credentials for the service call<br />Call the service<br />
  36. 36. Method-level ACLs<br />Add method-specific resource<br />Tell Zend_Amf_Server that the ACL needs to be checked against<br />Explicitly allow for guests<br />Already allowed for logged in users<br />
  37. 37. Demo : Creating and binding a PHP endpoint<br />(slides would mean endless screen shots that would result in… well… this:<br />