4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Serializer\Mapping\Factory;
14 use Symfony\Component\Serializer\Exception\InvalidArgumentException;
17 * Resolves a class name.
21 * @author Kévin Dunglas <dunglas@gmail.com>
23 trait ClassResolverTrait
26 * Gets a class name for a given class or instance.
32 * @throws InvalidArgumentException If the class does not exists
34 private function getClass($value)
36 if (\is_string($value)) {
37 if (!class_exists($value) && !interface_exists($value)) {
38 throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value));
41 return ltrim($value, '\\');
44 if (!\is_object($value)) {
45 throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value)));
48 return \get_class($value);