Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Serializer\Mapping\Factory; Chris@0: Chris@0: use Symfony\Component\Serializer\Exception\InvalidArgumentException; Chris@0: Chris@0: /** Chris@0: * Resolves a class name. Chris@0: * Chris@0: * @internal Chris@0: * Chris@0: * @author Kévin Dunglas Chris@0: */ Chris@0: trait ClassResolverTrait Chris@0: { Chris@0: /** Chris@0: * Gets a class name for a given class or instance. Chris@0: * Chris@0: * @param mixed $value Chris@0: * Chris@0: * @return string Chris@0: * Chris@0: * @throws InvalidArgumentException If the class does not exists Chris@0: */ Chris@0: private function getClass($value) Chris@0: { Chris@17: if (\is_string($value)) { Chris@0: if (!class_exists($value) && !interface_exists($value)) { Chris@0: throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value)); Chris@0: } Chris@0: Chris@0: return ltrim($value, '\\'); Chris@0: } Chris@0: Chris@17: if (!\is_object($value)) { Chris@17: throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value))); Chris@0: } Chris@0: Chris@17: return \get_class($value); Chris@0: } Chris@0: }