本文整理汇总了PHP中Classes::classOfValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Classes::classOfValue方法的具体用法?PHP Classes::classOfValue怎么用?PHP Classes::classOfValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Classes
的用法示例。
在下文中一共展示了Classes::classOfValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encodeResponseForSuccess
public static function encodeResponseForSuccess(Method $serviceMethod, $object, SerializationPolicy $serializationPolicy = null, $flags = AbstractSerializationStream::DEFAULT_FLAGS)
{
if (is_null($serviceMethod)) {
throw new NullPointerException('serviceMethod cannot be null');
}
if (is_null($serializationPolicy)) {
$serializationPolicy = self::getDefaultSerializationPolicy();
throw new NullPointerException('serializationPolicy cannot be null');
}
$methodReturnTypeName = $serviceMethod->getReturnType();
//TODO see if must be an object
if (empty($methodReturnTypeName)) {
$methodReturnType = Void::typeClass();
} else {
$methodReturnType = Classes::classOf($methodReturnTypeName);
}
if ($methodReturnType !== Void::typeClass() && !is_null($object)) {
// TODO : Verify
/*if ($methodReturnType->isPrimitive()) {
$actualReturnType = self::getPrimitiveClassFromWrapper(Classes::classOf($object));
}
else {
$actualReturnType = Classes::classOf($object);
}*/
$actualReturnType = Classes::classOfValue($object);
//var_dump($methodReturnType);
// TODO : Enum manage
if ($methodReturnType->isEnum() && $actualReturnType === Integer::typeClass()) {
return self::encodeResponse($methodReturnType, $object, false, $flags, $serializationPolicy);
}
if (is_null($actualReturnType) || !$methodReturnType->isAssignableFrom($actualReturnType)) {
$printedType = self::printTypeName(Classes::classOfValue($object));
$source = self::getSourceRepresentation($serviceMethod);
throw new IllegalArgumentException("Type '{$printedType}' does not match the return type in the method's signature : '{$source}'");
}
}
return self::encodeResponse($methodReturnType, $object, false, $flags, $serializationPolicy);
}
示例2: autoClass
public static function autoClass(array &$value)
{
$type = null;
for ($i = 0; $i < count($value); $i++) {
$itype = Classes::classOfValue($value[$i]);
if (is_null($type)) {
$type = $itype;
} else {
if ($type != $itype) {
return self::clazz(Object::clazz(), 1);
}
}
}
return self::clazz($type, 1);
}
示例3: makeObject
private function makeObject(Clazz $type, $value)
{
// no anonymous class, and no local class in php
$manualType = $type;
$customSerializer = null;
do {
$customSerializer = SerializabilityUtil::hasCustomFieldSerializer($manualType);
if ($customSerializer != null) {
break;
}
$manualType = $manualType->getSuperClass();
} while ($manualType != null);
$ins = null;
if ($customSerializer != null) {
$ins = $this->serializeWithCustomSerializer($customSerializer, $value, $type, $manualType);
} else {
$ins = new InstantiateCommand($type);
$this->identityMap->put($value, $ins);
}
if ($type != $manualType) {
if (!Classes::classOf('GWTSerializable')->isAssignableFrom($type) && !Classes::classOf('IsSerializable')->isAssignableFrom($type)) {
throw new SerializationException($type->getName() . ' is not a serializable type');
}
}
while ($type != $manualType) {
$serializableFields = $this->clientOracle->getOperableFields($type);
foreach ($serializableFields as $declField) {
assert($declField != null);
//echo '[' . $declField->getName() . ' = ' . $declField->getType() . ']<br />';
$accessor = Accessors::get($declField->getType());
$valueCommand = null;
$fieldValue = $accessor->get($value, $declField);
if (is_null($fieldValue)) {
$valueCommand = NullValueCommand::INSTANCE();
} else {
$fieldType = $declField->getType()->isPrimitive() ? $declField->getType() : ($declField->hasType() ? $declField->getType() : Classes::classOfValue($fieldValue));
$valueCommand = $this->makeValue($fieldType, $fieldValue);
}
//echo '{set ' . $declField->getDeclaringClass()->getName() . ' / ' . $declField->getName() . ' / ' . $valueCommand . '}';
$ins->set($declField->getDeclaringClass(), $declField->getName(), $valueCommand);
}
$type = $type->getSuperClass();
}
return $ins;
}
示例4: getClassForSerialization
private static function getClassForSerialization($instance, Clazz $instanceClass = null)
{
assert(!is_null($instance));
/*if ($instance instanceof SerializedEnum) {
return $instance->getEnumClass();
}*/
// TODO if enum
/*if (instance instanceof Enum<?>) {
Enum<?> e = (Enum<?>) instance;
return e.getDeclaringClass();
} else {
return instance.getClass();
}*/
if (is_null($instanceClass)) {
return Classes::classOfValue($instance);
} else {
return $instanceClass;
}
}