JamesRyanBell/cloudflare

此包已被废弃且不再维护。没有建议的替代包。

CloudFlare API - PHP

1.11.1 2017-08-04 19:01 UTC

README

https://github.com/cloudflare/cloudflare-php

由于Cloudflare已发布官方包,我将继续修复bug,但不会在此库上进行进一步的开发。

您可以在此处了解更多关于官方包的信息

Build Status Coverage Status Dependency Status Latest Stable Version Total Downloads StyleCI License Scrutinizer Code Quality

CloudFlare API - PHP

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

如果您发现包中存在问题,请通过问题通知我,但请尽量提供尽可能多的详细信息,最好是带有代码示例、环境信息等。

此包的文档可以在此处查看:https://jamesryanbell.github.io/cloudflare/

安装

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

$ composer require jamesryanbell/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