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.

40 lines
747B

  1. <?php
  2. namespace App\Contexts\Model;
  3. use App\Features\InstanceAble;
  4. use Illuminate\Database\Eloquent\Model;
  5. use LogicException;
  6. /**
  7. * @template TValue of Model
  8. */
  9. abstract class ModelContext
  10. {
  11. use InstanceAble;
  12. /** @var ?TValue $model */
  13. private ?Model $model = null;
  14. /**
  15. * @param TValue $model
  16. * @param boolean $override
  17. * @return void
  18. */
  19. public function set($model, bool $override = false)
  20. {
  21. if ($this->model !== null && $override === false) {
  22. throw new LogicException("コンテキスト 不正オーバーライド");
  23. }
  24. $this->model = $model;
  25. }
  26. /**
  27. * @return TValue
  28. */
  29. public function get()
  30. {
  31. return $this->model;
  32. }
  33. }