-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chore): refactor code to prevent breaking changes in ORM3 while …
…maintaining ORM2 compatibility
- Loading branch information
Zaruike
committed
Dec 5, 2024
1 parent
17fd413
commit 83a7265
Showing
6 changed files
with
62 additions
and
12 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
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,38 @@ | ||
<?php | ||
|
||
namespace Studit\H5PBundle\Service; | ||
|
||
use Composer\InstalledVersions; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
|
||
/** | ||
* This class exists to prevent breaking changes when working with different versions of Doctrine ORM. | ||
* For example, in Doctrine ORM v3.x, certain parameters require an ArrayCollection. | ||
* @author Joris Dugué | ||
*/ | ||
class DoctrineParser | ||
{ | ||
/** | ||
* This method converts parameters to an ArrayCollection for ORM v3. | ||
* If using ORM v2, it simply returns the received parameters as is. | ||
* | ||
* @param array $params The input parameters to process. | ||
* @return ArrayCollection|array Returns an ArrayCollection for ORM v3 or the original parameters for ORM v2. | ||
*/ | ||
public static function buildParams(array $params): ArrayCollection|array | ||
{ | ||
$doctrineVersion = InstalledVersions::getVersion('doctrine/orm'); | ||
if ($doctrineVersion !== null && str_starts_with($doctrineVersion, '3')) { | ||
// For Doctrine ORM v3, ensure the parameters are returned as an ArrayCollection | ||
$paramsCollection = []; | ||
|
||
foreach ($params as $k => $val){ | ||
$paramsCollection[] = new \Doctrine\ORM\Query\Parameter($k, $val); | ||
} | ||
|
||
return new ArrayCollection($paramsCollection); | ||
} | ||
// For Doctrine ORM v2, return the parameters as is | ||
return $params; | ||
} | ||
} |
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