Git Product home page Git Product logo

amfphp-2.0's Introduction

Amfphp

What is Amfphp?

Amfphp is free and open source software, and an essential brick for the development of Web Applications. Amfphp is used in projects that cover a wide spectrum, from games to business applications. The role of Amfphp is to make connecting an application running in the browser with a server in the cloud as simple as possible.

Applications no longer run only on desktops, but must also be available on a variety of smartphones and tablets. It is becoming increasingly complex to code with the diversity of technologies used in these terminals. Amfphp is the best solution for creating accessible services to all terminals. Developers can focus on features unique to their projects, regardless of the communication between client and server.

Amfphp includes productivity tools in the "Back Office", a companion Web application, that contains a Service Browser, useful for testing, a Client Generator to give you functional client code, and a Profiler to measure performance.

How does it work?

Amfphp works as an entry point for your client. Your client sends a request to a PHP script on your server where Amfphp is loaded. It parses the request, loads the requested service, calls it, and returns the answer accordingly.

Amfphp is maintained by Silex Labs.

Amfphp, Simple Remoting for Web Applications

Feedback

main Amfphp website

Documentation

Forums

Source Code

Class Reference

Silex Labs

Package Contents

The Amfphp library itself Amfphp

The Back Office

The Examples Examples

The class reference

Some free Amfphp images

The license

The change log

The composer file(see getcomposer.org) Composer

amfphp-2.0's People

Contributors

arielsom avatar dannykopping avatar evaleries avatar intermedi8 avatar joshtynjala avatar lexoyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amfphp-2.0's Issues

Discovery service incorrect filename checking

Editing service file in Vim (or, I believe, some other editors) a swap file is created (.service.php.swp) which brakes discovery service.

It seems discovery service takes all file names containing ".php" instead of file names ending with ".php".

PluginManager searching in .svn folders

Hi,

It seems the PluginManager searches in .svn folders. You might want to add a fliter ($pluginName == ".svn") for SVN folders.

Fatal error: require_once() [function.require]: Failed opening required 'C:\workspace\nvwebapps\trunk\v3\server\datacapture\deploy\data\api\v3\Amfphp/Plugins//.svn/.svn.php' (include_path='.;C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library') in C:\workspace\nvwebapps\trunk\v3\server\datacapture\deploy\data\api\v3\Amfphp\Core\PluginManager.php on line 92

Thanks,
Tim

Headers?

Where in the api do you retrieve the headers sent from flash/flex/client-side? like in the legacy version i where you use the Headers static class? i don't find it documented anywhere.

maintaining valueobject namespaces

Is it possible to properly map php valueobjects (without namespace) to namespaced value object?
e.g. currently I send com.package.User (.as) from client and it is properly resolved as User (.php) but once passed back to client on response I no longer see "com.package.User" but rather "User"

Invalid Argument

Flex
public function getAmf(metodo:String, result:Function):void{
var op:Operation = bridge.getOperation(metodo) as Operation;
var async:AsyncToken = op.send();
async.addResponder(new Responder(result, defaultFaultHandler));
}

php

public function menu(){
}

return error
Invalid number of parameters for method menu in service IMP.Ipm : 0 required, 0 total, 1 provided

amf3 dynamic object Serializer bug

Dynamic object should write a reference with null classname.

}else{
$traitsInfo = array("referenceId" => count($this->className2TraitsInfo), "propertyNames" => array());
$this->className2TraitsInfo[''] = $traitsInfo;
//anonymous object. So type this as a dynamic object with no sealed members.
//U29O-traits : 1011.
$this->writeAmf3Int(0xB);
//no class name. empty string for anonymous object
$this->writeAmf3String("");
//name/value pairs for dynamic properties
foreach ($d as $key => $value) {
if ($key[0] != "\0" && $key != $explicitTypeField) { //Don't show private members or explicit type
$this->writeAmf3String($key);
$this->writeAmf3Data($value);
}
}
//empty string, marks end of dynamic members
$this->outBuffer .= "\1";
}

AMF3 typed object serialization bug

I couldn't find any bug reporting facility for AMFPHP 2.1 on the site, so I am writing here.

There is some mess with string references in the serializer. It generates invalid reference indices. I managed to illustrate that with the deserializer not being able to handle the just serialized bytestream.

