Total Complexity | 8 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | final class DoctrineHelper |
||
9 | { |
||
10 | private function __construct() |
||
11 | { |
||
12 | } |
||
13 | |||
14 | /** |
||
15 | * Gets the real class name of a class name that could be a proxy. |
||
16 | * |
||
17 | * @param object|string $class |
||
18 | * |
||
19 | * @return string |
||
20 | * |
||
21 | * credits |
||
22 | * https://github.com/api-platform/core/blob/master/src/Util/ClassInfoTrait.php |
||
23 | */ |
||
24 | public static function getRealClassName($class): string |
||
25 | { |
||
26 | $class = \is_object($class) ? \get_class($class) : $class; |
||
27 | |||
28 | // __CG__: Doctrine Common Marker for Proxy (ODM < 2.0 and ORM < 3.0) |
||
29 | // __PM__: Ocramius Proxy Manager (ODM >= 2.0) |
||
30 | $positionCg = mb_strrpos($class, '\\__CG__\\'); |
||
31 | $positionPm = mb_strrpos($class, '\\__PM__\\'); |
||
32 | if ((false === $positionCg) && |
||
33 | (false === $positionPm)) { |
||
34 | return $class; |
||
35 | } |
||
36 | if (false !== $positionCg) { |
||
37 | return mb_substr($class, $positionCg + 8); |
||
38 | } |
||
39 | $className = ltrim($class, '\\'); |
||
40 | |||
41 | return mb_substr( |
||
42 | $className, |
||
43 | 8 + $positionPm, |
||
44 | mb_strrpos($className, '\\') - ($positionPm + 8) |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | public static function getDoctrineType(string $type): string |
||
51 | } |
||
52 | } |
||
53 |