1: <?php
2: namespace TIC\DormBundle\Hydration;
3:
4: use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
5:
6: /**
7: * Récupération de paires clé/valeur pour chaque ligne de résultat.
8: * Note: colonne 1 en clé et colonne 2 en valeur uniquement
9: *
10: * Exemple:
11: * > SELECT a, b, c FROM t
12: * < array(a1 => b1, a2 => b2, a3 => b3 ...)
13: */
14: class KeyvalHydrator extends AbstractHydrator
15: {
16:
17: /**
18: * Hydrates all rows from the current statement instance at once.
19: *
20: * @return mixed[]
21: */
22: protected function hydrateAllData(): array
23: {
24: $result = array();
25:
26: # while ($data = $this->_stmt->fetch(\PDO::FETCH_NUM)) {
27: while ($data = $this->statement()->fetchNumeric()) {
28: if (! \is_array($data) || \count($data) < 2) continue;
29:
30: $key = $data[0];
31: if ($key === null) $key = '[_NULL_]';
32: elseif ($key === '') $key = '[_EMPTY_]';
33:
34: $result[ $key ] = (\count($data) > 1) ? $data[1] : $data[0];
35: }
36:
37: return $result;
38: }
39:
40: }
41: