forked from GNUsocial/gnu-social
[DB] Add 'dql' method to wrap 'createQuery' and replace 'Gsactor' with 'GSActor'
This commit is contained in:
parent
688ee18411
commit
8cfa883c1b
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user