|
|
@@ -323,6 +323,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
|
|
throw new Zend_Amf_Server_Exception('Class "' . $className . '" does not exist: '.$e->getMessage(), 0, $e);
|
|
|
}
|
|
|
// Add the new loaded class to the server.
|
|
|
+ require_once 'Zend/Amf/Server/Exception.php';
|
|
|
$this->setClass($className, $source);
|
|
|
}
|
|
|
|
|
|
@@ -340,6 +341,8 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
|
|
$params = array_merge($params, $argv);
|
|
|
}
|
|
|
|
|
|
+ $params = $this->_castParameters($info, $params);
|
|
|
+
|
|
|
if ($info instanceof Zend_Server_Reflection_Function) {
|
|
|
$func = $info->getName();
|
|
|
$this->_checkAcl(null, $func);
|
|
|
@@ -961,4 +964,85 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
|
|
{
|
|
|
return array_keys($this->_table);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Cast parameters
|
|
|
+ *
|
|
|
+ * Takes the provided parameters from the request, and attempts to cast them
|
|
|
+ * to objects, if the prototype defines any as explicit object types
|
|
|
+ *
|
|
|
+ * @param Reflection $reflectionMethod
|
|
|
+ * @param array $params
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function _castParameters($reflectionMethod, array $params)
|
|
|
+ {
|
|
|
+ $prototypes = $reflectionMethod->getPrototypes();
|
|
|
+ $nonObjectTypes = array(
|
|
|
+ 'null',
|
|
|
+ 'mixed',
|
|
|
+ 'void',
|
|
|
+ 'unknown',
|
|
|
+ 'bool',
|
|
|
+ 'boolean',
|
|
|
+ 'number',
|
|
|
+ 'int',
|
|
|
+ 'integer',
|
|
|
+ 'double',
|
|
|
+ 'float',
|
|
|
+ 'string',
|
|
|
+ 'array',
|
|
|
+ 'object',
|
|
|
+ 'stdclass',
|
|
|
+ );
|
|
|
+ $types = array();
|
|
|
+ foreach ($prototypes as $prototype) {
|
|
|
+ foreach ($prototype->getParameters() as $parameter) {
|
|
|
+ $type = $parameter->getType();
|
|
|
+ if (in_array(strtolower($type), $nonObjectTypes)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $position = $parameter->getPosition();
|
|
|
+ $types[$position] = $type;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($types)) {
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($params as $position => $value) {
|
|
|
+ if (!isset($types[$position])) {
|
|
|
+ // No specific type to cast to? done
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $type = $types[$position];
|
|
|
+
|
|
|
+ if (!class_exists($type)) {
|
|
|
+ // Not a class, apparently. done
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($value instanceof $type) {
|
|
|
+ // Already of the right type? done
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!is_array($value) && !is_object($value)) {
|
|
|
+ // Can't cast scalars to objects easily; done
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Create instance, and loop through value to set
|
|
|
+ $object = new $type;
|
|
|
+ foreach ($value as $property => $defined) {
|
|
|
+ $object->{$property} = $defined;
|
|
|
+ }
|
|
|
+
|
|
|
+ $params[$position] = $object;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
}
|