-
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
81 additions
and
22 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Internal\Hydration; | ||
|
||
use Doctrine\ORM\Configuration; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Exception\InvalidHydrationMode; | ||
use Doctrine\ORM\Query; | ||
|
||
final class DefaultHydratorFactory implements HydratorFactory | ||
{ | ||
public function create(EntityManagerInterface $em, Configuration $config, string|int $hydrationMode): AbstractHydrator | ||
{ | ||
return match ($hydrationMode) { | ||
Query::HYDRATE_OBJECT => new ObjectHydrator($em), | ||
Query::HYDRATE_ARRAY => new ArrayHydrator($em), | ||
Query::HYDRATE_SCALAR => new ScalarHydrator($em), | ||
Query::HYDRATE_SINGLE_SCALAR => new SingleScalarHydrator($em), | ||
Query::HYDRATE_SIMPLEOBJECT => new SimpleObjectHydrator($em), | ||
Query::HYDRATE_SCALAR_COLUMN => new ScalarColumnHydrator($em), | ||
default => $this->createCustomHydrator((string) $hydrationMode, $em, $config), | ||
}; | ||
} | ||
|
||
private function createCustomHydrator(string $hydrationMode, EntityManagerInterface $em, Configuration $config): AbstractHydrator | ||
{ | ||
$class = $config->getCustomHydrationMode($hydrationMode); | ||
|
||
if ($class !== null) { | ||
return new $class($em); | ||
} | ||
|
||
throw InvalidHydrationMode::fromMode($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,19 @@ | ||
<?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. | ||
* | ||
* @psalm-param string|AbstractQuery::HYDRATE_* $hydrationMode | ||
*/ | ||
public function create(EntityManagerInterface $em, Configuration $config, string|int $hydrationMode): AbstractHydrator; | ||
} |