-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add HydrationFactory as extension point for tracking hydrations
- Loading branch information
Showing
5 changed files
with
96 additions
and
33 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
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
48 changes: 48 additions & 0 deletions
48
lib/Doctrine/ORM/Internal/Hydration/DefaultHydratorFactory.php
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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Internal\Hydration; | ||
|
||
use Doctrine\ORM\AbstractQuery; | ||
use Doctrine\ORM\Configuration; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Exception\InvalidHydrationMode; | ||
|
||
final class DefaultHydratorFactory implements HydratorFactory | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function create(EntityManagerInterface $em, Configuration $config, $hydrationMode): AbstractHydrator | ||
{ | ||
switch ($hydrationMode) { | ||
case AbstractQuery::HYDRATE_OBJECT: | ||
return new ObjectHydrator($em); | ||
|
||
case AbstractQuery::HYDRATE_ARRAY: | ||
return new ArrayHydrator($em); | ||
|
||
case AbstractQuery::HYDRATE_SCALAR: | ||
return new ScalarHydrator($em); | ||
|
||
case AbstractQuery::HYDRATE_SINGLE_SCALAR: | ||
return new SingleScalarHydrator($em); | ||
|
||
case AbstractQuery::HYDRATE_SIMPLEOBJECT: | ||
return new SimpleObjectHydrator($em); | ||
|
||
case AbstractQuery::HYDRATE_SCALAR_COLUMN: | ||
return new ScalarColumnHydrator($em); | ||
|
||
default: | ||
$class = $config->getCustomHydrationMode($hydrationMode); | ||
|
||
if ($class !== null) { | ||
return new $class($em); | ||
} | ||
} | ||
|
||
throw InvalidHydrationMode::fromMode((string) $hydrationMode); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Internal\Hydration; | ||
|
||
use Doctrine\ORM\AbstractQuery; | ||
use Doctrine\ORM\Configuration; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
interface HydratorFactory | ||
{ | ||
/** | ||
* Create a new instance for the given hydration mode. | ||
* | ||
* @param string|int $hydrationMode | ||
* @psalm-param string|AbstractQuery::HYDRATE_* $hydrationMode | ||
*/ | ||
public function create(EntityManagerInterface $em, Configuration $config, $hydrationMode): AbstractHydrator; | ||
} |
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