mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
bootstrap generic doc manager and associated services
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\GenericDoc;
|
||||
|
||||
final readonly class FetchQueryToSqlBuilder
|
||||
{
|
||||
private const SQL = <<<'SQL'
|
||||
SELECT
|
||||
'{{ key }}' AS key,
|
||||
{{ identifiers }} AS identifiers,
|
||||
{{ date }} AS doc_date
|
||||
FROM {{ from }}
|
||||
WHERE {{ where }}
|
||||
SQL;
|
||||
|
||||
/**
|
||||
* @param FetchQueryInterface $query
|
||||
* @return array{sql: string, params: list<mixed>}
|
||||
*/
|
||||
public function toSql(FetchQueryInterface $query): array
|
||||
{
|
||||
$sql = strtr(self::SQL, [
|
||||
'{{ key }}' => $query->getSelectKeyString(),
|
||||
'{{ identifiers }}' => $query->getSelectIdentifierJsonB(),
|
||||
'{{ date }}' => $query->getSelectDate(),
|
||||
'{{ from }}' => $query->getFromQuery(),
|
||||
'{{ where }}' => $query->getWhereQuery(),
|
||||
]);
|
||||
|
||||
$params = [
|
||||
...$query->getSelectIdentifierParams(),
|
||||
...$query->getSelectDateParams(),
|
||||
...$query->getFromQueryParams(),
|
||||
...$query->getWhereQueryParams()
|
||||
];
|
||||
|
||||
return ['sql' => $sql, 'params' => $params];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user