Skip to content

Commit 3a1961f

Browse files
authored
Merge pull request #1696 from dunglas/revert-1528
Revert "alwaysIdentifier annotation option implementation"
2 parents 34151e8 + 5a72ce4 commit 3a1961f

File tree

10 files changed

+4
-317
lines changed

10 files changed

+4
-317
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
declare(strict_types=1);
1313

14-
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\AlwaysIdentifierDummy;
1514
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Answer;
1615
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeItem;
1716
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeLabel;
@@ -862,24 +861,6 @@ public function thereAreDummyDateObjectsWithDummyDate(int $nb)
862861
$this->manager->flush();
863862
}
864863

865-
/**
866-
* @Given there are AlwaysIdentifierDummies
867-
*/
868-
public function thereAreAlwaysIdentifierDummies()
869-
{
870-
$mainDummy = new AlwaysIdentifierDummy();
871-
$relatedDummy = new AlwaysIdentifierDummy();
872-
873-
$this->manager->persist($relatedDummy);
874-
875-
$mainDummy->setParent($relatedDummy);
876-
$mainDummy->setChildren([$relatedDummy]);
877-
$mainDummy->setRelated([$relatedDummy]);
878-
879-
$this->manager->persist($mainDummy);
880-
$this->manager->flush();
881-
}
882-
883864
/**
884865
* @Given there are :nb dummyimmutabledate objects with dummyDate
885866
*/

features/hal/always_identifier.feature

Lines changed: 0 additions & 52 deletions
This file was deleted.

features/json/always_identifier.feature

Lines changed: 0 additions & 28 deletions
This file was deleted.

features/jsonld/always_identifier.feature

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Annotation/ApiProperty.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,4 @@ final class ApiProperty
6767
* @var array
6868
*/
6969
public $attributes = [];
70-
71-
/**
72-
* @var bool
73-
*/
74-
public $alwaysIdentifier;
7570
}

src/Metadata/Property/Factory/AnnotationPropertyMetadataFactory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,12 @@ private function createMetadata(ApiProperty $annotation, PropertyMetadata $paren
117117
$annotation->identifier,
118118
$annotation->iri,
119119
null,
120-
$annotation->attributes,
121-
null,
122-
$annotation->alwaysIdentifier
120+
$annotation->attributes
123121
);
124122
}
125123

126124
$propertyMetadata = $parentPropertyMetadata;
127-
foreach ([['get', 'description'], ['is', 'readable'], ['is', 'writable'], ['is', 'readableLink'], ['is', 'writableLink'], ['is', 'required'], ['get', 'iri'], ['is', 'identifier'], ['get', 'attributes'], ['is', 'alwaysIdentifier']] as $property) {
125+
foreach ([['get', 'description'], ['is', 'readable'], ['is', 'writable'], ['is', 'readableLink'], ['is', 'writableLink'], ['is', 'required'], ['get', 'iri'], ['is', 'identifier'], ['get', 'attributes']] as $property) {
128126
if (null !== $value = $annotation->{$property[1]}) {
129127
$propertyMetadata = $this->createWith($propertyMetadata, $property, $value);
130128
}

src/Metadata/Property/PropertyMetadata.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ final class PropertyMetadata
3434
private $childInherited;
3535
private $attributes;
3636
private $subresource;
37-
private $alwaysIdentifier;
3837

39-
public function __construct(Type $type = null, string $description = null, bool $readable = null, bool $writable = null, bool $readableLink = null, bool $writableLink = null, bool $required = null, bool $identifier = null, string $iri = null, $childInherited = null, array $attributes = null, SubresourceMetadata $subresource = null, bool $alwaysIdentifier = null)
38+
public function __construct(Type $type = null, string $description = null, bool $readable = null, bool $writable = null, bool $readableLink = null, bool $writableLink = null, bool $required = null, bool $identifier = null, string $iri = null, $childInherited = null, array $attributes = null, SubresourceMetadata $subresource = null)
4039
{
4140
$this->type = $type;
4241
$this->description = $description;
@@ -50,7 +49,6 @@ public function __construct(Type $type = null, string $description = null, bool
5049
$this->childInherited = $childInherited;
5150
$this->attributes = $attributes;
5251
$this->subresource = $subresource;
53-
$this->alwaysIdentifier = $alwaysIdentifier;
5452
}
5553

5654
/**
@@ -383,25 +381,4 @@ public function withSubresource(SubresourceMetadata $subresource = null): self
383381

384382
return $metadata;
385383
}
386-
387-
/**
388-
* Returns a new instance with the given alwaysIdentifier flag.
389-
*/
390-
public function withAlwaysIdentifier(bool $alwaysIdentifier): self
391-
{
392-
$metadata = clone $this;
393-
$metadata->alwaysIdentifier = $alwaysIdentifier;
394-
395-
return $metadata;
396-
}
397-
398-
/**
399-
* Is the property should be serialized as identifier ?
400-
*
401-
* @return bool|null
402-
*/
403-
public function isAlwaysIdentifier()
404-
{
405-
return $this->alwaysIdentifier;
406-
}
407384
}

src/Serializer/AbstractItemNormalizer.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ abstract class AbstractItemNormalizer extends AbstractObjectNormalizer
3939
{
4040
use ContextTrait;
4141

42-
const ALWAYS_IDENTIFIER = 'always_identifier';
43-
4442
protected $propertyNameCollectionFactory;
4543
protected $propertyMetadataFactory;
4644
protected $iriConverter;
@@ -99,10 +97,6 @@ public function normalize($object, $format = null, array $context = [])
9997
$context['resources'][$resource] = $resource;
10098
}
10199

102-
if ($context[self::ALWAYS_IDENTIFIER] ?? false) {
103-
return $context['iri'] ?? $this->iriConverter->getIriFromItem($object);
104-
}
105-
106100
return parent::normalize($object, $format, $context);
107101
}
108102

@@ -403,8 +397,6 @@ protected function getAttributeValue($object, $attribute, $format = null, array
403397
{
404398
$propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $attribute, $this->getFactoryOptions($context));
405399

406-
$context[self::ALWAYS_IDENTIFIER] = $propertyMetadata->isAlwaysIdentifier();
407-
408400
try {
409401
$attributeValue = $this->propertyAccessor->getValue($object, $attribute);
410402
} catch (NoSuchPropertyException $e) {

tests/Fixtures/TestBundle/Entity/AlwaysIdentifierDummy.php

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)