forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecretStore.php
More file actions
54 lines (45 loc) · 1.27 KB
/
Copy pathSecretStore.php
File metadata and controls
54 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace PHPCensor\Store;
use PHPCensor\Exception\HttpException;
use PHPCensor\Model\Secret;
use PHPCensor\Store;
/**
* @package PHP Censor
* @subpackage Application
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class SecretStore extends Store
{
protected string $tableName = 'secrets';
protected string $modelName = Secret::class;
/**
* Get a single Project by Ids.
*
* @param string[] $values
*
* @throws HttpException
*
* @return Secret[]
*/
public function getByNames(array $values, string $useConnection = 'read'): array
{
if (empty($values)) {
throw new HttpException('Values passed to ' . __FUNCTION__ . ' cannot be empty.');
}
$query = \sprintf(
'SELECT * FROM {{%s}} WHERE {{name}} IN (%s)',
$this->tableName,
("'" . \implode('\', \'', $values) . "'")
);
$stmt = $this->databaseManager->getConnection($useConnection)->prepare($query);
$rtn = [];
if ($stmt->execute()) {
while ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$rtn[$data['name']] = new Secret($this->storeRegistry, $data);
}
}
return $rtn;
}
}