本文整理汇总了PHP中Zend\Amf\Parser\TypeLoader::handleResource方法的典型用法代码示例。如果您正苦于以下问题:PHP TypeLoader::handleResource方法的具体用法?PHP TypeLoader::handleResource怎么用?PHP TypeLoader::handleResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Amf\Parser\TypeLoader
的用法示例。
在下文中一共展示了TypeLoader::handleResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeTypeMarker
/**
* Determine type and serialize accordingly
*
* Checks to see if the type was declared and then either
* auto negotiates the type or relies on the user defined markerType to
* serialize the data into amf
*
* @param misc $data
* @param misc $markerType
* @return Zend\AMF\Parser\AMF0\Serializer
* @throws Zend\AMF\Exception for unrecognized types or data
*/
public function writeTypeMarker($data, $markerType = null)
{
if (null !== $markerType) {
//try to reference the given object
if (!$this->writeObjectReference($data, $markerType)) {
// Write the Type Marker to denote the following action script data type
$this->_stream->writeByte($markerType);
switch ($markerType) {
case AMF\Constants::AMF0_NUMBER:
$this->_stream->writeDouble($data);
break;
case AMF\Constants::AMF0_BOOLEAN:
$this->_stream->writeByte($data);
break;
case AMF\Constants::AMF0_STRING:
$this->_stream->writeUTF($data);
break;
case AMF\Constants::AMF0_OBJECT:
$this->writeObject($data);
break;
case AMF\Constants::AMF0_NULL:
break;
case AMF\Constants::AMF0_REFERENCE:
$this->_stream->writeInt($data);
break;
case AMF\Constants::AMF0_MIXEDARRAY:
// Write length of numeric keys as zero.
$this->_stream->writeLong(0);
$this->writeObject($data);
break;
case AMF\Constants::AMF0_ARRAY:
$this->writeArray($data);
break;
case AMF\Constants::AMF0_DATE:
$this->writeDate($data);
break;
case AMF\Constants::AMF0_LONGSTRING:
$this->_stream->writeLongUTF($data);
break;
case AMF\Constants::AMF0_TYPEDOBJECT:
$this->writeTypedObject($data);
break;
case AMF\Constants::AMF0_AMF3:
$this->writeAmf3TypeMarker($data);
break;
default:
throw new AMF\Exception("Unknown Type Marker: " . $markerType);
}
}
} else {
if (is_resource($data)) {
$data = Parser\TypeLoader::handleResource($data);
}
switch (true) {
case is_int($data) || is_float($data):
$markerType = AMF\Constants::AMF0_NUMBER;
break;
case is_bool($data):
$markerType = AMF\Constants::AMF0_BOOLEAN;
break;
case is_string($data) && strlen($data) > 65536:
$markerType = AMF\Constants::AMF0_LONGSTRING;
break;
case is_string($data):
$markerType = AMF\Constants::AMF0_STRING;
break;
case is_object($data):
if ($data instanceof \DateTime || $data instanceof Date\Date) {
$markerType = AMF\Constants::AMF0_DATE;
} else {
if ($className = $this->getClassName($data)) {
//Object is a Typed object set classname
$markerType = AMF\Constants::AMF0_TYPEDOBJECT;
$this->_className = $className;
} else {
// Object is a generic classname
$markerType = AMF\Constants::AMF0_OBJECT;
}
break;
}
break;
case null === $data:
$markerType = AMF\Constants::AMF0_NULL;
break;
case is_array($data):
// check if it is an associative array
$i = 0;
foreach (array_keys($data) as $key) {
//.........这里部分代码省略.........
示例2: writeTypeMarker
/**
* Serialize PHP types to AMF3 and write to stream
*
* Checks to see if the type was declared and then either
* auto negotiates the type or use the user defined markerType to
* serialize the data from php back to AMF3
*
* @param mixed $data
* @param int $markerType
* @param mixed $dataByVal
* @return void
*/
public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
{
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
// variables should be passed by reference"
if (null === $data && $dataByVal !== false) {
$data =& $dataByVal;
}
if (null !== $markerType) {
// Write the Type Marker to denote the following action script data type
$this->_stream->writeByte($markerType);
switch ($markerType) {
case Amf\Constants::AMF3_NULL:
break;
case Amf\Constants::AMF3_BOOLEAN_FALSE:
break;
case Amf\Constants::AMF3_BOOLEAN_TRUE:
break;
case Amf\Constants::AMF3_INTEGER:
$this->writeInteger($data);
break;
case Amf\Constants::AMF3_NUMBER:
$this->_stream->writeDouble($data);
break;
case Amf\Constants::AMF3_STRING:
$this->writeString($data);
break;
case Amf\Constants::AMF3_DATE:
$this->writeDate($data);
break;
case Amf\Constants::AMF3_ARRAY:
$this->writeArray($data);
break;
case Amf\Constants::AMF3_OBJECT:
$this->writeObject($data);
break;
case Amf\Constants::AMF3_BYTEARRAY:
$this->writeByteArray($data);
break;
case Amf\Constants::AMF3_XMLSTRING:
$this->writeXml($data);
break;
default:
throw new Parser\Exception\OutOfBoundsException('Unknown Type Marker: ' . $markerType);
}
} else {
// Detect Type Marker
if (is_resource($data)) {
$data = Parser\TypeLoader::handleResource($data);
}
switch (true) {
case null === $data:
$markerType = Amf\Constants::AMF3_NULL;
break;
case is_bool($data):
if ($data) {
$markerType = Amf\Constants::AMF3_BOOLEAN_TRUE;
} else {
$markerType = Amf\Constants::AMF3_BOOLEAN_FALSE;
}
break;
case is_int($data):
if ($data > 0xfffffff || $data < -268435456) {
$markerType = Amf\Constants::AMF3_NUMBER;
} else {
$markerType = Amf\Constants::AMF3_INTEGER;
}
break;
case is_float($data):
$markerType = Amf\Constants::AMF3_NUMBER;
break;
case is_string($data):
$markerType = Amf\Constants::AMF3_STRING;
break;
case is_array($data):
$markerType = Amf\Constants::AMF3_ARRAY;
break;
case is_object($data):
// Handle object types.
if ($data instanceof \DateTime || $data instanceof Date\Date) {
$markerType = Amf\Constants::AMF3_DATE;
} else {
if ($data instanceof Value\ByteArray) {
$markerType = Amf\Constants::AMF3_BYTEARRAY;
} else {
if ($data instanceof \DOMDocument || $data instanceof \SimpleXMLElement) {
$markerType = Amf\Constants::AMF3_XMLSTRING;
} else {
$markerType = Amf\Constants::AMF3_OBJECT;
//.........这里部分代码省略.........