Created
December 5, 2017 19:06
-
-
Save enleur/dfcb5a539491b023168d3d4173b23dfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Component\Doctrine\ORM\Hydrators; | |
use Doctrine\ORM\Internal\Hydration\AbstractHydrator; | |
class NoneHydrator extends AbstractHydrator | |
{ | |
const NAME = 'NoneHydrator'; | |
protected $fieldNamesCache = []; | |
protected function hydrateAllData() | |
{ | |
$result = []; | |
foreach ($this->_stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { | |
$this->hydrateRowData($row, $result); | |
} | |
unset($this->fieldNamesCache); | |
return $result; | |
} | |
protected function hydrateRowData(array $sqlResult, array &$result) | |
{ | |
$data = []; | |
foreach ($sqlResult as $key => $value) { | |
if (($fieldName = $this->getFieldName($key)) === null) { | |
continue; | |
} | |
$data[$fieldName] = $value; | |
} | |
$result[] = $data; | |
} | |
/** | |
* @param $key | |
* @return null | |
*/ | |
protected function getFieldName($key) | |
{ | |
if (isset($this->fieldNamesCache[$key])) { | |
return $this->fieldNamesCache[$key]; | |
} | |
switch (true) { | |
case (isset($this->_rsm->scalarMappings[$key])): | |
return $this->fieldNamesCache[$key] = $this->_rsm->scalarMappings[$key]; | |
case (isset($this->_rsm->fieldMappings[$key])): | |
return $this->fieldNamesCache[$key] = $this->_rsm->fieldMappings[$key]; | |
case (isset($this->_rsm->newObjectMappings[$key])): | |
return $this->fieldNamesCache[$key] = $this->_rsm->scalarMappings[$key]; | |
case (isset($this->_rsm->metaMappings[$key])): | |
return $this->fieldNamesCache[$key] = $this->_rsm->metaMappings[$key]; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment