Skip to content

Commit

Permalink
Update HasRequestCriteriaTrait.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Dec 28, 2024
1 parent f51eeb2 commit 7049873
Showing 1 changed file with 1 addition and 43 deletions.
44 changes: 1 addition & 43 deletions src/Traits/HasRequestCriteriaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@

namespace Apiato\Core\Traits;

use Apiato\Core\Exceptions\CoreInternalErrorException;
use JetBrains\PhpStorm\Deprecated;
use Prettus\Repository\Criteria\RequestCriteria;
use Prettus\Repository\Exceptions\RepositoryException;
use Vinkla\Hashids\Facades\Hashids;

trait HasRequestCriteriaTrait
{
/**
* @return HasRequestCriteriaTrait
*
* @throws RepositoryException
*/
#[Deprecated(
reason: 'since Apiato 12.2.0, Use addRequestCriteria() on the Repository instead.
Will be removed from Tasks and Actions.',
replacement: '%class%->repository->addRequestCriteria();',
)]
public function addRequestCriteria($repository = null, array $fieldsToDecode = ['id']): static
public function addRequestCriteria(array $fieldsToDecode = ['id']): static
{
$this->pushCriteria(app(RequestCriteria::class));
if ($this->shouldDecodeSearch()) {
Expand All @@ -30,36 +21,6 @@ public function addRequestCriteria($repository = null, array $fieldsToDecode = [
return $this;
}

/**
* Validates, if the given Repository exists or uses $this->repository on the Task/Action to apply functions.
*
* @throws CoreInternalErrorException
*/
private function validateRepository($repository): Repository
{
$validatedRepository = $repository;

// check if we have a "custom" repository
if (is_null($repository)) {
if (!isset($this->repository)) {
throw new CoreInternalErrorException('No protected or public accessible repository available');
}
$validatedRepository = $this->repository;
}

// check, if the validated repository is null
if (is_null($validatedRepository)) {
throw new CoreInternalErrorException();
}

// check if it is a Repository class
if (!($validatedRepository instanceof Repository)) {
throw new CoreInternalErrorException();
}

return $validatedRepository;
}

private function shouldDecodeSearch(): bool
{
return $this->hashIdEnabled() && $this->isSearching(request()->query());
Expand Down Expand Up @@ -182,9 +143,6 @@ private function arrayToSearchQuery(array $decodedSearchArray): string
return $decodedSearchQuery;
}

/**
* @throws CoreInternalErrorException
*/
public function removeRequestCriteria(): static
{
$this->popCriteria(RequestCriteria::class);
Expand Down

0 comments on commit 7049873

Please sign in to comment.