From 8cfa883c1b933417f813a162b672ce35774b4a00 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Fri, 14 Aug 2020 22:36:08 +0000 Subject: [PATCH] [DB] Add 'dql' method to wrap 'createQuery' and replace 'Gsactor' with 'GSActor' --- src/Core/DB/DB.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Core/DB/DB.php b/src/Core/DB/DB.php index 5fbc034cf8..c0ea9fb712 100644 --- a/src/Core/DB/DB.php +++ b/src/Core/DB/DB.php @@ -34,6 +34,7 @@ use App\Util\Formatting; use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\ExpressionBuilder; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Query; use Exception; abstract class DB @@ -44,6 +45,16 @@ abstract class DB self::$em = $m; } + public static function dql(string $query, ?array $params) + { + $q = new Query(self::$em); + $q->setDQL($query); + foreach ($params as $k => $v) { + $q->setParameter($k, $v); + } + return $q->getResult(); + } + private static array $find_by_ops = ['or', 'and', 'eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'is_null', 'in', 'not_in', 'contains', 'member_of', 'starts_with', 'ends_with', ]; @@ -100,8 +111,9 @@ abstract class DB $args[0] = '\App\Entity\\' . ucfirst(Formatting::snakeCaseToCamelCase($args[0])); } } - if (($args[0] ?? '') === '\App\Entity\Gsactor') { - $args[0] = '\App\Entity\GSActor'; + + if (isset($args[0]) && is_string($args[0])) { + $args[0] = preg_replace('/Gsactor/', 'GSActor', $args[0] ?? ''); } return self::$em->{$name}(...$args);