1 | <?php |
||
12 | abstract class LocalAdapterLocator implements ObjectUnserializer |
||
13 | { |
||
14 | 2 | protected function locateUnserializerForClass(string $className, $serializedValue):?ObjectUnserializer |
|
15 | { |
||
16 | 2 | $hydratorName = $this->getNamespace() . '\\' . $className . '\\From' . ucfirst($this->getNameFromSerializedValue($serializedValue)); |
|
17 | |||
18 | 2 | if (class_exists($hydratorName)) { |
|
19 | 1 | return new $hydratorName; |
|
20 | } |
||
21 | |||
22 | 1 | return null; |
|
23 | } |
||
24 | |||
25 | 2 | public function tryToUnserializeValue(string $objectClassName, $serializedValue) |
|
26 | { |
||
27 | 2 | $adapter = $this->locateUnserializerForClass($objectClassName, $serializedValue); |
|
28 | |||
29 | 2 | if ($adapter) { |
|
30 | 1 | return $adapter->tryToUnserializeValue($objectClassName, $serializedValue); |
|
31 | } |
||
32 | |||
33 | 1 | throw new AdapterNotFoundException(sprintf("Adapter for %s not found", $objectClassName)); |
|
34 | } |
||
35 | |||
36 | abstract protected function getNamespace(): string; |
||
37 | |||
38 | /** |
||
39 | * @param $serializedValue |
||
40 | * @return string |
||
41 | */ |
||
42 | 2 | private function getNameFromSerializedValue($serializedValue) |
|
50 | |||
51 | 1 | private function getShortClassName($serializedValue): string |
|
57 | } |