Du kannst nicht mehr als 25 Themen auswählen
Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
|
- <?php
-
- namespace App\Logic\Contract;
-
- use App\Models\Contract;
- use LogicException;
-
- abstract class ContractManager
- {
-
- // ------------MEMBER----
- protected Contract $contract;
- protected bool $initialized = false;
-
-
- // -------------PUBLIC--------
- public function initById(string $id): static
- {
- $contract = Contract::findOrFail($id);
- $this->contract = $contract;
- $this->initialized = true;
- return $this;
- }
-
- public function initForCreate(): static
- {
- $contract = new Contract();
- $contract->setId();
-
- $this->contract = $contract;
- $this->initialized = true;
- return $this;
- }
-
- public function fill(array $attr): static
- {
- if (!$this->initialized) {
- throw new LogicException("初期化ミス");
- }
-
- $this->contract->fill($attr);
- return $this;
- }
-
- public function id(): string
- {
- if (!$this->initialized) {
- throw new LogicException("初期化ミス");
- }
- return $this->contract->id;
- }
-
-
- // ----------------PROTECTED----------
- protected function save(): static
- {
- $this->contract->save();
- return $this;
- }
- }
|