Newer
Older
Klaranouba7
a validé
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Core\Util;
/**
* Retrieves information about a class.
*
* @internal
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
trait ClassInfoTrait
{
/**
* Get class name of the given object.
*
* @param object $object
*/
private function getObjectClass($object): string
{
return $this->getRealClassName(\get_class($object));
}
/**
* Get the real class name of a class name that could be a proxy.
*/
private function getRealClassName(string $className): string
{
// __CG__: Doctrine Common Marker for Proxy (ODM < 2.0 and ORM < 3.0)
// __PM__: Ocramius Proxy Manager (ODM >= 2.0)
$positionCg = strrpos($className, '\\__CG__\\');
$positionPm = strrpos($className, '\\__PM__\\');
if (false === $positionCg && false === $positionPm) {
return $className;
}
if (false !== $positionCg) {
return substr($className, $positionCg + 8);
}
$className = ltrim($className, '\\');
return substr(
$className,
8 + $positionPm,
strrpos($className, '\\') - ($positionPm + 8)
);
}
}