Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DoctrineBridge] Add argument toEntityValueResolver to set type aliases#54545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,8 @@ public function __construct(
private ManagerRegistry $registry,
private ?ExpressionLanguage $expressionLanguage = null,
private MapEntity $defaults = new MapEntity(),
/** @var array<class-string, class-string> */
private readonly array $typeAliases = [],
) {
}

Expand All@@ -50,6 +52,9 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
if (!$options->class || $options->disabled) {
return [];
}

$options->class = $this->typeAliases[$options->class] ?? $options->class;

if (!$manager = $this->getManager($options->objectManager, $options->class)) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletionsrc/Symfony/Bridge/Doctrine/Attribute/MapEntity.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,7 +53,7 @@ public function __construct(
public function withDefaults(self $defaults, ?string $class): static
{
$clone = clone $this;
$clone->class ??= class_exists($class ?? '') ? $class : null;
$clone->class ??= class_exists($class ?? '')|| interface_exists($class ?? '', false)? $class : null;
$clone->objectManager ??= $defaults->objectManager;
$clone->expr ??= $defaults->expr;
$clone->mapping ??= $defaults->mapping;
Expand Down
1 change: 1 addition & 0 deletionssrc/Symfony/Bridge/Doctrine/CHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ CHANGELOG
---

* Accept `ReadableCollection` in `CollectionToArrayTransformer`
* Add type aliases support to `EntityValueResolver`

7.1
---
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -125,6 +125,42 @@ public function testResolveWithId(string|int $id)
$this->assertSame([$object], $resolver->resolve($request, $argument));
}

/**
* @dataProvider idsProvider
*/
public function testResolveWithIdAndTypeAlias(string|int $id)
{
$manager = $this->getMockBuilder(ObjectManager::class)->getMock();
$registry = $this->createRegistry($manager);
$resolver = new EntityValueResolver(
$registry,
null,
new MapEntity(),
// Using \Throwable because it is an interface
['Throwable' => 'stdClass'],
);

$request = new Request();
$request->attributes->set('id', $id);

$argument = $this->createArgument('Throwable', $mapEntity = new MapEntity(id: 'id'));

$repository = $this->getMockBuilder(ObjectRepository::class)->getMock();
$repository->expects($this->once())
->method('find')
->with($id)
->willReturn($object = new \stdClass());

$manager->expects($this->once())
->method('getRepository')
->with('stdClass')
->willReturn($repository);

$this->assertSame([$object], $resolver->resolve($request, $argument));
// Ensure the original MapEntity object was not updated
$this->assertNull($mapEntity->class);
}

public function testResolveWithNullId()
{
$manager = $this->createMock(ObjectManager::class);
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp