Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with doctrine/mongodb-odm v.2.0; Drop DoctrineClassUtils; #1026

Merged
merged 4 commits into from
Sep 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions Util/ClassUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Vich\UploaderBundle\Util;

use Doctrine\Common\Util\ClassUtils as DoctrineClassUtils;

class ClassUtils
{
/**
Expand All @@ -20,12 +18,28 @@ private function __construct()
*
* @return string The FQCN of the given object
*/
public static function getClass($object): string
public static function getClass(object $object): string
{
if (\class_exists(DoctrineClassUtils::class)) {
return DoctrineClassUtils::getClass($object);
$className = \get_class($object);

// see original code @ https://github.com/api-platform/core/blob/6e9ccf7418bf973d273b125d55ccc521b89afb06/src/Util/ClassInfoTrait.php#L38
// __CG__: Doctrine Common Marker for Proxy (ODM < 2.0 and ORM < 3.0)
garak marked this conversation as resolved.
Show resolved Hide resolved
// __PM__: Ocramius Proxy Manager (ODM >= 2.0)
if ((false === $positionCg = strrpos($className, '\\__CG__\\')) &&
(false === $positionPm = strrpos($className, '\\__PM__\\'))) {
return $className;
}

return \get_class($object);
if (false !== $positionCg) {
return substr($className, $positionCg + 8);
}

$className = ltrim($className, '\\');

return substr(
$className,
8 + $positionPm,
strrpos($className, '\\') - ($positionPm + 8)
);
}
}