![]() |
|
sfAmfPlugin - 1.2.3This Plugin to handle AMF requests from Flex client frontends |
|
![]() |
32
users
Sign-in
to change your status |
This Plugin to handle AMF requests from Flex client frontends. It makes the development of Flex-Applications with Symfony more easy |
Plugin to handle AMF requests from Flex frontends. The plugin is currently based on the SabreAMF library. It makes the development and integration of Services easy.
| Name | Status | |
|---|---|---|
|
|
lead | ed.pu-tfihs <<ta>> nrekrebaH.omiT |
Copyright (c) 2008 Timo Haberkern
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 1.5.1stable | MIT license | 1.0.0stable | 12/01/2010 |
| 1.5.0stable | MIT license | 1.0.0stable | 11/01/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.5.1stable | MIT license | 1.0.0stable | 12/01/2010 |
| 1.5.0stable | MIT license | 1.0.0stable | 11/01/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.5.1stable | MIT license | 1.0.0stable | 12/01/2010 |
| 1.5.0stable | MIT license | 1.0.0stable | 11/01/2010 |
| 1.4.2stable | MIT license | 1.0.0stable | 05/08/2009 |
| 1.4.1stable | MIT license | 1.0.0stable | 01/07/2009 |
| 1.4.0stable | MIT license | 1.0.0stable | 29/06/2009 |
| 1.3.0stable | MIT license | 1.0.0stable | 05/05/2009 |
| 1.2.4stable | MIT license | 1.0.0stable | 30/04/2009 |
| 1.2.3stable | MIT license | 1.0.0stable | 16/04/2009 |
| 1.2.2stable | MIT license | 1.0.0stable | 12/04/2009 |
| 1.2.0stable | MIT license | 1.2.0stable | 09/04/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.5.1stable | MIT license | 1.0.0stable | 12/01/2010 |
| 1.5.0stable | MIT license | 1.0.0stable | 11/01/2010 |
| 1.4.2stable | MIT license | 1.0.0stable | 05/08/2009 |
| 1.4.1stable | MIT license | 1.0.0stable | 01/07/2009 |
| 1.4.0stable | MIT license | 1.0.0stable | 29/06/2009 |
| 1.3.0stable | MIT license | 1.0.0stable | 05/05/2009 |
| 1.2.4stable | MIT license | 1.0.0stable | 30/04/2009 |
| 1.2.3stable | MIT license | 1.0.0stable | 16/04/2009 |
| 1.2.2stable | MIT license | 1.0.0stable | 12/04/2009 |
| 1.2.0stable | MIT license | 1.2.0stable | 09/04/2009 |
| 1.1.0stable | MIT license | 1.1.0stable | 27/08/2008 |
| 1.0.0stable | MIT license | 1.1.0stable | 26/08/2008 |
| 0.9.4beta | MIT license | 1.1.0stable | 25/08/2008 |
| 0.9.3beta | MIT license | 1.1.0stable | 25/08/2008 |
| 0.9.2beta | MIT license | 1.1.0stable | 25/08/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 1.2.0stable | MIT license | 1.2.0stable | 09/04/2009 |
| 1.1.0stable | MIT license | 1.1.0stable | 27/08/2008 |
| 1.0.0stable | MIT license | 1.1.0stable | 26/08/2008 |
| 0.9.4beta | MIT license | 1.1.0stable | 25/08/2008 |
| 0.9.3beta | MIT license | 1.1.0stable | 25/08/2008 |
| 0.9.2beta | MIT license | 1.1.0stable | 25/08/2008 |
Fixed bug with DateTime handling of objects in Service-Browser * Improved Look and feel of the Service browser * Fixed typos in sfAdapterBase * Improved documentation
The sfAmfPlugin provides you with all you need to write symfony backends for Flex clients. The communication is done via Adobes AMF protocol. On serverside the SabreAMF library is used to encode/decode the AMF streams. For parsing the annotations the Addendum library use used
The easiest way to install the plugin is to use the plugin:install command of symfony.
$ php symfony plugin:install sfAmfPlugin
If you preffer you can use the current development version from the subversion repository (http://svn.symfony-project.com/plugins/sfAmfPlugin) instead. Copy the checked out version to the plugins folder of your project and execute the command
$ symfony cc
That's it
AMF-Client Requests are try to execute Services on the backend. Therefore you have to create a RemoteObject in Flex that has a Symfony-URL (i.e http://flextest/Test/amf).
All your services you can call will need to be saved under lib/services in your project folder. There you can add as many subfolders as you need/want. Services on Flex-Side can use package names like org.company.project.Servicename. You can use this with symfony too. All you need to do is to save this Service under lib/services/org/company/project/Servicename.php. That's it!
A service can look like this: [php] class TestService extends sfAmfService { public function getValues() { return array('value1', 'value2', 'value3'); } }
Please keep in mind that your service needs to extend the sfAmfService class. By default every public function is accessable via a AMF-Request (you can change this with annotations, see below).
Instead of creating the Services by hand, you can use the amf:create-service commandline task.
$ symfony amf:create-service [--package=...] service_name
Sample 1:
$ symfony amf:create-service User
will create the file UserService.class.php in the folder lib/services of your project
Sample 2:
$ symfony amf:create-service --package=de.shiftup.projectname User
will create the file UserService.class.php in the folder lib/services/de/shiftup/projectname of your project
But how is this service called from client side? We need an URL to do so. For symfony this means you need a module and an action. The following listing shows you how an AMF action should look like:
public function executeAmf() { $this->setLayout(false); $gateway = new sfAmfGateway(); $response = sfContext::GetInstance()->getResponse(); $response->setContent($gateway->service()); return sfView::NONE; }
The sfAmfPlugin supports both ORM-Layers of Symfony (Propel and Doctrine). So you are able to return Doctrine_Recordset, Doctrine_Collection and Propel-Objects from your service. The plugin is doing the conversion to AMF for you.
Sample:
class TestService extends sfAmfService { public function getValues() { $result = Doctrine::getTable('Menu')->findAll(); return $result; } }
You can control the behaviour of the Service via setting annotations in the DocBlock comments of the function.
By default every public funtion is accessable via a AMF-Request. With the @AmfIgnore Annotation you can set
a public function to inaccessable. If you try to access this function you get an error message.
/** * @AmfIgnore */ public function getValues() { ... }
AMF has a nice feature called class mapping. In this case your result of the PHP will be automatically mapped
to a ActionScript class on the Flex client side.
Cause Flex can not do this without some informations you have to define the ActionScript class before returning
the values from PHP. With the sfAmfPlugin you can use the AmfClassMapping annotation to define this class name.
/** * @AmfClassMapping(name="ActionScriptClassName") */ public function getValues() { ... }
Besides class mapping the AMF plugin can convert your return data in some special ActionScript data types before sending them back to the Flex-Client
If you want to transfer array data you can use the return type ArrayCollecion. If so the data will casted in a ArrayCollection on Clientside automaticaly.
/** * @AmfReturnType("ArrayCollection") */ public function getImage() { $values = array(); $values[] = ...; $values[] = ...; return $values; }
Sometimes it can be useful to transfer byte array data (i.e. images) from PHP to Flex. Therefore you can set the
returning data type of a service method to ByteArray. This is done via the @AmfReturnType annotation
/** * @AmfReturnType("ByteArray") */ public function getImage() { $image = file_get_content('path/to/image.png'); return $image; }
I like to hear from you! Maybe you have an idea how to enhance the plugin. Just send me an email!
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
