+ All Categories
Home > Technology > Flex and PHP For the Flash Folks

Flex and PHP For the Flash Folks

Date post: 17-May-2015
Category:
Upload: kevin-schroeder
View: 1,269 times
Download: 4 times
Share this document with a friend
Popular Tags:
32
© All rights reserved. Zend Technologies, Inc . Flex and PHP – For the Flash Folks Kevin Schroeder Zend Technologies
Transcript
Page 1: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Flex and PHP – For the Flash FolksKevin Schroeder

Zend Technologies

Page 2: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Join us at ZendConThe premier PHP conference!

October 17-19, 2011 – Santa Clara, CA

www.zendcon.com

Conference ThemesCloud ComputingLearn about the latest developments in PHP Cloud infrastructure, management and application services

Mobile and User ExperienceLearn how to build engaging mobile apps with the latest PHP technologies and tools

Enterprise and Professional PHPExplore PHP best practices, new technologies and practical tips with industry experts

Conference Highlights•Sessions focused on how to best develop and

deploy PHP

•Sessions designed for all knowledge levels

•Intensive tutorials for accelerated learning

•PHP Certification crash courses and testing

•Exhibit hall showcasing the latest products

•Special networking opportunities during meals and

events

Page 3: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

About self::$me

Past: Programming/Sys Admin

Current: Technology Evangelist/Author/Composer

@kpschrade

Page 4: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Assumptions (rightly or wrongly)

• You know Flash

• You know about Flash Builder

• You have heard about Flash Builder for PHP

• You don’t know, or think you know, PHP

• You do not know Zend Framework

Page 5: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

PHP is written in C and written for the web

• If you wonder why PHP does something a certain way the answer will probably be found in one of those two places

Page 6: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

PHP

• Dynamically typed language (not un-typed/typeless) Variable values may be modified base on context

$data = “1two3four5”; can be worked upon as a string, integer, float or boolean.

Isn’t that kind of weird? Nope. See any integers?GET /?data=1two3four5&data2=1 HTTP/1.1Host: corpConnection: keep-aliveContent-Length: 0User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64)

AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24

Accept-Encoding: gzip,deflate,sdchAccept-Language: en-US,en;q=0.8Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Page 7: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Data types

• String

• Integer

• Float

• Boolean

• Object

• Resource

• Array

• NULL

Page 8: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Language Features

• Object Oriented Programming or Procedural (or both)

• Namespaces• Exceptions• Reflection• A dozen protocols or wrappers accessible to FS

ops• Wide range of APIs

Web Services XML Processing (DOM & Expat) Databases

• Huge number of frameworks• Huge number of applications

Page 9: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Functions

• If you are building only a service layer, best to stick with classes and objects over procedural code

* Only objects or arrays

Declaration (no return type)

Required parameter

Parameter class type *

Optional parameter

Returning a value

Page 10: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Objects/ClassesNamespace Declaration (PHP 5.3+)

Class Properties Magic/reserved

method names

Static Context

Calling a static element

No return type

Extending a class

Namespace Separator is \

Page 11: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Application Structure/Behavior (Autoloading)

• Class files need to be explicitly require()d unless you use an autoloader Use an autoloader

• Registered with the __autoload() method

If a class does not exist in the current request, it will be called to load the class file

Will equal “MyClass1”

Page 12: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Application Structure/Behavior (Autoloading)

• Don’t bother writing your own.

• FBPHP already includes Zend Framework which has one

MyClass1.php needs to be in the include_path

Page 13: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Application Structure/Behavior (Autoloading)

• Mapping class names to files

• Class files must be in the include_path

• Both map to Zend/Lib/MyClass.php

PHP 5 Pseudo namespaces

PHP 5.3+ Namespaces

Page 14: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Database Access

• Extensions (mysql, mysqli, sqlsrv, oci8, etc.)

• PDO (pdo_mysql, pdo_sqlite, pdo_ibm, etc.)

• Don’t create a DB connection in your general purpose classes Use dependency injection

Use a singleton/factory/adapter

Page 15: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Deployment

• PHP does not have a “required” binary distribution format like SWF, APK, IPA, etc. Zend Server 5.5 beta has a new deployment feature w/

package format

• Application is deployed as source code

• Deployed source files should generally be kept out of the public document root

• Configuration files should definitely be kept out of the document root

Page 16: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Flash/Flex Projects

Page 17: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Creating a project ( w/ PHP )

Page 18: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Tie two projects together

Select the PHP project

Enable support

Set your directories

Page 19: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Remoting

Page 20: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Zend Framework

• PHP-based framework managed by Zend Technologies

• Framework/Component library

• DB access/modeling

• Service layer

• Authentication/ACLs

• MVC

• A TON more

• Used as the supported mechanism for access PHP-based services in Flash Builder for PHP

Page 21: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Action Message Format

• Protocol for serializing objects to/from a Flash player

• Supports strong typing of data

• Support in multiple languages

• Support for any binary transport that ActionScript supports

• Two versions AMF0

AMF3

Page 22: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Zend_Amf

• A Zend Framework based component to facilitate connections to Flash

• Two mechanisms Direct Serializer

• Used for non-service endpoints (SMTP, Stomp, File System)

• Generally not what you will use

Zend_Amf_Server• Used for service-based endpoints

• Manages calls to service classes similar to MVC

• Generally what you will use

Page 23: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Direct Serializer

Weird, but required

Create an object

Create the output stream

Create the serializer

Write the object

Get the output from the stream

Page 24: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Reading the (PHP) serialized object

Not just for PHP!

Magic!

Regular binary data

Page 25: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

PHP Application

Building a Service Oriented Architecture

Service Class 1

Flash Application

Service Call 1

Service Call 3

Service Class 2Service Class 3Service Class 4

Gateway

HTTP

Page 26: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Steps

1. Create value object classes to represent data Use PHPDoc to document data types

2. Create a service class to provide access Use PHPDoc to document return types

3. Create the service in Flash Builder

4. Drag-n-drop services onto bindable components or create them directly using ActionScript

5. Profit!

Page 27: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

A Simple Architecture

Services to expose

Document Root

Libraries and Value Objects*

*/services is not in the include_path, otherwise value objects would go there

Page 28: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Integrating into your own application

• Define service classes

• Bootstrap your application

• Call Zend_Amf_Server

Page 29: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Handling authentication

Create a simple auth adapter

Add to gateway

Implements Zend_Auth_Adapter_Interface

Generic identity class

Identity object requires “role” property

Add role to server ACL

Allow only the logged in role

Page 30: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Handling Authentication (in Flash)

Set credentials for the service call

Call the service

Page 31: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Method-level ACLs

Already allowed for logged in users

Add method-specific resource

Explicitly allow for guests

Tell Zend_Amf_Server that the ACL needs to be checked against

Page 32: Flex and PHP For the Flash Folks

©All rights reserved. Zend Technologies, Inc.

Demo : Creating and binding a PHP endpoint(slides would mean endless screen shots that would result in… well… this:


Recommended