|
|
|
@@ -0,0 +1,60 @@ |
|
|
|
<?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; |
|
|
|
} |
|
|
|
} |