Exemplo n.º 1
0
 /**
  * Find if the class name is a class mapped name and return the
  * respective classname if it is.
  *
  * @param object $object
  * @return false|string $className
  */
 protected function getClassName($object)
 {
     require_once 'Maz/Amf/Parse/TypeLoader.php';
     //Check to see if the object is a typed object and we need to change
     $className = '';
     switch (true) {
         // the return class mapped name back to actionscript class name.
         case Maz_Amf_Parse_TypeLoader::getMappedClassName(get_class($object)):
             $className = Maz_Amf_Parse_TypeLoader::getMappedClassName(get_class($object));
             break;
             // Check to see if the user has defined an explicit Action Script type.
         // Check to see if the user has defined an explicit Action Script type.
         case isset($object->_explicitType):
             $className = $object->_explicitType;
             unset($object->_explicitType);
             break;
             // Check if user has defined a method for accessing the Action Script type
         // Check if user has defined a method for accessing the Action Script type
         case method_exists($object, 'getASClassName'):
             $className = $object->getASClassName();
             break;
             // No return class name is set make it a generic object
         // No return class name is set make it a generic object
         default:
             break;
     }
     if (!$className == '') {
         return $className;
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * Write object to ouput stream
  *
  * @param  mixed $data
  * @return Maz_Amf_Parse_Amf3_Serializer
  */
 public function writeObject($object)
 {
     $encoding = Maz_Amf_Constants::ET_PROPLIST;
     $className = '';
     $moreMappedFields = array();
     //Check to see if the object is a typed object and we need to change
     switch (true) {
         // the return class mapped name back to actionscript class name.
         case $className = Maz_Amf_Parse_TypeLoader::getMappedClassName(get_class($object)):
             $moreMappedFields = Maz_Amf_Parse_TypeLoader::getMoreMappedFields(get_class($object));
             break;
             // Check to see if the user has defined an explicit Action Script type.
         // Check to see if the user has defined an explicit Action Script type.
         case isset($object->_explicitType):
             $className = $object->_explicitType;
             unset($object->_explicitType);
             break;
             // Check if user has defined a method for accessing the Action Script type
         // Check if user has defined a method for accessing the Action Script type
         case method_exists($object, 'getASClassName'):
             $className = $object->getASClassName();
             break;
             // No return class name is set make it a generic object
         // No return class name is set make it a generic object
         default:
             break;
     }
     $traitsInfo = Maz_Amf_Constants::AMF3_OBJECT_ENCODING;
     $traitsInfo |= $encoding << 2;
     try {
         switch ($encoding) {
             case Maz_Amf_Constants::ET_PROPLIST:
                 $count = 0;
                 foreach ($object as $key => $value) {
                     $count++;
                 }
                 foreach ($moreMappedFields as $mappedField) {
                     $count++;
                 }
                 $traitsInfo |= $count << 4;
                 // Write the object ID
                 $this->writeInteger($traitsInfo);
                 // Write the classname
                 $this->writeString($className);
                 // Write the object Key's to the output stream
                 foreach ($object as $key => $value) {
                     $this->writeString($key);
                 }
                 foreach ($moreMappedFields as $mappedField) {
                     $this->writeString($mappedField['key']);
                 }
                 //Write the object values to the output stream.
                 foreach ($object as $key => $value) {
                     $this->writeTypeMarker($value);
                 }
                 foreach ($moreMappedFields as $mappedField) {
                     $key = $mappedField['key'];
                     $this->writeTypeMarker($object->{$key});
                 }
                 break;
             case Maz_Amf_Constants::ET_EXTERNAL:
                 require_once 'Maz/Amf/Exception.php';
                 throw new Maz_Amf_Exception('External Object Encoding not implemented');
                 break;
             default:
                 require_once 'Maz/Amf/Exception.php';
                 throw new Maz_Amf_Exception('Unknown Object Encoding type: ' . $encoding);
         }
     } catch (Exception $e) {
         require_once 'Maz/Amf/Exception.php';
         throw new Maz_Amf_Exception('Unable to writeObject output: ' . $e->getMessage());
     }
     return $this;
 }