for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace DH\DoctrineAuditBundle\Helper;
use Doctrine\Common\Persistence\Proxy;
class DoctrineHelper
{
/**
* Gets the real class name of a class name that could be a proxy.
*
* @param object|string $subject
* @return string
* credits
* https://github.com/api-platform/core/blob/master/src/Util/ClassInfoTrait.php
*/
* Get the real class name of a class name that could be a proxy.
public static function getRealClassName($class): string
$class = \is_object($class) ? \get_class($class) : $class;
// __CG__: Doctrine Common Marker for Proxy (ODM < 2.0 and ORM < 3.0)
// __PM__: Ocramius Proxy Manager (ODM >= 2.0)
if ((false === $positionCg = strrpos($class, '\\__CG__\\')) &&
(false === $positionPm = strrpos($class, '\\__PM__\\'))) {
return $class;
}
if (false !== $positionCg) {
return substr($class, $positionCg + 8);
$className = ltrim($class, '\\');
return substr(
$className,
8 + $positionPm,
$positionPm
strrpos($className, '\\') - ($positionPm + 8)
);
* Given a class name and a proxy namespace returns the proxy name.
* @param string $className
* @param string $proxyNamespace
public static function generateProxyClassName($className, $proxyNamespace): string
return rtrim($proxyNamespace, '\\').'\\'.Proxy::MARKER.'\\'.ltrim($className, '\\');