領収証発行サービス
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

61 行
1.2KB

  1. <?php
  2. namespace App\Logic\Contract;
  3. use App\Models\Contract;
  4. use LogicException;
  5. abstract class ContractManager
  6. {
  7. // ------------MEMBER----
  8. protected Contract $contract;
  9. protected bool $initialized = false;
  10. // -------------PUBLIC--------
  11. public function initById(string $id): static
  12. {
  13. $contract = Contract::findOrFail($id);
  14. $this->contract = $contract;
  15. $this->initialized = true;
  16. return $this;
  17. }
  18. public function initForCreate(): static
  19. {
  20. $contract = new Contract();
  21. $contract->setId();
  22. $this->contract = $contract;
  23. $this->initialized = true;
  24. return $this;
  25. }
  26. public function fill(array $attr): static
  27. {
  28. if (!$this->initialized) {
  29. throw new LogicException("初期化ミス");
  30. }
  31. $this->contract->fill($attr);
  32. return $this;
  33. }
  34. public function id(): string
  35. {
  36. if (!$this->initialized) {
  37. throw new LogicException("初期化ミス");
  38. }
  39. return $this->contract->id;
  40. }
  41. // ----------------PROTECTED----------
  42. protected function save(): static
  43. {
  44. $this->contract->save();
  45. return $this;
  46. }
  47. }