ACE is methodTable based. While ActionScript remoting code style should be
not so good to replace
with a JavaScript library (not absolutely friendly), the methodTable
system used by AMFPHP developers
is a real
good 'n safe solution to preserve server side classes methods.
AJSHP for example uses an
old remoting style but
-
PHP 4 get_class_* returns everything lowercased, then a dedicated method for compatibility is required
-
use of '__' private method prefix shouldn't be a good solution if one day I need that method
-
is not possible to verify input methods variables, with PHP 5 or greater too
The methodTable solution is simple, stable, quite perfect and ACE is just compatible with AMFPHP methodTable based classes.
Differences from AMFPHP is that ACE parses only some properties of the original AMFPHP methodTable var.
Here there's a methodTable example:
<?php // example file PHPString.class.php
class PHPString {
// this simple method, if called
// from other PHP scripts, doesn't
// care about variable types
// (i.e. echo $ps->str_repeat("hello", 10);)
// however, introducing ajax and a method caller
// should be dangerous for code execution because
// every malicious user should call this method
// with different parameters, that's why
// methodTable is a simple but cool way to
// resolve class code hacks
// (did you prefere multiple input var check for every method ? ... PHP isn't strict ... )
function str_repeat($str, $repeat = 1) {
return str_repeat($str, $repeat);
}
// methodTable should be created
// out or inside the class constructor
// and should contains:
var $methodTable = array(
// one or more keys with every
// javascript / flash usable method
// and for each key should contain:
"str_repeat" => array(
// an access key that if present will be
// used by ACE only if its value is "remote"
// [ options: remote / public / private ]
// if not present ACE thinks
// that developer has defined this method as usable from everyone
// then will enable javascript to use them
"access" => "remote",
// and an arguments key
// that if is not present, ACE doesn't verify
// anything and just works with every recieved parameter.
// If present ...
"arguments" => array(
// ... should contain associative or indexed values.
// In this example str_repeat method needs two parameters, but
// only the first is required
array(
// first parameter have to be a string
// then string type will filter every other type
"type" => "string",
// first parameter have to be sent, then its required
"required" => true
),
// second parameter is an optional ... but if present ...
array(
// it has to be an int or integer variable
"type" => "int"
)
)
)
);
}
?>
Then $methodTable variable has different security levels.
Here there's a summary of those:
// complete (best security)
var $methodTable = array(
"str_repeat" => array(
"access" => "remote",
"arguments" => array(
array(
"type" => "string",
"required" => true
),
array(
"type" => "int",
"required" => false
)
)
)
);
// partial (low security)
var $methodTable = array(
"str_repeat" => array(
"arguments" => array(
array(
"type" => "string",
"required" => true
)
)
)
);
// partial (low security)
var $methodTable = array(
"str_repeat" => array(
"access" => "remote",
"arguments" => array(
array(
"required" => true
)
)
)
);
// not usefull (bad security version)
var $methodTable = array(
"str_repeat" => array(
"access" => "remote",
"arguments" => array()
)
);
// not usefull (bad security version)
var $methodTable = array(
"str_repeat" => array(
"arguments" => array()
)
);
// not usefull (bad security version)
var $methodTable = array(
"str_repeat" => array()
);
If you're not interesting about AMFPHP compatibility / portability you can use only arguments key
and write only methods you need for javascript, then the access key is not important as type parameters is.
The require key, if type is defined, is automatically created and defined as false and ACE does type check with not required variables too.
However if an argument is defined as required, ACE counts total arguments then ACE calls server class method only if client has sent at least
required vars with their defined types.
// Best dedicated ACE $methodTable
var $methodTable = array(
"genericMethodName1" => array("arguments" => array(
array("type" => "string", "required" => true),
array("type" => "int", "required" => false)
)),
"genericMethodName2" => array("arguments" => array(
array("type" => "string", "required" => true)
)),
"genericMethodName3" => array("arguments" => array(
array("type" => "bool", "required" => true)
))
);
The type key should contain one of these strings:
-
string, for a string var
-
int, integer, for an integer var
-
float, double, for a float var
-
class, object, for a class var
-
bool, boolean, for a boolean var
-
array, for an array variable
-
null, for a null variable
Every other type are managed as undefined then if you need a mixed variable you should use type "mixed".
Once you've add a methodTable variable inside your class, every choosed method will be available for ACE interaction.