Skip to content

Commit fe679bf

Browse files
Zowacsoyuka
authored andcommitted
chore: move Doctrine/Common to his own component (api-platform#5572)
1 parent 304a967 commit fe679bf

23 files changed

+1364
-12
lines changed

src/Doctrine/Common/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/composer.lock
2+
/vendor
3+
/.phpunit.result.cache

src/Doctrine/Common/Filter/SearchFilterTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
namespace ApiPlatform\Doctrine\Common\Filter;
1515

1616
use ApiPlatform\Api\IdentifiersExtractorInterface;
17-
use ApiPlatform\Api\IriConverterInterface;
1817
use ApiPlatform\Doctrine\Common\PropertyHelperTrait;
1918
use ApiPlatform\Exception\InvalidArgumentException;
19+
use ApiPlatform\Metadata\IriConverterInterface;
2020
use Psr\Log\LoggerInterface;
2121
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
2222

src/Doctrine/Common/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT license
2+
3+
Copyright (c) 2015-present Kévin Dunglas
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is furnished
10+
to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

src/Doctrine/Common/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# API Platform - Doctrine Common
2+
3+
Common files used by api-platform/doctrine-orm and api-platform/doctrine-odm
4+
5+
## Resources
6+
7+

src/Doctrine/Common/State/PersistProcessor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use ApiPlatform\Metadata\Operation;
1818
use ApiPlatform\Metadata\Util\ClassInfoTrait;
1919
use ApiPlatform\State\ProcessorInterface;
20-
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
21-
use Doctrine\ORM\Mapping\ClassMetadataInfo;
2220
use Doctrine\Persistence\ManagerRegistry;
2321
use Doctrine\Persistence\ObjectManager as DoctrineObjectManager;
2422

@@ -115,7 +113,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
115113
private function isDeferredExplicit(DoctrineObjectManager $manager, $data): bool
116114
{
117115
$classMetadata = $manager->getClassMetadata($this->getObjectClass($data));
118-
if (($classMetadata instanceof ClassMetadataInfo || $classMetadata instanceof ClassMetadata) && method_exists($classMetadata, 'isChangeTrackingDeferredExplicit')) {
116+
if (method_exists($classMetadata, 'isChangeTrackingDeferredExplicit')) {
119117
return $classMetadata->isChangeTrackingDeferredExplicit();
120118
}
121119

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
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\Doctrine\Common\Tests\Fixtures\TestBundle\Entity;
15+
16+
use ApiPlatform\Metadata\ApiProperty;
17+
use ApiPlatform\Metadata\ApiResource;
18+
use ApiPlatform\Metadata\Get;
19+
use ApiPlatform\Metadata\Link;
20+
use Doctrine\Common\Collections\ArrayCollection;
21+
use Doctrine\Common\Collections\Collection;
22+
use Doctrine\ORM\Mapping as ORM;
23+
use Symfony\Component\Validator\Constraints as Assert;
24+
25+
/**
26+
* Dummy.
27+
*
28+
* @author Kévin Dunglas <[email protected]>
29+
*/
30+
#[ApiResource(filters: ['my_dummy.boolean', 'my_dummy.date', 'my_dummy.exists', 'my_dummy.numeric', 'my_dummy.order', 'my_dummy.range', 'my_dummy.search', 'my_dummy.property'], extraProperties: ['standard_put' => false])]
31+
#[ApiResource(uriTemplate: '/related_owned_dummies/{id}/owning_dummy{._format}', uriVariables: ['id' => new Link(fromClass: RelatedOwnedDummy::class, identifiers: ['id'], fromProperty: 'owningDummy')], status: 200, filters: ['my_dummy.boolean', 'my_dummy.date', 'my_dummy.exists', 'my_dummy.numeric', 'my_dummy.order', 'my_dummy.range', 'my_dummy.search', 'my_dummy.property'], operations: [new Get()])]
32+
#[ApiResource(uriTemplate: '/related_owning_dummies/{id}/owned_dummy{._format}', uriVariables: ['id' => new Link(fromClass: RelatedOwningDummy::class, identifiers: ['id'], fromProperty: 'ownedDummy')], status: 200, filters: ['my_dummy.boolean', 'my_dummy.date', 'my_dummy.exists', 'my_dummy.numeric', 'my_dummy.order', 'my_dummy.range', 'my_dummy.search', 'my_dummy.property'], operations: [new Get()])]
33+
#[ORM\Entity]
34+
class Dummy
35+
{
36+
/**
37+
* @var int|null The id
38+
*/
39+
#[ORM\Column(type: 'integer', nullable: true)]
40+
#[ORM\Id]
41+
#[ORM\GeneratedValue(strategy: 'AUTO')]
42+
private $id;
43+
44+
/**
45+
* @var string The dummy name
46+
*/
47+
#[ApiProperty(iris: ['https://schema.org/name'])]
48+
#[ORM\Column]
49+
#[Assert\NotBlank]
50+
private string $name;
51+
52+
/**
53+
* @var string|null The dummy name alias
54+
*/
55+
#[ApiProperty(iris: ['https://schema.org/alternateName'])]
56+
#[ORM\Column(nullable: true)]
57+
private $alias;
58+
59+
/**
60+
* @var array foo
61+
*/
62+
private ?array $foo = null;
63+
64+
/**
65+
* @var string|null A short description of the item
66+
*/
67+
#[ApiProperty(iris: ['https://schema.org/description'])]
68+
#[ORM\Column(nullable: true)]
69+
public $description;
70+
71+
/**
72+
* @var string|null A dummy
73+
*/
74+
#[ORM\Column(nullable: true)]
75+
public $dummy;
76+
77+
/**
78+
* @var bool|null A dummy boolean
79+
*/
80+
#[ORM\Column(type: 'boolean', nullable: true)]
81+
82+
public ?bool $dummyBoolean = null;
83+
/**
84+
* @var \DateTime|null A dummy date
85+
*/
86+
#[ApiProperty(iris: ['https://schema.org/DateTime'])]
87+
#[ORM\Column(type: 'datetime', nullable: true)]
88+
public $dummyDate;
89+
90+
/**
91+
* @var float|null A dummy float
92+
*/
93+
#[ORM\Column(type: 'float', nullable: true)]
94+
public $dummyFloat;
95+
96+
/**
97+
* @var string|null A dummy price
98+
*/
99+
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
100+
public $dummyPrice;
101+
102+
#[ApiProperty(push: true)]
103+
#[ORM\ManyToOne(targetEntity: RelatedDummy::class)]
104+
public ?RelatedDummy $relatedDummy = null;
105+
106+
#[ORM\ManyToMany(targetEntity: RelatedDummy::class)]
107+
public Collection|iterable $relatedDummies;
108+
109+
/**
110+
* @var array|null serialize data
111+
*/
112+
#[ORM\Column(type: 'json', nullable: true)]
113+
public $jsonData = [];
114+
115+
/**
116+
* @var array|null
117+
*/
118+
#[ORM\Column(type: 'simple_array', nullable: true)]
119+
public $arrayData = [];
120+
121+
/**
122+
* @var string|null
123+
*/
124+
#[ORM\Column(nullable: true)]
125+
public $nameConverted;
126+
127+
/**
128+
* @var RelatedOwnedDummy|null
129+
*/
130+
#[ORM\OneToOne(targetEntity: RelatedOwnedDummy::class, cascade: ['persist'], mappedBy: 'owningDummy')]
131+
public $relatedOwnedDummy;
132+
133+
/**
134+
* @var RelatedOwningDummy|null
135+
*/
136+
#[ORM\OneToOne(targetEntity: RelatedOwningDummy::class, cascade: ['persist'], inversedBy: 'ownedDummy')]
137+
public $relatedOwningDummy;
138+
139+
public static function staticMethod(): void
140+
{
141+
}
142+
143+
public function __construct()
144+
{
145+
$this->relatedDummies = new ArrayCollection();
146+
}
147+
148+
public function getId()
149+
{
150+
return $this->id;
151+
}
152+
153+
public function setId($id): void
154+
{
155+
$this->id = $id;
156+
}
157+
158+
public function setName(string $name): void
159+
{
160+
$this->name = $name;
161+
}
162+
163+
public function getName(): string
164+
{
165+
return $this->name;
166+
}
167+
168+
public function setAlias($alias): void
169+
{
170+
$this->alias = $alias;
171+
}
172+
173+
public function getAlias()
174+
{
175+
return $this->alias;
176+
}
177+
178+
public function setDescription($description): void
179+
{
180+
$this->description = $description;
181+
}
182+
183+
public function getDescription()
184+
{
185+
return $this->description;
186+
}
187+
188+
public function fooBar($baz): void
189+
{
190+
}
191+
192+
public function getFoo(): ?array
193+
{
194+
return $this->foo;
195+
}
196+
197+
public function setFoo(array $foo = null): void
198+
{
199+
$this->foo = $foo;
200+
}
201+
202+
public function setDummyDate(\DateTime $dummyDate = null): void
203+
{
204+
$this->dummyDate = $dummyDate;
205+
}
206+
207+
public function getDummyDate()
208+
{
209+
return $this->dummyDate;
210+
}
211+
212+
public function setDummyPrice($dummyPrice)
213+
{
214+
$this->dummyPrice = $dummyPrice;
215+
216+
return $this;
217+
}
218+
219+
public function getDummyPrice()
220+
{
221+
return $this->dummyPrice;
222+
}
223+
224+
public function setJsonData($jsonData): void
225+
{
226+
$this->jsonData = $jsonData;
227+
}
228+
229+
public function getJsonData()
230+
{
231+
return $this->jsonData;
232+
}
233+
234+
public function setArrayData($arrayData): void
235+
{
236+
$this->arrayData = $arrayData;
237+
}
238+
239+
public function getArrayData()
240+
{
241+
return $this->arrayData;
242+
}
243+
244+
public function getRelatedDummy(): ?RelatedDummy
245+
{
246+
return $this->relatedDummy;
247+
}
248+
249+
public function setRelatedDummy(RelatedDummy $relatedDummy): void
250+
{
251+
$this->relatedDummy = $relatedDummy;
252+
}
253+
254+
public function addRelatedDummy(RelatedDummy $relatedDummy): void
255+
{
256+
$this->relatedDummies->add($relatedDummy);
257+
}
258+
259+
public function getRelatedOwnedDummy()
260+
{
261+
return $this->relatedOwnedDummy;
262+
}
263+
264+
public function setRelatedOwnedDummy(RelatedOwnedDummy $relatedOwnedDummy): void
265+
{
266+
$this->relatedOwnedDummy = $relatedOwnedDummy;
267+
if ($this !== $this->relatedOwnedDummy->getOwningDummy()) {
268+
$this->relatedOwnedDummy->setOwningDummy($this);
269+
}
270+
}
271+
272+
public function getRelatedOwningDummy()
273+
{
274+
return $this->relatedOwningDummy;
275+
}
276+
277+
public function setRelatedOwningDummy(RelatedOwningDummy $relatedOwningDummy): void
278+
{
279+
$this->relatedOwningDummy = $relatedOwningDummy;
280+
}
281+
282+
public function isDummyBoolean(): ?bool
283+
{
284+
return $this->dummyBoolean;
285+
}
286+
287+
/**
288+
* @param bool $dummyBoolean
289+
*/
290+
public function setDummyBoolean($dummyBoolean): void
291+
{
292+
$this->dummyBoolean = $dummyBoolean;
293+
}
294+
295+
public function setDummy($dummy = null): void
296+
{
297+
$this->dummy = $dummy;
298+
}
299+
300+
public function getDummy()
301+
{
302+
return $this->dummy;
303+
}
304+
305+
public function getRelatedDummies(): Collection|iterable
306+
{
307+
return $this->relatedDummies;
308+
}
309+
}

0 commit comments

Comments
 (0)