Skip to content

Commit 39b61ad

Browse files
derrabusphansys
authored andcommitted
Make the doctrine/common dependency optional
1 parent 5d80d9d commit 39b61ad

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"php": "^7.4 || ^8.0",
4444
"behat/transliterator": "^1.2",
4545
"doctrine/collections": "^1.2 || ^2.0",
46-
"doctrine/common": "^2.13 || ^3.0",
4746
"doctrine/deprecations": "^1.0",
4847
"doctrine/event-manager": "^1.2 || ^2.0",
4948
"doctrine/persistence": "^2.2 || ^3.0",
@@ -54,6 +53,7 @@
5453
"require-dev": {
5554
"doctrine/annotations": "^1.13 || ^2.0",
5655
"doctrine/cache": "^1.11 || ^2.0",
56+
"doctrine/common": "^2.13 || ^3.0",
5757
"doctrine/dbal": "^3.7 || ^4.0",
5858
"doctrine/doctrine-bundle": "^2.3",
5959
"doctrine/mongodb-odm": "^2.3",
@@ -73,6 +73,7 @@
7373
},
7474
"conflict": {
7575
"doctrine/annotations": "<1.13 || >=3.0",
76+
"doctrine/common": "<2.13 || >=4.0",
7677
"doctrine/dbal": "<3.7 || >=5.0",
7778
"doctrine/mongodb-odm": "<2.3 || >=3.0",
7879
"doctrine/orm": "<2.14.0 || 2.16.0 || 2.16.1 || >=4.0"

src/Sortable/Mapping/Event/Adapter/ODM.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
namespace Gedmo\Sortable\Mapping\Event\Adapter;
1111

12-
use Doctrine\Common\Util\ClassUtils;
1312
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
1413
use Gedmo\Mapping\Event\Adapter\ODM as BaseAdapterODM;
1514
use Gedmo\Sortable\Mapping\Event\SortableAdapter;
15+
use Gedmo\Tool\ClassUtils;
1616

1717
/**
1818
* Doctrine event adapter for ODM adapted

src/Sortable/SortableListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Doctrine\Common\Comparable;
1313
use Doctrine\Common\EventArgs;
14-
use Doctrine\Common\Util\ClassUtils;
1514
use Doctrine\Deprecations\Deprecation;
1615
use Doctrine\Persistence\Event\LifecycleEventArgs;
1716
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
@@ -20,6 +19,7 @@
2019
use Doctrine\Persistence\ObjectManager;
2120
use Gedmo\Mapping\MappedEventSubscriber;
2221
use Gedmo\Sortable\Mapping\Event\SortableAdapter;
22+
use Gedmo\Tool\ClassUtils;
2323
use ProxyManager\Proxy\GhostObjectInterface;
2424

2525
/**

src/Tool/ClassUtils.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Tool;
13+
14+
use Doctrine\Common\Util\ClassUtils as CommonClassUtils;
15+
16+
/**
17+
* Utility class for Doctrine Common proxies.
18+
*/
19+
final class ClassUtils
20+
{
21+
private function __construct()
22+
{
23+
}
24+
25+
/**
26+
* Gets the real class name of an object (even if it's a proxy).
27+
*
28+
* If doctrine/common is not installed, this method behaves like {@see get_class()}.
29+
*
30+
* @param TObject $object
31+
* @return class-string<TObject>
32+
* @template TObject of object
33+
*/
34+
public static function getClass(object $object): string
35+
{
36+
if (class_exists(CommonClassUtils::class)) {
37+
return CommonClassUtils::getClass($object);
38+
}
39+
40+
return get_class($object);
41+
}
42+
}

src/Tool/Wrapper/EntityWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
namespace Gedmo\Tool\Wrapper;
1111

12-
use Doctrine\Common\Util\ClassUtils;
1312
use Doctrine\ORM\EntityManagerInterface;
1413
use Doctrine\ORM\Mapping\ClassMetadata;
1514
use Doctrine\Persistence\Proxy as PersistenceProxy;
15+
use Gedmo\Tool\ClassUtils;
1616

1717
/**
1818
* Wraps entity or proxy for more convenient

0 commit comments

Comments
 (0)