Source of file KeyvalHydrator.php

Size: 0,936 Bytes - Last Modified: 2023-11-16T22:56:02+01:00

/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/dorm-bundle/src/Hydration/KeyvalHydrator.php

1234567891011121314151617181920212223242526272829303132333435363738394041
<?php
namespace TIC\DormBundle\Hydration;

use Doctrine\ORM\Internal\Hydration\AbstractHydrator;

/**
 * Récupération de paires clé/valeur pour chaque ligne de résultat.
 * Note: colonne 1 en clé et colonne 2 en valeur uniquement
 *
 * Exemple:
 *   > SELECT a, b, c FROM t
 *   < array(a1 => b1, a2 => b2, a3 => b3 ...)
 */
class KeyvalHydrator extends AbstractHydrator
{

	/**
	 * Hydrates all rows from the current statement instance at once.
	 *
	 * @return mixed[]
	 */
	protected function hydrateAllData(): array
	{
		$result = array();
		
#		while ($data = $this->_stmt->fetch(\PDO::FETCH_NUM)) {
		while ($data = $this->statement()->fetchNumeric()) {
			if (! \is_array($data) || \count($data) < 2) continue;
			
			$key = $data[0];
			if     ($key === null) $key = '[_NULL_]';
			elseif ($key === '')   $key = '[_EMPTY_]';
			
			$result[ $key ] = (\count($data) > 1) ? $data[1] : $data[0];
		}
		
		return $result;
	}

}