-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an internal trait to allow cross-version compatibility for ORM hy…
…drators
- Loading branch information
Showing
4 changed files
with
144 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tool\ORM\Hydration; | ||
|
||
use Doctrine\ORM\Internal\Hydration\AbstractHydrator; | ||
|
||
// The methods we need the compat bridge for are protected, so we're using a public method for this check | ||
if ((new \ReflectionClass(AbstractHydrator::class))->getMethod('onClear')->hasReturnType()) { | ||
// ORM 3.x | ||
/** | ||
* Helper trait to address compatibility issues between ORM 2.x and 3.x. | ||
* | ||
* @mixin AbstractHydrator | ||
* | ||
* @internal | ||
*/ | ||
trait HydratorCompat | ||
{ | ||
/** | ||
* Executes one-time preparation tasks, once each time hydration is started | ||
* through {@link hydrateAll} or {@link toIterable()}. | ||
*/ | ||
protected function prepare(): void | ||
{ | ||
$this->doPrepareWithCompat(); | ||
} | ||
|
||
protected function doPrepareWithCompat(): void | ||
{ | ||
parent::prepare(); | ||
} | ||
|
||
/** | ||
* Executes one-time cleanup tasks at the end of a hydration that was initiated | ||
* through {@link hydrateAll} or {@link toIterable()}. | ||
*/ | ||
protected function cleanup(): void | ||
{ | ||
$this->doCleanupWithCompat(); | ||
} | ||
|
||
protected function doCleanupWithCompat(): void | ||
{ | ||
parent::cleanup(); | ||
} | ||
|
||
/** | ||
* Hydrates all rows from the current statement instance at once. | ||
*/ | ||
protected function hydrateAllData(): mixed | ||
{ | ||
return $this->doHydrateAllData(); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
protected function doHydrateAllData() | ||
{ | ||
return parent::hydrateAllData(); | ||
} | ||
} | ||
} else { | ||
// ORM 2.x | ||
/** | ||
* Helper trait to address compatibility issues between ORM 2.x and 3.x. | ||
* | ||
* @mixin AbstractHydrator | ||
* | ||
* @internal | ||
*/ | ||
trait HydratorCompat | ||
{ | ||
/** | ||
* Executes one-time preparation tasks, once each time hydration is started | ||
* through {@link hydrateAll} or {@link toIterable()}. | ||
* | ||
* @return void | ||
*/ | ||
protected function prepare() | ||
{ | ||
$this->doPrepareWithCompat(); | ||
} | ||
|
||
protected function doPrepareWithCompat(): void | ||
{ | ||
parent::prepare(); | ||
} | ||
|
||
/** | ||
* Executes one-time cleanup tasks at the end of a hydration that was initiated | ||
* through {@link hydrateAll} or {@link toIterable()}. | ||
* | ||
* @return void | ||
*/ | ||
protected function cleanup() | ||
{ | ||
$this->doCleanupWithCompat(); | ||
} | ||
|
||
protected function doCleanupWithCompat(): void | ||
{ | ||
parent::cleanup(); | ||
} | ||
|
||
/** | ||
* Hydrates all rows from the current statement instance at once. | ||
* | ||
* @return mixed[] | ||
*/ | ||
protected function hydrateAllData() | ||
{ | ||
return $this->doHydrateAllData(); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
protected function doHydrateAllData() | ||
{ | ||
return parent::hydrateAllData(); | ||
} | ||
} | ||
} |
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
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
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