dercoder / cloudflare
CloudFlare API - PHP
1.12.0
2018-11-06 17:54 UTC
Requires (Dev)
- phpunit/phpunit: < 6
- satooshi/php-coveralls: dev-master
README
API 文档可以在 https://api.cloudflare.com 找到,当 API 添加新功能时,我会尽快更新。如果遗漏了,请提交一个 pull request。
如果您发现包中存在问题,请通过 issues 告诉我,但请尽可能详细,最好包括代码示例、环境信息等。
安装
应通过 composer 进行安装,有关如何安装 composer 的详细信息,请参阅 https://getcomposer.org.cn/
$ composer require dercoder/cloudflare
功能
当前功能列表包括
- DNS 记录
- 区域
- Web 应用防火墙 (WAF)
- CloudFlare IP
- 用户管理
- 虚拟 DNS 管理
- 组织管理
- Railgun 管理
- 无密 SSL
- 原始 CA
- 流量管理器 [BETA]
- 流量控制
用法
在您需要在不同的服务之间对 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