dercoder/cloudflare

CloudFlare API - PHP

1.12.0 2018-11-06 17:54 UTC

README

API 文档可以在 https://api.cloudflare.com 找到,当 API 添加新功能时,我会尽快更新。如果遗漏了,请提交一个 pull request。

如果您发现包中存在问题,请通过 issues 告诉我,但请尽可能详细,最好包括代码示例、环境信息等。

安装

应通过 composer 进行安装,有关如何安装 composer 的详细信息,请参阅 https://getcomposer.org.cn/

$ composer require dercoder/cloudflare

功能

当前功能列表包括

用法

在您需要在不同的服务之间对 API 进行多次调用的情况下,首先创建一个 API 连接,然后将该连接传递给其他服务会更简单,例如。

    use Cloudflare\Zone\Dns;

    // Create a connection to the Cloudflare API which you can
    // then pass into other services, e.g. DNS, later on
    $client = new Cloudflare\Api('email@example.com', 'API_KEY');

    // Create a new DNS record
    $dns = new Cloudflare\Zone\Dns($client);
    $dns->create('12345678901234567890', 'A', 'name.com', '127.0.0.1', 120);

如果您只是执行单个操作,则可以在实例化类时直接连接到 API,例如。

    use Cloudflare\Zone\Dns;

    // Create a connection to the Cloudflare API which you can
    // then pass into other services, e.g. DNS, later on
    $dns = new Cloudflare\Zone\Dns('email@example.com', 'API_KEY');
    $dns->create('12345678901234567890', 'TXT', 'name.com', '127.0.0.1', 120);

页面规则

    use Cloudflare\Zone\Pagerules;

    // Define your targets
    // Currently you can only specify one URL per page rule but this implementation matches the API
    // so I am leaving it for now in the assumption they are planning to add multiple targets.
    $targets = [
        [
            'target' => 'url',
            'constraint' =>
            [
                'operator' => 'matches',
                'value' => 'http://example.co.uk/*'
            ]
        ]
    ];

    // Define your actions
    // Each action is held within it's own array.
    $actions = [
        [
            'id' => 'always_online',
            'value' => 'on'
        ]
    ];

    $pagerules = new Cloudflare\Zone\Pagerules('email@example.com', 'API_KEY');
    $pagerules->create($zoneId, $targets, $actions);

许可协议

MIT