vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  *
  15.  * This software consists of voluntary contributions made by many individuals
  16.  * and is licensed under the MIT license. For more information, see
  17.  * <http://www.doctrine-project.org>.
  18.  */
  19. namespace Doctrine\ORM\Internal\Hydration;
  20. use Doctrine\ORM\NonUniqueResultException;
  21. use Doctrine\ORM\NoResultException;
  22. use PDO;
  23. use function array_shift;
  24. use function count;
  25. use function key;
  26. /**
  27.  * Hydrator that hydrates a single scalar value from the result set.
  28.  */
  29. class SingleScalarHydrator extends AbstractHydrator
  30. {
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     protected function hydrateAllData()
  35.     {
  36.         $data    $this->_stmt->fetchAll(PDO::FETCH_ASSOC);
  37.         $numRows count($data);
  38.         if ($numRows === 0) {
  39.             throw new NoResultException();
  40.         }
  41.         if ($numRows 1) {
  42.             throw new NonUniqueResultException('The query returned multiple rows. Change the query or use a different result function like getScalarResult().');
  43.         }
  44.         if (count($data[key($data)]) > 1) {
  45.             throw new NonUniqueResultException('The query returned a row containing multiple columns. Change the query or use a different result function like getScalarResult().');
  46.         }
  47.         $result $this->gatherScalarRowData($data[key($data)]);
  48.         return array_shift($result);
  49.     }
  50. }