In another tool, I see that the keys in the resulting object are being messed up with wrong string references in the initial bytestream. You can also see that switching to writeAmf3AnonymousObject() somehow avoids the bug.

In other words, I get this:

{["n"] = {["i"] = 1, ["_class"] = "cls", ["s"] = "a", ["b"] = true, ["cls"] = {["i"] = 1, ["_class"] = "cls", ["b"] = true}}}

instead of getting this:

{["n"] = {["i"] = 1, ["_class"] = "cls", ["s"] = "a", ["b"] = true, ["n"] = {["i"] = 1, ["_class"] = "cls", ["b"] = true}}}

As of AMFPHP, it can't even deserialize the self-made bytestream crashing on exception.

Please consider the following:

<?php

require_once dirname(__FILE__) . '/Amfphp/ClassLoader.php';

class AmfSerializerWrapper extends Amfphp_Core_Amf_Serializer {
    public function writeAmf3TypedObject($d) {
        return parent::writeAmf3TypedObject($d);
    }
    public function writeAmf3AnonymousObject($d) {
        return parent::writeAmf3AnonymousObject($d);
    }
}

class AmfDeserializerWrapper extends Amfphp_Core_Amf_Deserializer {
    public function readAmf3Object() {
        return parent::readAmf3Object();
    }
}

$emptyPacket = new Amfphp_Core_Amf_Packet();
$emptyPacket->amfVersion = Amfphp_Core_Amf_Constants::AMF3_ENCODING;

$explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;

$s = new stdClass();
$d = $s;

for ($i = 0; $i < 2; ++$i) {
    $t = new stdClass();
    $t->$explicitTypeField ='cls';
    $t->i = 1;
    $t->s = 'a';
    $t->b = true;
    $s->n = $t;
    $s = $t;
}

$serializer = new AmfSerializerWrapper($emptyPacket);
$serializer->writeAmf3TypedObject($d);
//$serializer->writeAmf3AnonymousObject($d);
$serialized = $serializer->getOutput();

$serialized = substr($serialized, 1);

$deserializer = new AmfDeserializerWrapper($serialized);
$deserialized = $deserializer->readAmf3Object();

var_dump($deserialized);

?>

$ php test.php

Fatal error: Uncaught exception 'Amfphp_Core_Exception' with message 'Undefined string reference: 6' in /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserializer.php:489
Stack trace:
#0 /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserializer.php(401): Amfphp_Core_Amf_Deserializer->readAmf3String()
#1 /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserializer.php(631): Amfphp_Core_Amf_Deserializer->readAmf3Data()
#2 /tmp/amfphp-2.1/test.php(16): Amfphp_Core_Amf_Deserializer->readAmf3Object()
#3 /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserializer.php(409): AmfDeserializerWrapper->readAmf3Object()
#4 /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserializer.php(631): Amfphp_Core_Amf_Deserializer->readAmf3Data()
#5 /tmp/amfphp-2.1/test.php(16): Amfphp_Core_Amf_Deserializer->readAmf3Object()
#6 /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserializer.php(409): AmfDeserializerWrapper->readAmf3Object()
#7 /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserial in /tmp/amfphp-2.1/Amfphp/Core/Amf/Deserializer.php on line 489

AMF version detection missing in amf Deserializer

There is implementation bug in the deserializer which also affects the AMF serialization. The version used is not detected properly so the serializer won't encode the ByteArray as a AMF3 ByteArray. I think i also have solved most of the problem, but it's up to u to implement it.

