You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
829 B

7 days ago
7 days ago
7 days ago
  1. <?php
  2. namespace OSM\Element\Member;
  3. class Member
  4. {
  5. public int $ref;
  6. public string $role;
  7. public static function createFromArray($array)
  8. {
  9. assert(is_array($array));
  10. $hasType = isset($array['type']);
  11. assert($hasType);
  12. $className = __NAMESPACE__.'\\'.ucfirst($array['type']);
  13. $hasClass = class_exists($className);
  14. $instance = new $className();
  15. $hasRef = isset($array['ref']);
  16. assert($hasRef);
  17. $instance->ref = (int) $array['ref'];
  18. $hasRole = isset($array['role']);
  19. assert($hasRole);
  20. $instance->role = (string) $array['role'];
  21. $instance->completeFromArray($array);
  22. return $instance;
  23. }
  24. public function isSame(Member $other): bool
  25. {
  26. return $this->ref === $other->ref;
  27. }
  28. }