mirror of
https://github.com/itflow-org/itflow
synced 2026-06-16 23:01:04 +00:00
Allow PHP-8.2 and up Compatibility instead of just PHP-8.4
This commit is contained in:
@@ -2,12 +2,19 @@
|
||||
|
||||
namespace Illuminate\Contracts\Database;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class ModelIdentifier
|
||||
{
|
||||
/**
|
||||
* Use the Relation morphMap for a Model's name when serializing.
|
||||
*/
|
||||
protected static bool $useMorphMap = false;
|
||||
|
||||
/**
|
||||
* The class name of the model.
|
||||
*
|
||||
* @var class-string<\Illuminate\Database\Eloquent\Model>
|
||||
* @var class-string<\Illuminate\Database\Eloquent\Model>|string|null
|
||||
*/
|
||||
public $class;
|
||||
|
||||
@@ -44,15 +51,19 @@ class ModelIdentifier
|
||||
/**
|
||||
* Create a new model identifier.
|
||||
*
|
||||
* @param class-string<\Illuminate\Database\Eloquent\Model> $class
|
||||
* @param class-string<\Illuminate\Database\Eloquent\Model>|null $class
|
||||
* @param mixed $id
|
||||
* @param array $relations
|
||||
* @param mixed $connection
|
||||
*/
|
||||
public function __construct($class, $id, array $relations, $connection)
|
||||
{
|
||||
$this->id = $id;
|
||||
if ($class !== null && self::$useMorphMap) {
|
||||
$class = Relation::getMorphAlias($class);
|
||||
}
|
||||
|
||||
$this->class = $class;
|
||||
$this->id = $id;
|
||||
$this->relations = $relations;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
@@ -69,4 +80,26 @@ class ModelIdentifier
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully-qualified class name of the Model.
|
||||
*
|
||||
* @return class-string<\Illuminate\Database\Eloquent\Model>|null
|
||||
*/
|
||||
public function getClass(): ?string
|
||||
{
|
||||
if (self::$useMorphMap && $this->class !== null) {
|
||||
return Relation::getMorphedModel($this->class) ?? $this->class;
|
||||
}
|
||||
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether to use the relational morph-map when serializing Models.
|
||||
*/
|
||||
public static function useMorphMap(bool $useMorphMap = true): void
|
||||
{
|
||||
static::$useMorphMap = $useMorphMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user