Skip to content

Commit b1cdf5d

Browse files
committed
Merge 4.1
2 parents d48c291 + e9ef4c7 commit b1cdf5d

17 files changed

+1704
-98075
lines changed

Eloquent/Metadata/ModelMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public function getAttributes(Model $model): Collection
101101
}
102102

103103
/**
104-
* @param array<int, array{columns: string[]}> $indexes
104+
* @param array<int, array{columns: string[], primary?: bool}> $indexes
105105
*/
106106
private function isColumnPrimaryKey(array $indexes, string $column): bool
107107
{
108108
foreach ($indexes as $index) {
109-
if (\in_array($column, $index['columns'], true)) {
109+
if (\in_array($column, $index['columns'], true) && (true === ($index['primary'] ?? false))) {
110110
return true;
111111
}
112112
}

Eloquent/State/PersistProcessor.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
use ApiPlatform\Metadata\HttpOperation;
1919
use ApiPlatform\Metadata\Operation;
2020
use ApiPlatform\State\ProcessorInterface;
21+
use Illuminate\Database\Eloquent\Collection;
2122
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2223
use Illuminate\Database\Eloquent\Relations\HasMany;
24+
use Illuminate\Database\Eloquent\Relations\MorphMany;
25+
use Illuminate\Database\Eloquent\Relations\MorphTo;
2326

2427
/**
2528
* @implements ProcessorInterface<\Illuminate\Database\Eloquent\Model, \Illuminate\Database\Eloquent\Model>
@@ -45,7 +48,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
4548
continue;
4649
}
4750

48-
if (BelongsTo::class === $relation['type']) {
51+
if (BelongsTo::class === $relation['type'] || MorphTo::class === $relation['type']) {
4952
$rel = $data->{$relation['name']};
5053

5154
if (!$rel->exists) {
@@ -57,10 +60,10 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
5760
$this->relations[$relation['method_name']] = $relation['name'];
5861
}
5962

60-
if (HasMany::class === $relation['type']) {
63+
if (HasMany::class === $relation['type'] || MorphMany::class === $relation['type']) {
6164
$rel = $data->{$relation['name']};
6265

63-
if (!\is_array($rel)) {
66+
if (!\is_array($rel) && !$rel instanceof Collection) {
6467
throw new RuntimeException('To-Many relationship is not a collection.');
6568
}
6669

State/AccessCheckerProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
2222

2323
/**
24-
* Allows access based on the ApiPlatform\Symfony\Security\ResourceAccessCheckerInterface.
24+
* Allows access based on the ApiPlatform\Metadata\ResourceAccessCheckerInterface.
2525
* This implementation covers GraphQl and HTTP.
2626
*
2727
* @see ResourceAccessCheckerInterface

Tests/EloquentTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,19 @@ public function testRelationIsHandledOnCreateWithNestedDataToMany(): void
523523
],
524524
]);
525525
}
526+
527+
public function testPostWithEmptyMorphMany(): void
528+
{
529+
$response = $this->postJson('/api/post_with_morph_manies', [
530+
'title' => 'My first post',
531+
'content' => 'This is the content of my first post.',
532+
'comments' => [['content' => 'hello']],
533+
], ['accept' => 'application/ld+json', 'content-type' => 'application/ld+json']);
534+
$response->assertStatus(201);
535+
$response->assertJson([
536+
'title' => 'My first post',
537+
'content' => 'This is the content of my first post.',
538+
'comments' => [['content' => 'hello']],
539+
]);
540+
}
526541
}

Tests/ValidationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,12 @@ public function testValidationSnakeCase(): void
5757
$response = $this->postJson('/api/issue_6932', $data, ['accept' => 'application/ld+json', 'content-type' => 'application/ld+json']);
5858
$response->assertStatus(422);
5959
}
60+
61+
public function testRouteWithRequirements(): void
62+
{
63+
$response = $this->get('api/issue_7194_requirements/test', ['accept' => 'application/ld+json']);
64+
$response->assertStatus(404);
65+
$response = $this->get('api/issue_7194_requirements/1', ['accept' => 'application/ld+json']);
66+
$response->assertStatus(200);
67+
}
6068
}

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
},
8787
"branch-alias": {
8888
"dev-main": "4.2.x-dev",
89-
"dev-3.4": "3.4.x-dev"
89+
"dev-3.4": "3.4.x-dev",
90+
"dev-4.1": "4.1.x-dev"
9091
},
9192
"symfony": {
9293
"require": "^6.4 || ^7.1"
@@ -126,5 +127,6 @@
126127
"type": "vcs",
127128
"url": "https://github.com/soyuka/phpunit"
128129
}
129-
]
130+
],
131+
"version": "v4.1.15"
130132
}

0 commit comments

Comments
 (0)