| 1 |
<?php |
| 2 |
|
| 3 |
namespace Illuminate\Contracts\Database; |
| 4 |
|
| 5 |
use Illuminate\Database\Eloquent\Relations\Relation; |
| 6 |
|
| 7 |
class ModelIdentifier |
| 8 |
{ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
protected static bool $useMorphMap = false; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public $class; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public $id; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public $relations; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public $connection; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public $collectionClass; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public function __construct($class, $id, array $relations, $connection) |
| 60 |
{ |
| 61 |
if ($class !== null && self::$useMorphMap) { |
| 62 |
$class = Relation::getMorphAlias($class); |
| 63 |
} |
| 64 |
|
| 65 |
$this->class = $class; |
| 66 |
$this->id = $id; |
| 67 |
$this->relations = $relations; |
| 68 |
$this->connection = $connection; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public function useCollectionClass(?string $collectionClass) |
| 78 |
{ |
| 79 |
$this->collectionClass = $collectionClass; |
| 80 |
|
| 81 |
return $this; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public function getClass(): ?string |
| 90 |
{ |
| 91 |
if (self::$useMorphMap && $this->class !== null) { |
| 92 |
return Relation::getMorphedModel($this->class) ?? $this->class; |
| 93 |
} |
| 94 |
|
| 95 |
return $this->class; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public static function useMorphMap(bool $useMorphMap = true): void |
| 102 |
{ |
| 103 |
static::$useMorphMap = $useMorphMap; |
| 104 |
} |
| 105 |
} |