Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennjacobs committed Dec 21, 2023
1 parent 6651c2c commit dc462ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/Base/ModelManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function replace(string $interfaceClass, string $modelClass): void
/**
* Gets the registered class for the interface.
*/
public function get(string $interfaceClass)
public function get(string $interfaceClass): ?string
{
return $this->models[$interfaceClass];
return $this->models[$interfaceClass] ?? null;
}

/**
Expand All @@ -67,7 +67,7 @@ private function validateClassIsEloquentModel(string $class): void
}
}

protected function bindModel(string $interfaceClass, string $modelClass)
protected function bindModel(string $interfaceClass, string $modelClass): void
{
// Bind in container
app()->bind($interfaceClass, $modelClass);
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/Base/Traits/HasModelExtending.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

namespace Lunar\Base\Traits;

use Lunar\Facades\ModelManifest;

trait HasModelExtending
{
//
/**
* Returns the model class registered in the model manifest.
*/
public static function modelClass(): string
{
$shortName = (new \ReflectionClass(static::class))->getShortName();

$contractClass = 'Lunar\\Models\\Contracts\\' . $shortName;

return ModelManifest::get($contractClass) ?? static::class;
}
}

0 comments on commit dc462ce

Please sign in to comment.