WebHook.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace Plugin\WebHooks\Entity;
  20. use App\Core\Entity;
  21. use DateTimeInterface;
  22. class WebHook extends Entity
  23. {
  24. // {{{ Autocode
  25. // @codeCoverageIgnoreStart
  26. private int $actor_id;
  27. private string $event;
  28. private string $target;
  29. private DateTimeInterface $created;
  30. private DateTimeInterface $modified;
  31. public function setActorId(int $actor_id): self
  32. {
  33. $this->actor_id = $actor_id;
  34. return $this;
  35. }
  36. public function getActorId(): int
  37. {
  38. return $this->actor_id;
  39. }
  40. public function setEvent(string $event): self
  41. {
  42. $this->event = mb_substr($event, 0, 32);
  43. return $this;
  44. }
  45. public function getEvent(): string
  46. {
  47. return $this->event;
  48. }
  49. public function setTarget(string $target): self
  50. {
  51. $this->target = $target;
  52. return $this;
  53. }
  54. public function getTarget(): string
  55. {
  56. return $this->target;
  57. }
  58. public function setCreated(DateTimeInterface $created): self
  59. {
  60. $this->created = $created;
  61. return $this;
  62. }
  63. public function getCreated(): DateTimeInterface
  64. {
  65. return $this->created;
  66. }
  67. public function setModified(DateTimeInterface $modified): self
  68. {
  69. $this->modified = $modified;
  70. return $this;
  71. }
  72. public function getModified(): DateTimeInterface
  73. {
  74. return $this->modified;
  75. }
  76. // @codeCoverageIgnoreEnd
  77. // }}} Autocode
  78. public static function schemaDef(): array
  79. {
  80. return [
  81. 'name' => 'webhook',
  82. 'fields' => [
  83. 'actor_id' => ['type' => 'int', 'not null' => true, 'actor who made this hook'],
  84. 'event' => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'name of the event this is a hook for'],
  85. 'target' => ['type' => 'text', 'not null' => true, 'description' => 'the target URL to POST to'],
  86. 'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'],
  87. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  88. ],
  89. 'primary key' => ['actor_id', 'event'],
  90. 'indexes' => [
  91. 'webhook_actor_id_idx' => ['actor_id'],
  92. ],
  93. ];
  94. }
  95. }