-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLA-1302] Add PassesClaimCondition rule and update ClaimBeam mutatio…
…n. (#40)
- Loading branch information
1 parent
3ea13df
commit e658b19
Showing
5 changed files
with
70 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Enjin\Platform\Beam\GraphQL\Traits; | ||
|
||
use Enjin\Platform\Beam\Rules\PassesClaimCondition; | ||
use Enjin\Platform\Beam\Rules\PassesClaimConditions; | ||
|
||
trait HasBeamClaimConditions | ||
{ | ||
public function getClaimConditionRules(bool $singleUse): array | ||
{ | ||
$conditions = collect(PassesClaimConditions::getConditionalFunctions()); | ||
|
||
return $conditions | ||
->map(fn ($condition) => new PassesClaimCondition($condition, $singleUse)) | ||
->toArray(); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Enjin\Platform\Beam\Rules; | ||
|
||
use Closure; | ||
use Enjin\Platform\Rules\Traits\HasDataAwareRule; | ||
use Illuminate\Contracts\Validation\DataAwareRule; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
|
||
class PassesClaimCondition implements DataAwareRule, ValidationRule | ||
{ | ||
use HasDataAwareRule; | ||
|
||
/** | ||
* Create new rule instance. | ||
*/ | ||
public function __construct( | ||
protected Closure $function, | ||
protected bool $singleUse | ||
) { | ||
} | ||
|
||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* @param Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail | ||
* | ||
* @return void | ||
*/ | ||
public function validate(string $attribute, mixed $value, Closure $fail): void | ||
{ | ||
$result = ($this->function)($attribute, $value, $this->singleUse, $this->data); | ||
|
||
if (true !== $result) { | ||
$fail(is_string($result) ? $result : __('enjin-platform-beam::validation.passes_condition')); | ||
} | ||
} | ||
} |
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