|
1 | | -<?php |
2 | | -namespace App\ModelSerializers; |
| 1 | +<?php namespace App\ModelSerializers; |
3 | 2 | /** |
4 | 3 | * Copyright 2019 OpenStack Foundation |
5 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -42,12 +41,10 @@ final class SerializerRegistry |
42 | 41 | */ |
43 | 42 | private static $instance; |
44 | 43 |
|
45 | | - const SerializerType_Public = 'PUBLIC'; |
| 44 | + const SerializerType_Public = 'PUBLIC'; |
46 | 45 | const SerializerType_Private = 'PRIVATE'; |
47 | 46 |
|
48 | | - private function __clone() |
49 | | - { |
50 | | - } |
| 47 | + private function __clone(){} |
51 | 48 |
|
52 | 49 | /** |
53 | 50 | * @var IResourceServerContext |
@@ -115,19 +112,17 @@ private function __construct() |
115 | 112 | * @param string $type |
116 | 113 | * @return IModelSerializer |
117 | 114 | */ |
118 | | - public function getSerializer($object, $type = self::SerializerType_Public) |
119 | | - { |
120 | | - if (is_null($object)) |
121 | | - return null; |
122 | | - |
123 | | - $class = class_basename(is_string($object) ? $object : get_class($object)); |
124 | | - if (!isset($this->registry[$class])) |
125 | | - throw new \InvalidArgumentException('Serializer not found for ' . $class); |
| 115 | + public function getSerializer($object, $type = self::SerializerType_Public){ |
| 116 | + if(is_null($object)) return null; |
| 117 | + $reflect = new ReflectionClass($object); |
| 118 | + $class = $reflect->getShortName(); |
| 119 | + if(!isset($this->registry[$class])) |
| 120 | + throw new \InvalidArgumentException('Serializer not found for '.$class); |
126 | 121 |
|
127 | 122 | $serializer_class = $this->registry[$class]; |
128 | 123 |
|
129 | | - if (is_array($serializer_class)) { |
130 | | - if (!isset($serializer_class[$type])) |
| 124 | + if(is_array($serializer_class)){ |
| 125 | + if(!isset($serializer_class[$type])) |
131 | 126 | throw new \InvalidArgumentException(sprintf('Serializer not found for %s , type %s', $class, $type)); |
132 | 127 | $serializer_class = $serializer_class[$type]; |
133 | 128 | } |
|
0 commit comments