protected function readHeaders() {
    $topByte = $this->readByte(); // ignore the first two bytes --  version or something
    $secondByte = $this->readByte(); //0 for Flash,
    // This line i would think solves the version detection problem. 
    // The value value bellow will return 3 for AMF3 and null for AMF0
    $version = ($topByte & 0xFF) << 8 | $secondByte & 0xFF;
    $this->deserializedPacket->amfVersion = $version == 3 ? AMFConstants::AMF3_ENCODING :   AMFConstants::AMF0_ENCODING;

as mentioned above the version code above should detect which version of amf that is used, its mentioned in the AMF0 format specification that the first two bytes (unsigned 16-bit int) stands for the version.

Bigger value for "MAX_STORED_OBJECTS"

Constant "MAX_STORED_OBJECTS" in "Amfphp_Core_Amf_Serializer" must be a variable in order to increase size.

Edit:
I'm extending the class and using public static var to set bigger value where is needed.

Implement RESTful API service call mapping for AmfPHP

REST is one of the most common ways to consume a Web API these days. As AmfPHP is all about exposing services, it should support for RESTful API calls. This would be convenient for advanced developers and a good way to get started for newcomers to AmfPHP.

How would a RESTful API be mapped to an AmfPHP service?

Calls

Each service is considered a resource, and the HTTP methods(GET, PUT, POST, DELETE, etc.) is a service method. These methods are converted to lower case to respect usual coding conventions. What is actually done by the methods and which methods are implemented is left to the developer.

So for a example:

parameters

An array of parameters for the call is constructed from both the URL and the request body.
Suppose you want to update a user record in your database.

  • The first parameter is $id, an int value giving the id of the record. Example value: 123
  • The second parameter is an associative array with the new record values. Example value: {"firstName": "John", "surname":"Doe"}

The following calls are equivalent:

Error Codes

The developer can return an error code like with any other PHP code. For example:

header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);

Would return a 'HTTP 500 Internal Server Error' response.

Example syntax for a service

The following code is an example implementation for a 'User' Amfphp service implementing HTTP GET, PUT, POST, and DELETE calls.

    class User{
        /**
        * mapped from HTTP GET to http://yourserver.com/amfphp/User/
        * if URL is http://yourserver.com/amfphp/User/123 then $id shall be set to 123
        * load all users if $id is null
        * otherwise load user with an id equal to $id
        */
        function get($id = null){
              //TODO
        }

        /**
        * mapped from HTTP POST to http://yourserver.com/amfphp/User/
        * Creates a User
        * An array is expected, so that multiple parameters are supported.
        *  Here is an example of valid data:
        *  [ {"firstName": "John", "surname":"Doe"} ]
        */
        function post($user){
              //TODO
        }

        /**
        * mapped from HTTP PUT to http://yourserver.com/amfphp/User
        * updates a User
        * An array is expected, so that multiple parameters are supported.
        *  Here is an example of valid data:
        *  [ 123, {"firstName": "John", "surname":"Doe"} ]
        */
        function put($id, $user){
              //TODO
        }


        /**
        * mapped from HTTP DELETE to http://yourserver.com/amfphp/User/123
        * deletes a user. If the user doesn't exist, return HTTP error code.
        */
        function delete($id){
              //TODO
             header($_SERVER['SERVER_PROTOCOL'] . ' User not found', true, 500);
        }
      

    }

Data Formats

As elsewhere the content type http header is used to determine the incoming format. These are AMF or JSON by default. Amfphp shall return the data using the same format as the incoming data.

Exceptions

Exceptions shall be caught and transformed into a 'HTTP 500 Internal Server Error exception.' , unless the error code is set in the exception. In this case the passed error code shall be used as the HTTP return code.
Suppose you put the following code in your service method:

throw new Exception('Forbidden', 403);

This shall result in an HTTP 403 response.

Implementation

A .htaccess file would handle the necessary URL rewriting, and a plugin similar to the AmfphpJson plugin would handle the consequent mapping.

Here is an example .htaccess file:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?uri=%{REQUEST_URI} [QSA,L]

It shall need to be next to the entry point file(Amfphp/index.php) rather than in the plugin folder, which would be more elegant but is unfortunately impossible.

The plugin called 'AmfphpRest' shall use the existing serializer/deserializer mechanisms. It shall however need to use the FILTER_DESERIALIZED_REQUEST_HANDLER and FILTER_EXCEPTION_HANDLER filters to handle the request mapping and return codes.

Is it possible to replace serialise and deserialise methods with amf3 extension?

Hello,

We are facing performance issues in one of the old production project. We've found that the actual task/function just takes 100ms but serialise and de-serialise takes much more time than that. As its legacy project, can't change much but was curious that what if we can just change 2 methods - serialise and deserialise ...

If anyone can share their expert advise to achieve this or any other thoughts is most appreciated.

Thanks!

Low Performance

I'm using, however I'm having a poor performance to return the data.
The amfphp falls into a loop almost infinite, takes too long to process writeAmf3Array

$ret = new stdClass();
$explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
$ret->$explicitTypeField = "flex.messaging.io.ArrayCollection";
$ret->source = $yourData;
return $ret;

adding response header

Is it possible to add amf message response header with proper must understang flag via amfphp 2?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.