CustomValidationRule.php
2 months ago
DisableIntrospection.php
2 months ago
ExecutableDefinitions.php
2 months ago
FieldsOnCorrectType.php
2 months ago
FragmentsOnCompositeTypes.php
2 months ago
KnownArgumentNames.php
2 months ago
KnownArgumentNamesOnDirectives.php
2 months ago
KnownDirectives.php
2 months ago
KnownFragmentNames.php
2 months ago
KnownTypeNames.php
2 months ago
LoneAnonymousOperation.php
2 months ago
LoneSchemaDefinition.php
2 months ago
NoFragmentCycles.php
2 months ago
NoUndefinedVariables.php
2 months ago
NoUnusedFragments.php
2 months ago
NoUnusedVariables.php
2 months ago
OneOfInputObjectsRule.php
2 months ago
OverlappingFieldsCanBeMerged.php
2 months ago
PossibleFragmentSpreads.php
2 months ago
PossibleTypeExtensions.php
2 months ago
ProvidedRequiredArguments.php
2 months ago
ProvidedRequiredArgumentsOnDirectives.php
2 months ago
QueryComplexity.php
2 months ago
QueryDepth.php
2 months ago
QuerySecurityRule.php
2 months ago
ScalarLeafs.php
2 months ago
SingleFieldSubscription.php
2 months ago
UniqueArgumentDefinitionNames.php
2 months ago
UniqueArgumentNames.php
2 months ago
UniqueDirectiveNames.php
2 months ago
UniqueDirectivesPerLocation.php
2 months ago
UniqueEnumValueNames.php
2 months ago
UniqueFieldDefinitionNames.php
2 months ago
UniqueFragmentNames.php
2 months ago
UniqueInputFieldNames.php
2 months ago
UniqueOperationNames.php
2 months ago
UniqueOperationTypes.php
2 months ago
UniqueTypeNames.php
2 months ago
UniqueVariableNames.php
2 months ago
ValidationRule.php
2 months ago
ValuesOfCorrectType.php
2 months ago
VariablesAreInputTypes.php
2 months ago
VariablesInAllowedPosition.php
2 months ago
CustomValidationRule.php
37 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules; |
| 4 | |
| 5 | use Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node; |
| 6 | use Automattic\WooCommerce\Vendor\GraphQL\Language\VisitorOperation; |
| 7 | use Automattic\WooCommerce\Vendor\GraphQL\Validator\ValidationContext; |
| 8 | |
| 9 | /** |
| 10 | * @see Node, VisitorOperation |
| 11 | * |
| 12 | * @phpstan-type NodeVisitorFnResult VisitorOperation|mixed|null |
| 13 | * @phpstan-type VisitorFnResult array<string, callable(Node): NodeVisitorFnResult>|array<string, array<string, callable(Node): NodeVisitorFnResult>> |
| 14 | * @phpstan-type VisitorFn callable(ValidationContext): VisitorFnResult |
| 15 | */ |
| 16 | class CustomValidationRule extends ValidationRule |
| 17 | { |
| 18 | /** |
| 19 | * @var callable |
| 20 | * |
| 21 | * @phpstan-var VisitorFn |
| 22 | */ |
| 23 | protected $visitorFn; |
| 24 | |
| 25 | /** @phpstan-param VisitorFn $visitorFn */ |
| 26 | public function __construct(string $name, callable $visitorFn) |
| 27 | { |
| 28 | $this->name = $name; |
| 29 | $this->visitorFn = $visitorFn; |
| 30 | } |
| 31 | |
| 32 | public function getVisitor(ValidationContext $context): array |
| 33 | { |
| 34 | return ($this->visitorFn)($context); |
| 35 | } |
| 36 | } |
| 37 |