ArrayOf.php
2 months ago
ConnectionOf.php
2 months ago
Deprecated.php
2 months ago
Description.php
2 months ago
Experimental.php
4 weeks ago
HiddenFromMetadataQuery.php
4 weeks ago
Ignore.php
2 months ago
Internal.php
4 weeks ago
Metadata.php
4 weeks ago
Name.php
2 months ago
Parameter.php
2 months ago
ParameterDescription.php
2 months ago
PublicAccess.php
4 weeks ago
RequiredCapability.php
4 weeks ago
ReturnType.php
2 months ago
ScalarType.php
2 months ago
Unroll.php
2 months ago
Parameter.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Api\Attributes; |
| 6 | |
| 7 | use Attribute; |
| 8 | |
| 9 | /** |
| 10 | * Declares an explicit GraphQL argument for a query or mutation. |
| 11 | * |
| 12 | * Use this when the argument cannot be inferred from the `execute()` method |
| 13 | * signature — for example, when a parameter needs a specific GraphQL type, |
| 14 | * nullability, or default that differs from what reflection would produce. |
| 15 | * This attribute is repeatable: apply it once per argument. |
| 16 | */ |
| 17 | #[Attribute( Attribute::TARGET_ALL | Attribute::IS_REPEATABLE )] |
| 18 | final class Parameter { |
| 19 | /** |
| 20 | * Whether a default value was provided. |
| 21 | * |
| 22 | * @var bool |
| 23 | */ |
| 24 | public readonly bool $has_default; |
| 25 | |
| 26 | /** |
| 27 | * Constructor. |
| 28 | * |
| 29 | * @param string $name The GraphQL argument name (not needed when unrolling). |
| 30 | * @param string $type The PHP type name ('int', 'string', 'float', 'bool') |
| 31 | * or a fully-qualified class name for complex types. |
| 32 | * @param bool $nullable Whether the argument accepts null. |
| 33 | * @param bool $array Whether the argument is a list (e.g. `[Int!]`). |
| 34 | * @param mixed $default The default value if the argument is omitted. |
| 35 | * @param string $description Human-readable description for the schema. |
| 36 | * @param bool $has_default Set to true to explicitly indicate a default is |
| 37 | * provided (needed when the default value is null). |
| 38 | * @param bool $unroll When true, the class given in $type is expanded into |
| 39 | * individual GraphQL arguments (one per public property). |
| 40 | */ |
| 41 | public function __construct( |
| 42 | public readonly string $name = '', |
| 43 | public readonly string $type = '', |
| 44 | public readonly bool $nullable = false, |
| 45 | public readonly bool $array = false, |
| 46 | public readonly mixed $default = null, |
| 47 | public readonly string $description = '', |
| 48 | bool $has_default = false, |
| 49 | public readonly bool $unroll = false, |
| 50 | ) { |
| 51 | // We need a separate flag because null could be a valid default value. |
| 52 | // Callers pass has_default: true when they supply a default, or we infer |
| 53 | // it from the default value being non-null. |
| 54 | $this->has_default = $has_default || null !== $default; |
| 55 | } |
| 56 | } |
| 57 |