Mercurial > hg > isophonics-drupal-site
annotate vendor/symfony/serializer/Mapping/Factory/ClassResolverTrait.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 /* |
Chris@0 | 4 * This file is part of the Symfony package. |
Chris@0 | 5 * |
Chris@0 | 6 * (c) Fabien Potencier <fabien@symfony.com> |
Chris@0 | 7 * |
Chris@0 | 8 * For the full copyright and license information, please view the LICENSE |
Chris@0 | 9 * file that was distributed with this source code. |
Chris@0 | 10 */ |
Chris@0 | 11 |
Chris@0 | 12 namespace Symfony\Component\Serializer\Mapping\Factory; |
Chris@0 | 13 |
Chris@0 | 14 use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
Chris@0 | 15 |
Chris@0 | 16 /** |
Chris@0 | 17 * Resolves a class name. |
Chris@0 | 18 * |
Chris@0 | 19 * @internal |
Chris@0 | 20 * |
Chris@0 | 21 * @author Kévin Dunglas <dunglas@gmail.com> |
Chris@0 | 22 */ |
Chris@0 | 23 trait ClassResolverTrait |
Chris@0 | 24 { |
Chris@0 | 25 /** |
Chris@0 | 26 * Gets a class name for a given class or instance. |
Chris@0 | 27 * |
Chris@0 | 28 * @param mixed $value |
Chris@0 | 29 * |
Chris@0 | 30 * @return string |
Chris@0 | 31 * |
Chris@0 | 32 * @throws InvalidArgumentException If the class does not exists |
Chris@0 | 33 */ |
Chris@0 | 34 private function getClass($value) |
Chris@0 | 35 { |
Chris@17 | 36 if (\is_string($value)) { |
Chris@0 | 37 if (!class_exists($value) && !interface_exists($value)) { |
Chris@0 | 38 throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value)); |
Chris@0 | 39 } |
Chris@0 | 40 |
Chris@0 | 41 return ltrim($value, '\\'); |
Chris@0 | 42 } |
Chris@0 | 43 |
Chris@17 | 44 if (!\is_object($value)) { |
Chris@17 | 45 throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value))); |
Chris@0 | 46 } |
Chris@0 | 47 |
Chris@17 | 48 return \get_class($value); |
Chris@0 | 49 } |
Chris@0 | 50 } |