AMFBaseDeserializer tweak

View: New views
1 Messages — Rating Filter:   Alert me  

AMFBaseDeserializer tweak

by Rich Rodecker-3 :: Rate this Message:

| View Threaded | Show Only this Message

Hello,

I'm not sure which is the preferred method for communicating with the amfphp group, the mailing list or the forums (seems like both have been active), so I'm posting this here.  I added a little tweak or two to AMFBaseDeserializer->mapClass() that I'd like to share.  It basically just attempts to create an instance of a class first before checking for the class by building a file path.  


function mapClass($typeIdentifier)
{
//Check out if class exists
if($typeIdentifier == "")
{
return NULL;
}
$clazz = NULL;
$mappedClass = str_replace('.', '/', $typeIdentifier);

if($typeIdentifier == "flex.messaging.messages.CommandMessage")
{
return new CommandMessage();
}
if($typeIdentifier == "flex.messaging.messages.RemotingMessage")
{
return new RemotingMessage();
}
if($typeIdentifier == "flex.messaging.io.ArrayCollection")
{
return new ArrayCollection();
}
if(isset($GLOBALS['amfphp']['incomingClassMappings'][$typeIdentifier]))
{
$mappedClass = str_replace('.', '/', $GLOBALS['amfphp']['incomingClassMappings'][$typeIdentifier]);
}
// Depending on various settings (autoload, include_path, etc),
// we may be able to just create an instance using the given $typeIdentifier.
// If we cam, just return it and skip all the code below.
try{
$clazz =  new $typeIdentifier;
if ( $clazz != null){
return $clazz;
}
}catch(Exceptiion $e){
}
$lastPlace = strrpos('/' . $mappedClass, '/');
$classname = substr($mappedClass, $lastPlace);
$clazz = new $classname;

$include = FALSE;

if(file_exists($GLOBALS['amfphp']['customMappingsPath'] . $mappedClass . '.php'))
{
$include = $GLOBALS['amfphp']['customMappingsPath'] . $mappedClass . '.php';
}
elseif(file_exists($GLOBALS['amfphp']['customMappingsPath'] . $mappedClass . '.class.php'))
{
$include = $GLOBALS['amfphp']['customMappingsPath'] . $mappedClass . '.class.php';
}
if($include !== FALSE)
{
include_once($include);
$lastPlace = strrpos('/' . $mappedClass, '/');
$classname = substr($mappedClass, $lastPlace);
if(class_exists($classname))
{
$clazz = new $classname;
}else {
}
}
return $clazz; // return the object
}


The ArrayCollection class in the method above is just:


class ArrayCollection extends ArrayObject
{
var $_explicitType = "flex.messaging.io.ArrayCollection";
public function __construct( $config = array() )
{
parent::__construct( $config, ArrayObject::ARRAY_AS_PROPS );
}
}
?>



------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
amfphp-general mailing list
amfphp-general@...
https://lists.sourceforge.net/lists/listinfo/amfphp-general