Source of file KeyhashHydrator.php

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

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

1234567891011121314151617181920212223242526272829303132333435363738394041
<?php
namespace TIC\DormBundle\Hydration;

use Doctrine\ORM\Internal\Hydration\ArrayHydrator;

/**
 * Récupération des résultats groupés par les valeurs uniques de la 1ère colonne (en index)
 *
 * Exemple:
 *   > SELECT a, b, c FROM t
 *   < array(
 *       a1 => array('a' => a1, 'b' => b1, 'c' => c1)
 *       a2 => array('a' => a2, 'b' => b2, 'c' => c2)
 *       ...
 *     )
 */
class KeyhashHydrator extends ArrayHydrator
{

	/**
	 * Hydrates all rows from the current statement instance at once.
	 *
	 * @return mixed[]
	 */
	protected function hydrateAllData(): array
	{
		$result = array();
		
		foreach (parent::hydrateAllData() as $data) {
			$key = \reset($data);
			if     ($key === null) $key = '[_NULL_]';
			elseif ($key === '')   $key = '[_EMPTY_]';
			
			$result[ $key ] = $data;
		}
		
		return $result;
	}

}