This topic describes how to use SDK for PHP to delete one or more event targets of an event rule.

Sample code:

<? php

namespace Alibabacloud\Sample;

use AlibabaCloud\SDK\EventBridge\Eventbridge;
use AlibabaCloud\SDK\EventBridge\Models\Config;
use AlibabaCloud\SDK\EventBridge\Models\DeleteTargetsRequest;
use AlibabaCloud\Tea\Console\Console;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Exception;

class Client
{
    /**
     * Uses the createClient() function to initialize common request parameters.
     *
     * @return Eventbridge
     */
    public static function createClient()
    {
        $config = new Config([]);
        $config->accessKeyId = ('accessKeyId');
        $config->accessKeySecret = ('ACCESS_KEY_SECRET');
        $config->endpoint = ('EVENT_BRIDGE_ENDPOINT');

        return new Eventbridge($config);
    }


    /**
     * @param Eventbridge $client
     *
     * @return void
     */
    public static function deleteTargetsSample($client)
    {
        try {
            $removeTargetsResponse               = new DeleteTargetsRequest([]);
            $removeTargetsResponse->eventBusName = 'demo-bus';
            $removeTargetsResponse->ruleName     = 'myRule';
            $list                                = [
                '1234',
            ];
            $removeTargetsResponse->targetIds = $list;
            $response                         = $client->deleteTargets($removeTargetsResponse);
            Console::log('--------------------delete targets success--------------------');
            Console::log(Utils::toJSONString($response->toMap()));
        } catch (Exception $error) {
            if (!( $error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            Console::log($error->message);
        }
    }

    /**
     * @param string[] $args
     *
     * @return void
     */
    public static function main($args)
    {
        $client = self::createClient();
        self::deleteTargetsSample($client);
    }
}
require '../vendor/autoload.php';
Client::main([]);