private function callVisitor($data, Type $type, Context $context, ClassMetadata $metadata = null) { $visitor = $context->getVisitor(); // First, try whether a custom handler exists for the given type if (null !== ($handler = $this->handlerRegistry->getHandler($context->getDirection(), $type->getName()))) { return $visitor->visitCustom($handler, $data, $type, $context); } switch ($type->getName()) { case 'NULL': return $visitor->visitNull($data, $type, $context); case 'string': return $visitor->visitString($data, $type, $context); case 'integer': return $visitor->visitInteger($data, $type, $context); case 'boolean': return $visitor->visitBoolean($data, $type, $context); case 'double': case 'float': return $visitor->visitDouble($data, $type, $context); case 'array': return $this->visitArray($visitor, $data, $type, $context); case 'resource': $msg = 'Resources are not supported in serialized data.'; throw new RuntimeException($msg); default: if (null === $metadata) { // Missing handler for custom type return null; } $exclusionStrategy = $context->getExclusionStrategy(); if (null !== $exclusionStrategy && $exclusionStrategy->shouldSkipClass($metadata, $context)) { return null; } return $visitor->visitObject($metadata, $data, $type, $context, $this->objectConstructor); } }