本文整理汇总了PHP中Zend_Amf_Parse_TypeLoader类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Amf_Parse_TypeLoader类的具体用法?PHP Zend_Amf_Parse_TypeLoader怎么用?PHP Zend_Amf_Parse_TypeLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Amf_Parse_TypeLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->_server = new Zend_Amf_Server();
$this->_server->setProduction(false);
Zend_Amf_Parse_TypeLoader::resetMap();
$this->_acl = new Zend_Acl();
}
示例2: setClassMap
/**
* Map ActionScript classes to PHP classes
*
* @param string $asClass
* @param string $phpClass
* @return Zend_Amf_Server
*/
public function setClassMap($asClass, $phpClass)
{
require_once 'Zend/Amf/Parse/TypeLoader.php';
Zend_Amf_Parse_TypeLoader::setMapping($asClass, $phpClass);
return $this;
}
示例3: _phpTypeToAS
/**
* Map from PHP type name to AS type name
*
* @param string $typename PHP type name
* @return string AS type name
*/
protected function _phpTypeToAS($typename)
{
if (class_exists($typename)) {
$vars = get_class_vars($typename);
if (isset($vars['_explicitType'])) {
return $vars['_explicitType'];
}
}
if (false !== ($asname = Zend_Amf_Parse_TypeLoader::getMappedClassName($typename))) {
return $asname;
}
return $typename;
}
示例4: testClassMap
/**
* Add a class mapping and lookup the mapping to make sure
* the mapping succeeds
*/
public function testClassMap()
{
$this->_server->setClassMap('controller.test', 'Zend_Amf_testclass');
$className = Zend_Amf_Parse_TypeLoader::getMappedClassName('Zend_Amf_testclass');
$this->assertEquals('controller.test', $className);
}
示例5: writeObject
public function writeObject($object)
{
if ($this->writeObjectReference($object)) {
return $this;
}
$className = '';
switch (true) {
case $className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object)):
break;
case isset($object->_explicitType):
$className = $object->_explicitType;
break;
case method_exists($object, 'getASClassName'):
$className = $object->getASClassName();
break;
case $object instanceof stdClass:
$className = '';
break;
default:
$className = get_class($object);
break;
}
$writeTraits = true;
if (array_key_exists($className, $this->_referenceDefinitions)) {
$traitsInfo = $this->_referenceDefinitions[$className]['id'];
$encoding = $this->_referenceDefinitions[$className]['encoding'];
$propertyNames = $this->_referenceDefinitions[$className]['propertyNames'];
$traitsInfo = $traitsInfo << 2 | 0x1;
$writeTraits = false;
} else {
$propertyNames = array();
if ($className == '') {
$encoding = Zend_Amf_Constants::ET_DYNAMIC;
} else {
$encoding = Zend_Amf_Constants::ET_PROPLIST;
foreach ($object as $key => $value) {
if ($key[0] != "_") {
$propertyNames[] = $key;
}
}
}
$this->_referenceDefinitions[$className] = array('id' => count($this->_referenceDefinitions), 'encoding' => $encoding, 'propertyNames' => $propertyNames);
$traitsInfo = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
$traitsInfo |= $encoding << 2;
$traitsInfo |= count($propertyNames) << 4;
}
$this->writeInteger($traitsInfo);
if ($writeTraits) {
$this->writeString($className);
foreach ($propertyNames as $value) {
$this->writeString($value);
}
}
try {
switch ($encoding) {
case Zend_Amf_Constants::ET_PROPLIST:
foreach ($propertyNames as $key) {
$this->writeTypeMarker($object->{$key});
}
break;
case Zend_Amf_Constants::ET_DYNAMIC:
foreach ($propertyNames as $key) {
$this->writeTypeMarker($object->{$key});
}
foreach ($object as $key => $value) {
if (!in_array($key, $propertyNames) && $key[0] != "_") {
$this->writeString($key);
$this->writeTypeMarker($value);
}
}
$this->writeString('');
break;
case Zend_Amf_Constants::ET_EXTERNAL:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('External Object Encoding not implemented');
break;
default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknown Object Encoding type: ' . $encoding);
}
} catch (Exception $e) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unable to writeObject output: ' . $e->getMessage(), 0, $e);
}
return $this;
}
示例6: readObject
/**
* Read an object from the AMF stream and convert it into a PHP object
*
* @todo Rather than using an array of traitsInfo create Zend_Amf_Value_TraitsInfo
* @return object|array
*/
public function readObject()
{
$traitsInfo = $this->readInteger();
$storedObject = ($traitsInfo & 0x1) == 0;
$traitsInfo = $traitsInfo >> 1;
// Check if the Object is in the stored Objects reference table
if ($storedObject) {
$ref = $traitsInfo;
if (!isset($this->_referenceObjects[$ref])) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknown Object reference: ' . $ref);
}
$returnObject = $this->_referenceObjects[$ref];
} else {
// Check if the Object is in the stored Definistions reference table
$storedClass = ($traitsInfo & 0x1) == 0;
$traitsInfo = $traitsInfo >> 1;
if ($storedClass) {
$ref = $traitsInfo;
if (!isset($this->_referenceDefinitions[$ref])) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknows Definition reference: ' . $ref);
}
// Populate the reference attributes
$className = $this->_referenceDefinitions[$ref]['className'];
$encoding = $this->_referenceDefinitions[$ref]['encoding'];
$propertyNames = $this->_referenceDefinitions[$ref]['propertyNames'];
} else {
// The class was not in the reference tables. Start reading rawdata to build traits.
// Create a traits table. Zend_Amf_Value_TraitsInfo would be ideal
$className = $this->readString();
$encoding = $traitsInfo & 0x3;
$propertyNames = array();
$traitsInfo = $traitsInfo >> 2;
}
// We now have the object traits defined in variables. Time to go to work:
if (!$className) {
// No class name generic object
$returnObject = new stdClass();
} else {
// Defined object
// Typed object lookup agsinst registered classname maps
if ($loader = Zend_Amf_Parse_TypeLoader::loadType($className)) {
$returnObject = new $loader();
} else {
//user defined typed object
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Typed object not found: ' . $className . ' ');
}
}
// Add the Object ot the reference table
$this->_referenceObjects[] = $returnObject;
$properties = array();
// clear value
// Check encoding types for additional processing.
switch ($encoding) {
case Zend_Amf_Constants::ET_EXTERNAL:
// Externalizable object such as {ArrayCollection} and {ObjectProxy}
if (!$storedClass) {
$this->_referenceDefinitions[] = array('className' => $className, 'encoding' => $encoding, 'propertyNames' => $propertyNames);
}
$returnObject->externalizedData = $this->readTypeMarker();
break;
case Zend_Amf_Constants::ET_DYNAMIC:
// used for Name-value encoding
if (!$storedClass) {
$this->_referenceDefinitions[] = array('className' => $className, 'encoding' => $encoding, 'propertyNames' => $propertyNames);
}
// not a refrence object read name value properties from byte stream
do {
$property = $this->readString();
if ($property != "") {
$propertyNames[] = $property;
$properties[$property] = $this->readTypeMarker();
}
} while ($property != "");
break;
default:
// basic property list object.
if (!$storedClass) {
$count = $traitsInfo;
// Number of properties in the list
for ($i = 0; $i < $count; $i++) {
$propertyNames[] = $this->readString();
}
// Add a refrence to the class.
$this->_referenceDefinitions[] = array('className' => $className, 'encoding' => $encoding, 'propertyNames' => $propertyNames);
}
foreach ($propertyNames as $property) {
$properties[$property] = $this->readTypeMarker();
}
break;
}
// Add properties back to the return object.
//.........这里部分代码省略.........
示例7: setClassMap
/**
* Map ActionScript classes to PHP classes
*
* @param string $asClass
* @param string $phpClass
* @return Zend_Amf_Server
*/
public function setClassMap($asClass, $phpClass)
{
Zend_Amf_Parse_TypeLoader::setMapping($asClass, $phpClass);
return $this;
}
示例8: testAmf0TypedObjecDeserializedToNativePHPObject
public function testAmf0TypedObjecDeserializedToNativePHPObject()
{
Zend_Amf_Parse_TypeLoader::setMapping("ContactVO", "Contact");
$myRequest = file_get_contents(dirname(__FILE__) . '/Request/mock/typedObjectAmf0Request.bin');
// send the mock object request to be deserialized
$this->_request->initialize($myRequest);
// Make sure that no headers where recieved
$this->assertEquals(0, sizeof($this->_request->getAmfHeaders()));
// Make sure that the message body was set after deserialization
$this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
$bodies = $this->_request->getAmfBodies();
$this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
$data = $bodies[0]->getData();
// Make sure that we are dealing with a PHP simpleXml element
$this->assertTrue($data[0] instanceof Contact);
// Make sure that the xml was deserialized properly and check its value
$this->assertEquals('arnold', (string) $data[0]->lastname);
}
示例9: testUnknownClassMap
public function testUnknownClassMap()
{
$class = Zend_Amf_Parse_TypeLoader::loadType('com.example.vo.Bogus');
$this->assertEquals('stdClass', $class);
}
示例10: writeObject
/**
* Write object to ouput stream
*
* @param mixed $data
* @return Zend_Amf_Parse_Amf3_Serializer
*/
public function writeObject($object)
{
$encoding = Zend_Amf_Constants::ET_PROPLIST;
$className = '';
//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 = Zend_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;
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 = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
$traitsInfo |= $encoding << 2;
try {
switch ($encoding) {
case Zend_Amf_Constants::ET_PROPLIST:
$count = 0;
foreach ($object as $key => $value) {
if ($key[0] != "_") {
$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) {
if ($key[0] != "_") {
$this->writeString($key);
}
}
//Write the object values to the output stream.
foreach ($object as $key => $value) {
if ($key[0] != "_") {
$this->writeTypeMarker($value);
}
}
break;
case Zend_Amf_Constants::ET_EXTERNAL:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('External Object Encoding not implemented');
break;
default:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknown Object Encoding type: ' . $encoding);
}
} catch (Exception $e) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unable to writeObject output: ' . $e->getMessage());
}
return $this;
}
示例11: testCtxNoParse
/**
* Defining new unknown resource type, handler has no parse()
*
*/
public function testCtxNoParse()
{
Zend_Amf_Parse_TypeLoader::setResourceLoader(new Zend_Amf_TestResourceLoader("3"));
try {
$resp = $this->_callService("returnCtx");
} catch (Zend_Amf_Server_Exception $e) {
$this->assertContains("Could not call parse()", $e->getMessage());
return;
}
$this->fail("Failed to throw exception on unknown resource");
}
示例12: readObject
public function readObject()
{
$traitsInfo = $this->readInteger();
$storedObject = ($traitsInfo & 0x1) == 0;
$traitsInfo = $traitsInfo >> 1;
if ($storedObject) {
$ref = $traitsInfo;
if (!isset($this->_referenceObjects[$ref])) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknown Object reference: ' . $ref);
}
$returnObject = $this->_referenceObjects[$ref];
} else {
$storedClass = ($traitsInfo & 0x1) == 0;
$traitsInfo = $traitsInfo >> 1;
if ($storedClass) {
$ref = $traitsInfo;
if (!isset($this->_referenceDefinitions[$ref])) {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Unknows Definition reference: ' . $ref);
}
$className = $this->_referenceDefinitions[$ref]['className'];
$encoding = $this->_referenceDefinitions[$ref]['encoding'];
$propertyNames = $this->_referenceDefinitions[$ref]['propertyNames'];
} else {
$className = $this->readString();
$encoding = $traitsInfo & 0x3;
$propertyNames = array();
$traitsInfo = $traitsInfo >> 2;
}
if (!$className) {
$returnObject = new stdClass();
} else {
if ($loader = Zend_Amf_Parse_TypeLoader::loadType($className)) {
$returnObject = new $loader();
} else {
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Typed object not found: ' . $className . ' ');
}
}
$this->_referenceObjects[] = $returnObject;
$properties = array();
switch ($encoding) {
case Zend_Amf_Constants::ET_EXTERNAL:
if (!$storedClass) {
$this->_referenceDefinitions[] = array('className' => $className, 'encoding' => $encoding, 'propertyNames' => $propertyNames);
}
$returnObject->externalizedData = $this->readTypeMarker();
break;
case Zend_Amf_Constants::ET_DYNAMIC:
if (!$storedClass) {
$this->_referenceDefinitions[] = array('className' => $className, 'encoding' => $encoding, 'propertyNames' => $propertyNames);
}
do {
$property = $this->readString();
if ($property != "") {
$propertyNames[] = $property;
$properties[$property] = $this->readTypeMarker();
}
} while ($property != "");
break;
default:
if (!$storedClass) {
$count = $traitsInfo;
for ($i = 0; $i < $count; $i++) {
$propertyNames[] = $this->readString();
}
$this->_referenceDefinitions[] = array('className' => $className, 'encoding' => $encoding, 'propertyNames' => $propertyNames);
}
foreach ($propertyNames as $property) {
$properties[$property] = $this->readTypeMarker();
}
break;
}
foreach ($properties as $key => $value) {
if ($key) {
$returnObject->{$key} = $value;
}
}
}
if ($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
if (isset($returnObject->externalizedData)) {
$returnObject = $returnObject->externalizedData;
} else {
$returnObject = get_object_vars($returnObject);
}
}
return $returnObject;
}
示例13: writeObject
/**
* Write object to ouput stream
*
* @param mixed $data
* @return Zend_Amf_Parse_Amf3_Serializer
*/
public function writeObject($object)
{
if ($this->writeObjectReference($object)) {
return $this;
}
$className = '';
//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 = Zend_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;
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
case $object instanceof stdClass:
$className = '';
break;
// By default, use object's class name
// By default, use object's class name
default:
$className = get_class($object);
break;
}
$writeTraits = true;
//check to see, if we have a corresponding definition
if (array_key_exists($className, $this->_referenceDefinitions)) {
$traitsInfo = $this->_referenceDefinitions[$className]['id'];
$encoding = $this->_referenceDefinitions[$className]['encoding'];
$propertyNames = $this->_referenceDefinitions[$className]['propertyNames'];
$traitsInfo = $traitsInfo << 2 | 0x1;
$writeTraits = false;
} else {
$propertyNames = array();
if ($className == '') {
//if there is no className, we interpret the class as dynamic without any sealed members
$encoding = Zend_Amf_Constants::ET_DYNAMIC;
} else {
$encoding = Zend_Amf_Constants::ET_PROPLIST;
foreach ($object as $key => $value) {
if ($key[0] != "_") {
$propertyNames[] = $key;
}
}
}
$this->_referenceDefinitions[$className] = array('id' => count($this->_referenceDefinitions), 'encoding' => $encoding, 'propertyNames' => $propertyNames);
$traitsInfo = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
$traitsInfo |= $encoding << 2;
$traitsInfo |= count($propertyNames) << 4;
}
$this->writeInteger($traitsInfo);
if ($writeTraits) {
$this->writeString($className);
foreach ($propertyNames as $value) {
$this->writeString($value);
}
}
try {
switch ($encoding) {
case Zend_Amf_Constants::ET_PROPLIST:
//Write the sealed values to the output stream.
foreach ($propertyNames as $key) {
$this->writeTypeMarker($object->{$key});
}
break;
case Zend_Amf_Constants::ET_DYNAMIC:
//Write the sealed values to the output stream.
foreach ($propertyNames as $key) {
$this->writeTypeMarker($object->{$key});
}
//Write remaining properties
foreach ($object as $key => $value) {
if (!in_array($key, $propertyNames) && $key[0] != "_") {
$this->writeString($key);
$this->writeTypeMarker($value);
}
}
//Write an empty string to end the dynamic part
$this->writeString($this->_strEmpty);
break;
case Zend_Amf_Constants::ET_EXTERNAL:
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('External Object Encoding not implemented');
break;
default:
require_once 'Zend/Amf/Exception.php';
//.........这里部分代码省略.........
示例14: testPhpObjectSerializedToAmf0TypedObjectClassMap
public function testPhpObjectSerializedToAmf0TypedObjectClassMap()
{
Zend_Amf_Parse_TypeLoader::setMapping("ContactVO", "Contact");
$data = array();
$contact = new Contact();
$contact->id = '15';
$contact->firstname = 'Joe';
$contact->lastname = 'Smith';
$contact->email = 'jsmith@adobe.com';
$contact->mobile = '123-456-7890';
unset($contact->_explicitType);
array_push($data, $contact);
$contact = new Contact();
$contact->id = '23';
$contact->firstname = 'Adobe';
$contact->lastname = 'Flex';
$contact->email = 'was@here.com';
$contact->mobile = '123-456-7890';
unset($contact->_explicitType);
array_push($data, $contact);
$newBody = new Zend_Amf_Value_MessageBody('/1/onResult', null, $data);
$this->_response->setObjectEncoding(0x0);
$this->_response->addAmfBody($newBody);
$this->_response->finalize();
$testResponse = $this->_response->getResponse();
// Load the expected response.
$mockResponse = file_get_contents(dirname(__FILE__) . '/Response/mock/typedObjectAmf0Response.bin');
// Check that the response matches the expected serialized value
$this->assertEquals($mockResponse, $testResponse);
}
示例15: readTypedObject
/**
* Read Class that is to be mapped to a server class.
*
* Commonly used for Value Objects on the server
*
* @todo implement Typed Class mapping
* @return object|array
* @throws Zend_Amf_Exception if unable to load type
*/
public function readTypedObject()
{
require_once PHP_LIBRARY_PATH . 'Zend/Amf/Parse/TypeLoader.php';
// get the remote class name
$className = $this->_stream->readUTF();
$loader = Zend_Amf_Parse_TypeLoader::loadType($className);
$returnObject = new $loader();
$properties = get_object_vars($this->readObject());
foreach ($properties as $key => $value) {
if ($key) {
$returnObject->{$key} = $value;
}
}
if ($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
$returnObject = get_object_vars($returnObject);
}
return $returnObject;
}