Commit 24793846 authored by Guillaume Perréal's avatar Guillaume Perréal

Regénère @id et @type pour les ressources.

parent 9422cc38
......@@ -416,9 +416,11 @@ final class MetadataFactory implements MetadataFactoryInterface
$properties[$propertyName] = $property;
if ($property->isEmbedded()) {
$type = $property->getLeafType();
$className = $type->getClassName();
if ($className) {
$queue[] = PHPClass::get($className);
if ($type) {
$className = $type->getClassName();
if ($className) {
$queue[] = PHPClass::get($className);
}
}
}
}
......@@ -427,7 +429,7 @@ final class MetadataFactory implements MetadataFactoryInterface
$abstract = (new \ReflectionClass($current->getFullName()))->isAbstract();
$representations[$current->getFullName()] = new RepresentationMetadata($name, $current, $parent, $properties, $abstract);
$representations[$current->getFullName()] = new RepresentationMetadata($name, $current, $parent, $properties, $abstract, $this->isResource($current));
}
return new SerializationMetadata($class, $groups, $normalization, $representations);
......
......@@ -55,6 +55,9 @@ final class RepresentationMetadata implements ClassName, HasName
*/
private $abstract;
/** @var bool */
private $resource;
/**
* RepresentationMetadata constructor.
*
......@@ -63,7 +66,7 @@ final class RepresentationMetadata implements ClassName, HasName
* @param ClassName|null $parent
* @param PropertyMetadata[] $properties
*/
public function __construct(string $name, ClassName $class, ?ClassName $parent, array $properties, bool $abstract)
public function __construct(string $name, ClassName $class, ?ClassName $parent, array $properties, bool $abstract, bool $resource)
{
if ($parent && $class->getFullName() === $parent->getFullName()) {
throw new DomainException("$class cannot be its own parent");
......@@ -79,6 +82,7 @@ final class RepresentationMetadata implements ClassName, HasName
$this->name = $name;
$this->abstract = $abstract;
$this->resource = $resource;
}
/**
......@@ -153,6 +157,16 @@ final class RepresentationMetadata implements ClassName, HasName
return $this->abstract;
}
/**
* Get resource.
*
* @return bool
*/
public function isResource(): bool
{
return $this->resource;
}
/**
* {@inheritdoc}
*/
......
......@@ -55,14 +55,18 @@ final class ClassInfo implements ClassName
/** @var bool */
private $abstract;
/** @var bool */
private $resource;
/**
* ClassInfo constructor.
*
* @param ClassName $class
* @param ClassName $class
* @param PropertyMetadata[] $properties
* @param bool $abstract
* @param bool $abstract
* @param bool $resource
*/
public function __construct(ClassName $class, array $properties = [], bool $abstract = false)
public function __construct(ClassName $class, array $properties = [], bool $abstract = false, bool $resource = false)
{
$this->class = $class;
$this->abstract = $abstract;
......@@ -71,6 +75,7 @@ final class ClassInfo implements ClassName
$this->virtualProperties[$property->getName()] = $property;
}
$this->concreteProperties = $abstract ? [] : $this->virtualProperties;
$this->resource = $resource;
}
/**
......@@ -127,6 +132,16 @@ final class ClassInfo implements ClassName
return $this->abstract;
}
/**
* Get resource.
*
* @return bool
*/
public function isResource(): bool
{
return $this->resource;
}
/**
* Get parent.
*
......
......@@ -254,7 +254,7 @@ final class SerializationMapper implements TypeFactoryInterface
);
}
if ($this->withAtFields && $identifierCount > 0) {
if ($this->withAtFields && $classInfo->isResource()) {
$properties['@id'] = new Property(
'@id',
'',
......@@ -374,7 +374,8 @@ final class SerializationMapper implements TypeFactoryInterface
$this->classInfo[$className] = new ClassInfo(
$repr,
$repr->getProperties(),
$repr->isAbstract()
$repr->isAbstract(),
$repr->isResource()
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment