-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the code compatible with DBAL 3 and 4 by swithing the type when …
…the Mapping is loaded
- Loading branch information
Showing
6 changed files
with
69 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\UserBundle\Listener; | ||
|
||
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DoctrineMappingListener | ||
{ | ||
private bool $isArrayTypeAvailable; | ||
|
||
public function __construct(private string $userClass) | ||
{ | ||
$this->isArrayTypeAvailable = class_exists('Doctrine\DBAL\Types\ArrayType'); | ||
} | ||
|
||
/** | ||
* @throws \Doctrine\DBAL\Exception | ||
*/ | ||
public function loadClassMetadata(LoadClassMetadataEventArgs $event): void | ||
{ | ||
$metadata = $event->getClassMetadata(); | ||
|
||
if (!$this->isArrayTypeAvailable) { | ||
return; | ||
} | ||
|
||
if ($metadata->getName() !== $this->userClass) { | ||
return; | ||
} | ||
|
||
if (!$metadata->hasField('roles')) { | ||
return; | ||
} | ||
|
||
/** | ||
* @psalm-suppress InvalidPropertyAssignmentValue | ||
*/ | ||
$metadata->fieldMappings['roles']['type'] = 'array'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters