-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44af4a7
commit e00bb44
Showing
26 changed files
with
142 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,15 @@ | |
|
||
namespace Apiato\Core\Abstracts\Tasks; | ||
|
||
use Apiato\Core\Traits\HasRequestCriteriaTrait; | ||
|
||
/** | ||
* Class Task. | ||
* | ||
* @author Mahmoud Zalt <[email protected]> | ||
*/ | ||
abstract class Task | ||
{ | ||
use HasRequestCriteriaTrait; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Apiato\Core\Traits; | ||
|
||
use Apiato\Core\Abstracts\Repositories\Repository; | ||
use Apiato\Core\Exceptions\CoreInternalErrorException; | ||
use Prettus\Repository\Criteria\RequestCriteria; | ||
|
||
/** | ||
* Trait HasRequestCriteriaTrait | ||
* | ||
* @author Johannes Schobel <[email protected]> | ||
*/ | ||
trait HasRequestCriteriaTrait | ||
{ | ||
|
||
/** | ||
* Adds the RequestCriteria to a Repository | ||
* | ||
* @param null $repository | ||
*/ | ||
public function addRequestCriteria($repository = null) | ||
{ | ||
$validatedRepository = $this->validateRepository($repository); | ||
|
||
$validatedRepository->pushCriteria(app(RequestCriteria::class)); | ||
} | ||
|
||
/** | ||
* Removes the RequestCriteria from a Repository | ||
* | ||
* @param null $repository | ||
*/ | ||
public function removeRequestCriteria($repository = null) | ||
{ | ||
$validatedRepository = $this->validateRepository($repository); | ||
|
||
$validatedRepository->popCriteria(RequestCriteria::class); | ||
} | ||
|
||
/** | ||
* Validates, if the given Repository exists or uses $this->repository on the Task/Action to apply functions | ||
* | ||
* @param $repository | ||
* | ||
* @return mixed | ||
* @throws CoreInternalErrorException | ||
*/ | ||
private function validateRepository($repository) | ||
{ | ||
$validatedRepository = $repository; | ||
|
||
// check if we have a "custom" repository | ||
if (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 (null === $validatedRepository) { | ||
throw new CoreInternalErrorException(); | ||
} | ||
|
||
// check if it is a Repository class | ||
if (! ($validatedRepository instanceof Repository)) { | ||
throw new CoreInternalErrorException(); | ||
} | ||
|
||
return $validatedRepository; | ||
} | ||
|
||
} |
Oops, something went wrong.