PluginProbe
WooCommerce / 11.1.0-beta.2
WooCommerce v11.1.0-beta.2
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Internal / Api / Autogenerated / GraphQLMutations / DeleteCoupon.php
DeleteCoupon.php
86 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 // THIS FILE IS AUTO-GENERATED. DO NOT EDIT MANUALLY.
5
6 namespace Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLMutations;
7
8 use Automattic\WooCommerce\Api\Mutations\Coupons\DeleteCoupon as DeleteCouponCommand;
9 use Automattic\WooCommerce\Api\Infrastructure\QueryInfoExtractor;
10 use Automattic\WooCommerce\Api\Infrastructure\ResolverHelpers;
11 use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Output\DeleteCouponResult as DeleteCouponResultType;
12 use Automattic\WooCommerce\Api\Infrastructure\Schema\ResolveInfo;
13 use Automattic\WooCommerce\Api\Infrastructure\Schema\Type;
14
15 class DeleteCoupon {
16 public static function get_field_definition(): array {
17 return array(
18 'type' => Type::nonNull( DeleteCouponResultType::get() ),
19 'description' => __( 'Delete a coupon.', 'woocommerce' ),
20 'authorization' => array(
21 array(
22 'attribute' => 'RequiredCapability',
23 'args' => array(
24 0 => 'manage_woocommerce',
25 ),
26 ),
27 ),
28 'args' => array(
29 'id' => array(
30 'type' => Type::nonNull( Type::int() ),
31 'description' => __( 'The ID of the coupon to delete.', 'woocommerce' ),
32 ),
33 'force' => array(
34 'type' => Type::nonNull( Type::boolean() ),
35 'description' => __( 'Whether to permanently delete the coupon (bypass trash).', 'woocommerce' ),
36 'defaultValue' => false,
37 ),
38 ),
39 'resolve' => array( self::class, 'resolve' ),
40 );
41 }
42
43 public static function resolve( mixed $root, array $args, mixed $context, ResolveInfo $info ): mixed {
44 // Standalone authorization gate: no authorize() method on the command,
45 // so the autodiscovered authorization attributes are the sole guard.
46 if ( ! self::compute_preauthorized( $context['principal'] ) ) {
47 throw ResolverHelpers::build_authorization_error( $context['principal'] );
48 }
49
50 // Publish the root query's metadata so downstream field-level
51 // authorization gates can read it via `$_metadata['query']`.
52 // $context is an ArrayObject (see GraphQLController::process_request())
53 // so the mutation propagates to nested resolvers.
54 $context['_query_metadata'] = array();
55
56 $command = \Automattic\WooCommerce\Api\Infrastructure\ClassResolver::resolve_class( DeleteCouponCommand::class );
57
58 $execute_args = array();
59 if ( array_key_exists( 'id', $args ) ) {
60 $execute_args['id'] = $args['id'];
61 }
62 if ( array_key_exists( 'force', $args ) ) {
63 $execute_args['force'] = $args['force'];
64 }
65
66 $result = ResolverHelpers::execute_command( $command, $execute_args );
67
68 return $result;
69 }
70
71 /**
72 * Compute the value `_preauthorized` would carry for a given principal —
73 * the AND of the autodiscovered authorization attributes' authorize()
74 * outcomes on this command. Single source of truth for both the resolver's
75 * own gates and external (code-API) callers asking about authorization
76 * without going through GraphQL execution.
77 *
78 * Returns true vacuously when the command has no authorization attributes
79 * (in that case authorize() on the command is the sole guard, and that
80 * method should be consulted instead).
81 */
82 public static function compute_preauthorized( \Automattic\WooCommerce\Api\Infrastructure\Principal $principal ): bool {
83 return ( new \Automattic\WooCommerce\Api\Attributes\RequiredCapability( 'manage_woocommerce' ) )->authorize( $principal );
84 }
85 }
86