private static function computeHasCustomFieldSerializer(Clazz $instanceType) { assert($instanceType != null); $qualifiedTypeName = $instanceType->getName(); $simpleSerializerName = $qualifiedTypeName . '_CustomFieldSerializer'; $customSerializer = self::getCustomFieldSerializer($simpleSerializerName); if ($customSerializer != null) { return $customSerializer; } $customSerializerClass = self::getCustomFieldSerializer(self::JRE_SERIALIZER_PACKAGE . '.' . $simpleSerializerName); if (!is_null($customSerializerClass)) { return $customSerializerClass; } return null; }
private static function printTypeName(Clazz $type) { // Primitives // if ($type === Integer::typeClass()) { return 'int'; } else { if ($type === Long::typeClass()) { return 'long'; } else { if ($type === Short::typeClass()) { return 'short'; } else { if ($type === Byte::typeClass()) { return 'byte'; } else { if ($type === Character::typeClass()) { return 'char'; } else { if ($type === Boolean::typeClass()) { return 'boolean'; } else { if ($type === Float::typeClass()) { return 'float'; } else { if ($type === Double::typeClass()) { return 'double'; } } } } } } } } // Arrays // if ($type->isArray()) { $componentType = $type->getComponentType(); return self::printTypeName($componentType) . '[]'; } // Everything else // return str_replace('$', '.', $type->getName()); }
public function subClassOf(Clazz $clazz) { return $this->reflect->isSubclassOf($clazz->getName()); }
private function serializeWithCustomSerializer(Clazz $customSerializer, $instance, Clazz $instanceClass, Clazz $manuallySerializedType) { assert(!$instanceClass->isArray()); foreach ($customSerializer->getMethods() as $method) { if ($method->getName() === 'serialize') { assert($method->isStatic()); $toReturn = new InvokeCustomFieldSerializerCommand($instanceClass, $customSerializer, $manuallySerializedType); $this->identityMap->put($instance, $toReturn); $subWriter = new CommandServerSerializationStreamWriter(new HasValuesCommandSink($toReturn), $this->clientOracle, $this->identityMap); $method->invoke($subWriter, $instance); return $toReturn; } } throw new NoSuchMethodException('Could not find serialize method in custom serializer ' . $customSerializer->getName()); }
private function canonicalName(Clazz $clazz) { if ($clazz->isArray()) { $leafType = $clazz; do { $leafType = $leafType->getComponentType(); } while ($leafType->isArray()); $enclosing = $leafType->getEnclosingClass(); if (!is_null($enclosing)) { // com.foo.Enclosing$Name[] return $this->canonicalName($enclosing) . '$' . $clazz->getName(); } else { if ($leafType->getPackage() === '') { // Name0[ return $clazz->getName(); } else { // com.foo.Name[] return $leafType->getPackage() . '.' . $clazz->getName(); } } } else { return $clazz->getFullName(); } }