/** * Startup * * @param object $controller * @return void */ function initialize(&$controller) { $controller->isAmf = false; if (class_exists('amfdispatcher') && AmfDispatcher::active()) { $controller->isAmf = true; $controller->disableCache(); $controller->view = 'Amf.Amf'; $data = AmfDispatcher::data(); if (is_array($data) || is_object($data)) { $controller->data = $data; } } }
/** * Renders view for given action and layout. In this case the view * is our Flash application and we simply need to serialize the data * and send it back to the client. * @param string $action * @param string $layout * @param string $file * @return void */ public function render($action = null, $layout = null, $file = null) { if (!empty($this->validationErrors)) { $this->viewVars['ValidationErrors'] = $this->validationErrors; } $dispatcher = AmfDispatcher::getInstance(); $encoding = $dispatcher->request->getObjectEncoding(); $messageBody = new Zend_Amf_Value_MessageBody('/1/onResult', null, $this->viewVars); $response = new Zend_Amf_Response_Http(); $response->setObjectEncoding($encoding); $response->addAmfBody($messageBody); $response->finalize(); echo $response->getResponse(); }
/** * Startup * * @param object $controller * @return void */ function initialize(&$controller) { $controller->isAmf = false; if (class_exists('amfdispatcher') && AmfDispatcher::active()) { $controller->isAmf = true; $controller->disableCache(); $controller->view = 'Amf.Amf'; $data = AmfDispatcher::data(); if (!empty($data)) { if (is_object($data)) { $controller->data = Set::reverse($data); } elseif (Set::countDim($data) == 1) { $controller->data = array_pop($data); } else { $controller->data = $data; } } } }
function __construct(&$controller) { if (is_object($controller)) { $this->viewVars = $controller->viewVars; if (isset($controller->compress)) { $this->compress = $controller->compress; } if ($this->compress === true) { $this->compress = 30100; } $dispatcher = AmfDispatcher::getInstance(); $vars = array('binaryType', 'binaryLength', 'bigEndian', 'references', 'stored', 'types', 'requests', 'request', 'header', 'body', 'encoding'); foreach ($vars as $var) { $this->{$var} = $dispatcher->{$var}; } } if (ClassRegistry::isKeySet('amfview')) { $amf = ClassRegistry::getObject('amfview'); $this->stream = $amf->stream; $this->__hasRendered = $amf->__hasRendered; } ClassRegistry::addObject('amfview', $this); }
/** * Gets data of the given $type from an AMF3-encoded data stream * * @param string $type * @return unknown */ function __decode3($type = null) { $_this =& AmfDispatcher::getInstance(); if ($type == null) { $type = $_this->__next(1); } switch ($type) { case 'undefined': case 'null': return null; case 'bool_false': return false; case 'bool_true': return true; case 'integer': $count = 1; $int = 0; $byte = $_this->read('byte'); while (($byte & 0x80) != 0 && $count < 4) { $int <<= 7; $int |= $byte & 0x7f; $byte = $_this->read('byte'); $count++; } if ($count < 4) { $int <<= 7; $int |= $byte; } else { $int <<= 8; $int |= $byte; if (($int & 0x10000000) != 0) { $int |= 0xe0000000; } } return $int; case 'number': return $_this->read('float'); case 'str': case 'xml': return $_this->__find('str'); case 'date': $ref = $_this->read('int'); if (($ref & 0x1) == 0) { $ref = $ref >> 1; if ($ref >= count($_this->stored)) { return false; } return $_this->stored[$ref]; } //$timeOffset = ($dateref >> 1) * 6000 * -1; $date = $_this->read('float'); //$date -= $timeOffset; $_this->stored[] = $date; return $date; case 'array': list($id, $data) = $_this->__ref(); if ($data === false) { return false; } elseif ($data === null) { $id = $id >> 1; $data = array(); $_this->read('byte'); for ($i = 0; $i < $id; $i++) { $data[] = $_this->__decode3(); } $_this->stored[] = $data; return $data; } else { return $data; } case 'object': list($id, $object) = $_this->__ref(); if ($object === false) { return false; } elseif ($object === null) { $classRef = $id >> 1; $type = $classRef >> 1 & 0x3; list($classRef, $classTemplate) = $_this->__ref($classRef); if ($classTemplate === false) { return false; } elseif ($classTemplate != null) { if (is_a($classTemplate, 'itypedobject') || is_a($classTemplate, 'ITypedObject')) { $className = 'CakeClass'; } else { $className = false; } } else { $className = $_this->__decode3('str'); $classTemplate = false; } // Create the values array and store it in $stored // before reading the properties. $values = array(); $isMapped = false; if ($className) { if ($localClass == $className) { $obj = new $localClass(); $isMapped = true; } else { $obj = Set::map($values); } } else { $obj =& $values; } $_this->stored[] = $obj; // Check to see the encoding type switch ($objType) { case 2: if ($classTemplate) { $propertyNames = array_keys($classTemplate->__decode()); for ($i = 0; $i < count($propertyNames); $i++) { $values[$propertyNames[$i]] = $_this->__decode3(); } } else { // Property-value pairs do { $propertyName = $_this->read('str'); if ($propertyName != '' && !is_null($propertyName)) { $propValue = $_this->__decode3(); $values[$propertyName] = $propValue; } } while ($propertyName != ''); } break; case 1: // One single value, no propertyname. Not sure what to do with this, so following ServiceCapture's example and naming the property 'source' $values["source"] = $_this->__decode3(); break; case 0: $propertyCount = $classref >> 3; $propertyNames = array(); // First read all the propertynames, then the values for ($i = 0; $i < $propertyCount; $i++) { $propertyName = $_this->__decode3('str'); $propertyNames[] = $propertyName; } foreach ($propertyNames as $pn) { $values[$pn] = $_this->__decode3(); } break; } if ($isMapped) { foreach ($values as $k => $v) { $obj->{$k} = $v; } } else { if (is_a($obj) && method_exists($obj, 'setAMFData')) { $obj->setAMFData($values); } } return $obj; } case 'xml_string': $length = $_this->read('int') >> 1; return $_this->read($length, 'str'); break; } }
/** * undocumented function * * @return void * **/ function __construct(&$controller) { if (is_object($controller)) { $this->viewVars = $controller->viewVars; if (isset($controller->compress)) { $this->compress = $controller->compress; } if ($this->compress === true) { $this->compress = 30100; } $dispatcher = AmfDispatcher::getInstance(); $vars = array('binaryType', 'binaryLength', 'bigEndian', 'references', 'stored', 'types', 'requests', 'request', 'header', 'body', 'encoding'); foreach ($vars as $var) { $this->{$var} = $dispatcher->{$var}; } } }
/** * Returns true, only when a request containing AMF data * is successfully forwarded. * @return boolean */ public static function isActive() { $dispatcher = AmfDispatcher::getInstance(); return $dispatcher->active; }