-
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.
Add PassesClaimCondition rule and update ClaimBeam mutation.
- Loading branch information
1 parent
3ea13df
commit 5c57bdc
Showing
5 changed files
with
67 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,37 @@ | ||
<?php | ||
|
||
namespace Enjin\Platform\Beam\Rules; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\Validation\DataAwareRule; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
|
||
class PassesClaimCondition implements DataAwareRule, ValidationRule | ||
{ | ||
protected array $data = []; | ||
|
||
/** | ||
* Create new rule instance. | ||
*/ | ||
public function __construct( | ||
protected Closure $function, | ||
protected bool $singleUse | ||
) { | ||
} | ||
|
||
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')); | ||
} | ||
} | ||
|
||
public function setData(array $data) | ||
{ | ||
$this->data = $data; | ||
|
||
return $this; | ||
} | ||
} |
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