Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
milewski committed May 30, 2021
1 parent 0b2a595 commit 4e53759
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace DigitalCreative\Jaqen\Services\ResourceManager\Http\Controllers;

use DigitalCreative\Jaqen\Http\Requests\BaseRequest;
use DigitalCreative\Jaqen\Services\ResourceManager\AbstractResource;
use Illuminate\Support\Collection;

Expand All @@ -14,10 +13,10 @@ class ResourceController extends Controller
/**
* Return a list of all registered resources
*/
public function resources(BaseRequest $request): Collection
public function resources(): Collection
{
return $this->resourceManager
->allAuthorizedResources($request)
->allAuthorizedResources()
->map(fn(AbstractResource $resource) => $resource->getDescriptor());
}

Expand Down
14 changes: 6 additions & 8 deletions src/Services/ResourceManager/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ public function setResources(array $resources): self
{
$this->resources = $this->resources
->merge($resources)
->mapWithKeys(fn($resource) => [ $resource::uriKey() => $resource ]);
->mapWithKeys(fn(AbstractResource|string $resource) => [ $resource::uriKey() => $resource ]);

return $this;
}

public function allAuthorizedResources(BaseRequest $request): Collection
public function allAuthorizedResources(): Collection
{
/**
* @todo implement authorized to see
*/
return $this->resources->map(fn($class, $key) => new $class($request))
->filter(fn(AbstractResource $resource) => $resource->authorizeToView())
->values();
return $this->resources
->map(fn(AbstractResource|string $resource) => $resource instanceof AbstractResource ? $resource : resolve($resource))
->filter(fn(AbstractResource $resource) => $resource->authorizeToView())
->values();
}

public function resourceForRequest(BaseRequest $request): AbstractResource
Expand Down

0 comments on commit 4e53759

Please sign in to comment.