Skip to content

Commit df8cdbe

Browse files
ISSUE-172: Removed hard dependency on Symfony Add-on Transformers and Doctrine
1 parent cf7a012 commit df8cdbe

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
],
1111
"require": {
1212
"php": ">=7.2.5",
13-
"darkwebdesign/symfony-addon-transformers": "5.0.*",
14-
"doctrine/common": "^2.4",
1513
"symfony/form": "5.0.*"
1614
},
1715
"require-dev": {
16+
"darkwebdesign/symfony-addon-transformers": "5.0.*",
17+
"doctrine/common": "^2.4",
1818
"phpunit/phpunit": "^8.5"
1919
},
2020
"suggest": {
21-
"darkwebdesign/symfony-addon-pack": "All Symfony add-ons bundled together"
21+
"darkwebdesign/symfony-addon-pack": "All Symfony add-ons bundled together",
22+
"darkwebdesign/symfony-addon-transformers": "Required for BooleanType and EntityType",
23+
"doctrine/common": "Required for EntityType"
2224
},
2325
"autoload": {
2426
"psr-4": {

src/BooleanType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class BooleanType extends AbstractType
4343
*/
4444
public function buildForm(FormBuilderInterface $builder, array $options): void
4545
{
46+
if (!class_exists(BooleanToValueTransformer::class)) {
47+
throw new \LogicException(sprintf('You cannot use "%s" as the "darkwebdesign/symfony-addon-transformers" package is not installed. Try running "composer require darkwebdesign/symfony-addon-transformers".', __CLASS__));
48+
}
49+
4650
$builder->addModelTransformer(new BooleanToValueTransformer($options['value_true'], $options['value_false']));
4751
}
4852

src/EntityType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
use Symfony\Component\OptionsResolver\Options;
3232
use Symfony\Component\OptionsResolver\OptionsResolver;
3333

34+
if (!interface_exists(ManagerRegistry::class)) {
35+
throw new \LogicException('You cannot use "DarkWebDesign\SymfonyAddonFormTypes\EntityType" as the "doctrine/common" package is not installed. Try running "composer require doctrine/common".');
36+
}
37+
3438
/**
3539
* Entity form field type.
3640
*
@@ -56,6 +60,10 @@ public function __construct(ManagerRegistry $registry)
5660
*/
5761
public function buildForm(FormBuilderInterface $builder, array $options): void
5862
{
63+
if (!class_exists(EntityToIdentifierTransformer::class)) {
64+
throw new \LogicException(sprintf('You cannot use "%s" as the "darkwebdesign/symfony-addon-transformers" package is not installed. Try running "composer require darkwebdesign/symfony-addon-transformers".', __CLASS__));
65+
}
66+
5967
$builder->addViewTransformer(new EntityToIdentifierTransformer($options['entity_manager'], $options['class']));
6068
}
6169

@@ -64,6 +72,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6472
*/
6573
public function configureOptions(OptionsResolver $resolver): void
6674
{
75+
if (!interface_exists(ObjectManager::class)) {
76+
throw new \LogicException(sprintf('You cannot use "%s" as the "doctrine/common" package is not installed. Try running "composer require doctrine/common".', __CLASS__));
77+
}
78+
6779
$registry = $this->registry;
6880

6981
$entityManagerNormalizer = function (Options $options, $entityManager) use ($registry) {

0 commit comments

Comments
 (0)