vendor/gedmo/doctrine-extensions/src/Tool/ORM/Hydration/HydratorCompat.php line 128

  1. <?php
  2. /*
  3.  * This file is part of the Doctrine Behavioral Extensions package.
  4.  * (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Gedmo\Tool\ORM\Hydration;
  9. use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
  10. // The methods we need the compat bridge for are protected, so we're using a public method for this check
  11. if ((new \ReflectionClass(AbstractHydrator::class))->getMethod('onClear')->hasReturnType()) {
  12.     // ORM 3.x
  13.     /**
  14.      * Helper trait to address compatibility issues between ORM 2.x and 3.x.
  15.      *
  16.      * @mixin AbstractHydrator
  17.      *
  18.      * @internal
  19.      */
  20.     trait HydratorCompat
  21.     {
  22.         /**
  23.          * Executes one-time preparation tasks, once each time hydration is started
  24.          * through {@link hydrateAll} or {@link toIterable()}.
  25.          */
  26.         protected function prepare(): void
  27.         {
  28.             $this->doPrepareWithCompat();
  29.         }
  30.         protected function doPrepareWithCompat(): void
  31.         {
  32.             parent::prepare();
  33.         }
  34.         /**
  35.          * Executes one-time cleanup tasks at the end of a hydration that was initiated
  36.          * through {@link hydrateAll} or {@link toIterable()}.
  37.          */
  38.         protected function cleanup(): void
  39.         {
  40.             $this->doCleanupWithCompat();
  41.         }
  42.         protected function doCleanupWithCompat(): void
  43.         {
  44.             parent::cleanup();
  45.         }
  46.         /**
  47.          * Hydrates all rows from the current statement instance at once.
  48.          */
  49.         protected function hydrateAllData(): array
  50.         {
  51.             return $this->doHydrateAllData();
  52.         }
  53.         /**
  54.          * @return mixed[]
  55.          */
  56.         protected function doHydrateAllData()
  57.         {
  58.             return parent::hydrateAllData();
  59.         }
  60.     }
  61. } else {
  62.     // ORM 2.x
  63.     /**
  64.      * Helper trait to address compatibility issues between ORM 2.x and 3.x.
  65.      *
  66.      * @mixin AbstractHydrator
  67.      *
  68.      * @internal
  69.      */
  70.     trait HydratorCompat
  71.     {
  72.         /**
  73.          * Executes one-time preparation tasks, once each time hydration is started
  74.          * through {@link hydrateAll} or {@link toIterable()}.
  75.          *
  76.          * @return void
  77.          */
  78.         protected function prepare()
  79.         {
  80.             $this->doPrepareWithCompat();
  81.         }
  82.         protected function doPrepareWithCompat(): void
  83.         {
  84.             parent::prepare();
  85.         }
  86.         /**
  87.          * Executes one-time cleanup tasks at the end of a hydration that was initiated
  88.          * through {@link hydrateAll} or {@link toIterable()}.
  89.          *
  90.          * @return void
  91.          */
  92.         protected function cleanup()
  93.         {
  94.             $this->doCleanupWithCompat();
  95.         }
  96.         protected function doCleanupWithCompat(): void
  97.         {
  98.             parent::cleanup();
  99.         }
  100.         /**
  101.          * Hydrates all rows from the current statement instance at once.
  102.          *
  103.          * @return mixed[]
  104.          */
  105.         protected function hydrateAllData()
  106.         {
  107.             return $this->doHydrateAllData();
  108.         }
  109.         /**
  110.          * @return mixed[]
  111.          */
  112.         protected function doHydrateAllData()
  113.         {
  114.             return parent::hydrateAllData();
  115.         }
  116.     }
  117. }