Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Oct 16, 2023
1 parent 4b72c7a commit 624e300
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/Concerns/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@
*/
trait Attributes
{
private const MINIMAL_ATTRIBUTES_KEY = self::class.':$minimalAttributes';

/**
* @return void
*/
public static function useMinimalAttributes()
{
App::instance(self::MINIMAL_ATTRIBUTES_KEY, true);
App::instance(self::class.':$minimalAttributes', true);
}

/**
* @return bool
*/
private static function minimalAttributes()
{
return App::bound(self::MINIMAL_ATTRIBUTES_KEY)
? App::make(self::MINIMAL_ATTRIBUTES_KEY)
return App::bound(self::class.':$minimalAttributes')
? App::make(self::class.':$minimalAttributes')
: false;
}

Expand Down
20 changes: 8 additions & 12 deletions src/Concerns/Identification.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
*/
trait Identification
{
private const ID_RESOLVER_KEY = self::class.':$idResolver';

private const TYPE_RESOLVER_KEY = self::class.':$typeResolver';

private string|null $idCache = null;

private string|null $typeCache = null;
Expand All @@ -35,7 +31,7 @@ trait Identification
*/
public static function resolveIdUsing(callable $callback)
{
App::instance(self::ID_RESOLVER_KEY, $callback);
App::instance(self::class.':$idResolver', $callback);
}

/**
Expand All @@ -44,16 +40,16 @@ public static function resolveIdUsing(callable $callback)
*/
public static function resolveTypeUsing(callable $callback)
{
App::instance(self::TYPE_RESOLVER_KEY, $callback);
App::instance(self::class.':$typeResolver', $callback);
}

/**
* @return (callable(mixed, Request): string)
*/
private static function idResolver()
{
if (! App::bound(self::ID_RESOLVER_KEY)) {
return App::instance(self::ID_RESOLVER_KEY, function (mixed $resource, Request $request): string {
if (! App::bound(self::class.':$idResolver')) {
return App::instance(self::class.':$idResolver', function (mixed $resource, Request $request): string {
if (! $resource instanceof Model) {
throw ResourceIdentificationException::attemptingToDetermineIdFor($resource);
}
Expand All @@ -65,16 +61,16 @@ private static function idResolver()
});
}

return App::make(self::ID_RESOLVER_KEY);
return App::make(self::class.':$idResolver');
}

/**
* @return (callable(mixed, Request): string)
*/
private static function typeResolver()
{
if (! App::bound(self::TYPE_RESOLVER_KEY)) {
return App::instance(self::TYPE_RESOLVER_KEY, function (mixed $resource, Request $request): string {
if (! App::bound(self::class.':$typeResolver')) {
return App::instance(self::class.':$typeResolver', function (mixed $resource, Request $request): string {
if (! $resource instanceof Model) {
throw ResourceIdentificationException::attemptingToDetermineTypeFor($resource);
}
Expand All @@ -83,7 +79,7 @@ private static function typeResolver()
});
}

return App::make(self::TYPE_RESOLVER_KEY);
return App::make(self::class.':$typeResolver');
}

/**
Expand Down

0 comments on commit 624e300

Please sign in to comment.