Skip to content

Commit b0b31a3

Browse files
ISSUE-172: Removed hard dependency on Symfony Add-on Transformers and Doctrine
1 parent 560cd81 commit b0b31a3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
],
1111
"require": {
1212
"php": ">=7.2.5",
13-
"doctrine/common": "^2.4",
14-
"doctrine/orm": "^2.4",
1513
"symfony/form": "5.0.*"
1614
},
1715
"require-dev": {
16+
"doctrine/common": "^2.4",
17+
"doctrine/orm": "^2.4",
1818
"phpunit/phpunit": "^8.5"
1919
},
2020
"suggest": {
2121
"darkwebdesign/symfony-addon-pack": "All Symfony add-ons bundled together",
22-
"darkwebdesign/symfony-form-types": "Enables the use of the EntityType Form Field"
22+
"doctrine/common": "Required for EntityToIdentifierTransformer",
23+
"doctrine/orm": "Required for EntityToIdentifierTransformer"
2324
},
2425
"autoload": {
2526
"psr-4": {

src/EntityToIdentifierTransformer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
use Symfony\Component\Form\Exception\InvalidArgumentException;
2929
use Symfony\Component\Form\Exception\TransformationFailedException;
3030

31+
if (!interface_exists(ObjectManager::class)) {
32+
throw new \LogicException('You cannot use "DarkWebDesign\SymfonyAddonTransformers\EntityToIdentifierTransformer" as the "doctrine/common" package is not installed. Try running "composer require doctrine/common".');
33+
}
34+
3135
/**
3236
* Transforms between an identifier and a Doctrine entity.
3337
*
@@ -85,6 +89,10 @@ public function transform($value)
8589
throw new TransformationFailedException('Expected an object.');
8690
}
8791

92+
if (!class_exists(ClassUtils::class)) {
93+
throw new \LogicException(sprintf('You cannot use "%s" as the "doctrine/common" package is not installed. Try running "composer require doctrine/common".', __CLASS__));
94+
}
95+
8896
$className = ClassUtils::getClass($value);
8997

9098
if ($className !== $this->className && !is_subclass_of($className, $this->className)) {

0 commit comments

Comments
 (0)