Skip to content

Commit

Permalink
bind to the container instead of using a static
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Oct 16, 2023
1 parent 93dfac0 commit f112ff6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/Concerns/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
use Illuminate\Http\Request;
use Illuminate\Http\Resources\PotentiallyMissing;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use TiMacDonald\JsonApi\Support\Fields;

/**
* @internal
*/
trait Attributes
{
private static bool $minimalAttributes = false;
private const MINIMAL_ATTRIBUTES_KEY = self::class.':$minimalAttributes';

/**
* @return void
*/
public static function minimalAttributes($value = true)
{
self::$minimalAttributes = $value;
App::instance(self::MINIMAL_ATTRIBUTES_KEY, $value);
}

/**
Expand Down Expand Up @@ -52,6 +53,13 @@ private function resolveAttributes(Request $request)
*/
private function requestedFields(Request $request)
{
return Fields::getInstance()->parse($request, $this->toType($request), self::$minimalAttributes);
return Fields::getInstance()->parse($request, $this->toType($request), self::resolveMinimalAttributes());
}

private static function resolveMinimalAttributes(): bool
{
return App::bound(self::MINIMAL_ATTRIBUTES_KEY)
? (bool) App::make(self::MINIMAL_ATTRIBUTES_KEY)
: false;
}
}
1 change: 0 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ protected function tearDown(): void
parent::tearDown();

JsonApiResource::resolveServerImplementationNormally();
JsonApiResource::minimalAttributes(false);
}

protected function assertValidJsonApi(TestResponse|string|array $data): void
Expand Down

0 comments on commit f112ff6

Please sign in to comment.