123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Entity;
- abstract class AbstractEntity {
-
- private $name;
- private $slug;
- private $data = [];
- protected function setFromData(array $data) {
- foreach ($data as $key => $value) {
- $prop = ltrim($key, '_');
- $method = sprintf("set%s", ucfirst(
- $prop
- ));
- if (method_exists($this, $method)) {
- [$this, $method]($value);
- } elseif (property_exists($this, $prop)) {
- $this->{$prop} = $value;
- } else {
- if (property_exists($this, 'data')) {
- if (isset($this->data[$key]))
- continue;
- if (strpos($key, '-') !== false)
- continue;
- $this->data[$key] = $value;
- }
- }
- }
- }
- public function getName(): ?string {
- return $this->name;
- }
- public function setName(string $name): self {
- $this->name = $name;
- return $this;
- }
- public function getSlug(): ?string {
- return $this->slug;
- }
- public function setSlug(string $slug): self {
- $this->slug = $slug;
- return $this;
- }
- public function getData(): ?array {
- return $this->data;
- }
- }
|