File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
Fixtures/TestBundle/Document Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 87
87
use ApiPlatform \Tests \Fixtures \TestBundle \Document \SoMany as SoManyDocument ;
88
88
use ApiPlatform \Tests \Fixtures \TestBundle \Document \Taxon as TaxonDocument ;
89
89
use ApiPlatform \Tests \Fixtures \TestBundle \Document \ThirdLevel as ThirdLevelDocument ;
90
+ use ApiPlatform \Tests \Fixtures \TestBundle \Document \UidBasedId as UidBasedIdDocument ;
90
91
use ApiPlatform \Tests \Fixtures \TestBundle \Document \UrlEncodedId as UrlEncodedIdDocument ;
91
92
use ApiPlatform \Tests \Fixtures \TestBundle \Document \User as UserDocument ;
92
93
use ApiPlatform \Tests \Fixtures \TestBundle \Document \VideoGame as VideoGameDocument ;
@@ -1376,7 +1377,7 @@ public function thereIsAUrlEncodedIdResource(): void
1376
1377
*/
1377
1378
public function thereIsAUidBasedIdResource (string $ id ): void
1378
1379
{
1379
- $ uidBasedIdResource = ($ this ->isOrm () ? new UidBasedId (Ulid::fromBase32 ($ id )) : throw new \ RuntimeException ( ' TODO ' ));
1380
+ $ uidBasedIdResource = ($ this ->isOrm () ? new UidBasedId (Ulid::fromBase32 ($ id )) : new UidBasedIdDocument (Ulid:: fromBase32 ( $ id ) ));
1380
1381
$ this ->manager ->persist ($ uidBasedIdResource );
1381
1382
$ this ->manager ->flush ();
1382
1383
$ this ->manager ->clear ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Tests \Fixtures \TestBundle \Document ;
15
+
16
+ use ApiPlatform \Doctrine \Orm \Filter \SearchFilter ;
17
+ use ApiPlatform \Metadata \ApiFilter ;
18
+ use ApiPlatform \Metadata \ApiResource ;
19
+ use ApiPlatform \Metadata \Get ;
20
+ use ApiPlatform \Metadata \GetCollection ;
21
+ use ApiPlatform \Metadata \Post ;
22
+ use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
23
+ use Symfony \Component \Uid \Ulid ;
24
+
25
+ /**
26
+ * @author Beno!t POLASZEK <[email protected] >
27
+ *
28
+ * Resource with an Uid-based ID
29
+ */
30
+ #[ApiResource(operations: [new Get (), new Post (), new GetCollection ()])]
31
+ #[ApiFilter(SearchFilter::class, properties: ['id ' => 'exact ' ])]
32
+ #[ODM \Document]
33
+ class UidBasedId
34
+ {
35
+ #[ODM \Id(strategy: 'none ' )]
36
+ public Ulid $ id ;
37
+
38
+ public function __construct (?Ulid $ id )
39
+ {
40
+ $ this ->id = $ id ?? new Ulid ();
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments