comparison vendor/symfony/serializer/Mapping/Factory/ClassResolverTrait.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Serializer\Mapping\Factory;
13
14 use Symfony\Component\Serializer\Exception\InvalidArgumentException;
15
16 /**
17 * Resolves a class name.
18 *
19 * @internal
20 *
21 * @author Kévin Dunglas <dunglas@gmail.com>
22 */
23 trait ClassResolverTrait
24 {
25 /**
26 * Gets a class name for a given class or instance.
27 *
28 * @param mixed $value
29 *
30 * @return string
31 *
32 * @throws InvalidArgumentException If the class does not exists
33 */
34 private function getClass($value)
35 {
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));
39 }
40
41 return ltrim($value, '\\');
42 }
43
44 if (!is_object($value)) {
45 throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($value)));
46 }
47
48 return get_class($value);
49 }
50 }