AccidentCasesFocusObj.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace common\util;
  3. use common\models\AccidentCases;
  4. use JsonSerializable;
  5. /**
  6. * Class AccidentCasesFocusObj
  7. * @package common\util
  8. * @property int $id
  9. * @property string $title
  10. * @property string images
  11. * @property int start_time
  12. */
  13. class AccidentCasesFocusObj implements JsonSerializable
  14. {
  15. private int $id;
  16. private ?string $title;
  17. private ?string $images;
  18. private ?int $start_time;
  19. /**
  20. * @return int
  21. */
  22. public function getId(): int
  23. {
  24. return $this->id;
  25. }
  26. /**
  27. * @param int $id
  28. */
  29. public function setId(int $id): void
  30. {
  31. $this->id = $id;
  32. }
  33. /**
  34. * @return string
  35. */
  36. public function getTitle(): string
  37. {
  38. return $this->title;
  39. }
  40. /**
  41. * @param string $title
  42. */
  43. public function setTitle(string $title): void
  44. {
  45. $this->title = $title;
  46. }
  47. public function __construct(AccidentCases $AccidentCases)
  48. {
  49. $this->id = $AccidentCases->id;
  50. $this->title = $AccidentCases->title;
  51. $this->images = $AccidentCases->images;
  52. $this->start_time = $AccidentCases->start_time;
  53. }
  54. /**
  55. * json_encode无法转化私有属性,需要使用jsonSerialize自定义转换私有的属性
  56. * @return array
  57. */
  58. public function jsonSerialize(): array
  59. {
  60. return [
  61. "id" => $this->id,
  62. "title" => $this->title,
  63. "images" => $this->images,
  64. "start_time" => $this->start_time,
  65. ];
  66. }
  67. }