AbstractHydrator.php
9 months ago
ArrayHydrator.php
9 months ago
HydrationException.php
9 months ago
IterableResult.php
9 months ago
ObjectHydrator.php
9 months ago
ScalarColumnHydrator.php
9 months ago
ScalarHydrator.php
9 months ago
SimpleObjectHydrator.php
9 months ago
SingleScalarHydrator.php
9 months ago
index.php
9 months ago
SingleScalarHydrator.php
29 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Internal\Hydration; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\NonUniqueResultException; |
| 6 | use MailPoetVendor\Doctrine\ORM\NoResultException; |
| 7 | use function array_shift; |
| 8 | use function count; |
| 9 | use function key; |
| 10 | class SingleScalarHydrator extends AbstractHydrator |
| 11 | { |
| 12 | protected function hydrateAllData() |
| 13 | { |
| 14 | $data = $this->statement()->fetchAllAssociative(); |
| 15 | $numRows = count($data); |
| 16 | if ($numRows === 0) { |
| 17 | throw new NoResultException(); |
| 18 | } |
| 19 | if ($numRows > 1) { |
| 20 | throw new NonUniqueResultException('The query returned multiple rows. Change the query or use a different result function like getScalarResult().'); |
| 21 | } |
| 22 | $result = $this->gatherScalarRowData($data[key($data)]); |
| 23 | if (count($result) > 1) { |
| 24 | throw new NonUniqueResultException('The query returned a row containing multiple columns. Change the query or use a different result function like getScalarResult().'); |
| 25 | } |
| 26 | return array_shift($result); |
| 27 | } |
| 28 | } |
| 29 |