From 44859f796a65d266a9f1c0dc040b4dcd906dc0fe Mon Sep 17 00:00:00 2001 From: Tobias Gross-Vogt <tgros@tugraz.at> Date: Tue, 8 Feb 2022 13:01:28 +0100 Subject: [PATCH] extracted course trait from course --- src/Entity/Course.php | 73 +------------------------------ src/Entity/CourseInterface.php | 24 ++++++++++ src/Entity/CourseTrait.php | 80 ++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 71 deletions(-) create mode 100644 src/Entity/CourseInterface.php create mode 100644 src/Entity/CourseTrait.php diff --git a/src/Entity/Course.php b/src/Entity/Course.php index fbeae68..3daaa07 100644 --- a/src/Entity/Course.php +++ b/src/Entity/Course.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Dbp\Relay\CourseBundle\Entity; -use ApiPlatform\Core\Annotation\ApiProperty; use ApiPlatform\Core\Annotation\ApiResource; use Dbp\Relay\CourseBundle\Controller\GetCoursesByOrganization; use Symfony\Component\Serializer\Annotation\Groups; @@ -47,77 +46,9 @@ use Symfony\Component\Serializer\Annotation\Groups; * }, * iri="https://schema.org/Course", * normalizationContext={"groups" = {"Course:output"}, "jsonld_embed_context" = true}, - * denormalizationContext={"groups" = {"Course:input"}, "jsonld_embed_context" = true} * ) */ -class Course +class Course implements CourseInterface { - /** - * @ApiProperty(identifier=true) - */ - private $identifier; - - /** - * @ApiProperty(iri="https://schema.org/name") - * @Groups({"Course:output"}) - * - * @var string - */ - private $name; - - /** - * @ApiProperty - * @Groups({"Course:output"}) - * - * @var string - */ - private $type; - - /** - * @ApiProperty(iri="https://schema.org/description") - * @Groups({"Course:output"}) - * - * @var string - */ - private $description; - - public function getIdentifier(): string - { - return $this->identifier; - } - - public function setIdentifier(string $identifier): void - { - $this->identifier = $identifier; - } - - public function getName(): string - { - return $this->name; - } - - public function setName(string $name): void - { - $this->name = $name; - } - - public function getType(): string - { - return $this->type; - } - - public function setType(string $type): void - { - $this->type = $type; - } - - public function getDescription(): string - { - return $this->description; - } - - public function setDescription(string $description): void - { - $this->description = $description; - } + use CourseTrait; } diff --git a/src/Entity/CourseInterface.php b/src/Entity/CourseInterface.php new file mode 100644 index 0000000..e080e21 --- /dev/null +++ b/src/Entity/CourseInterface.php @@ -0,0 +1,24 @@ +<?php + +declare(strict_types=1); + +namespace Dbp\Relay\CourseBundle\Entity; + +interface CourseInterface +{ + public function getIdentifier(): string; + + public function setIdentifier(string $identifier): void; + + public function getName(): string; + + public function setName(string $name): void; + + public function getType(): string; + + public function setType(string $type): void; + + public function getDescription(): string; + + public function setDescription(string $description): void; +} diff --git a/src/Entity/CourseTrait.php b/src/Entity/CourseTrait.php new file mode 100644 index 0000000..fee2a48 --- /dev/null +++ b/src/Entity/CourseTrait.php @@ -0,0 +1,80 @@ +<?php + +declare(strict_types=1); + +namespace Dbp\Relay\CourseBundle\Entity; + +use ApiPlatform\Core\Annotation\ApiProperty; +use Symfony\Component\Serializer\Annotation\Groups; + +trait CourseTrait +{ + /** + * @ApiProperty(identifier=true) + */ + private $identifier; + + /** + * @ApiProperty(iri="https://schema.org/name") + * @Groups({"Course:output"}) + * + * @var string + */ + private $name; + + /** + * @ApiProperty + * @Groups({"Course:output"}) + * + * @var string + */ + private $type; + + /** + * @ApiProperty(iri="https://schema.org/description") + * @Groups({"Course:output"}) + * + * @var string + */ + private $description; + + public function getIdentifier(): string + { + return $this->identifier; + } + + public function setIdentifier(string $identifier): void + { + $this->identifier = $identifier; + } + + public function getName(): string + { + return $this->name; + } + + public function setName(string $name): void + { + $this->name = $name; + } + + public function getType(): string + { + return $this->type; + } + + public function setType(string $type): void + { + $this->type = $type; + } + + public function getDescription(): string + { + return $this->description; + } + + public function setDescription(string $description): void + { + $this->description = $description; + } +} -- GitLab