myena / phpipam-api
PHPIPAM SDK
dev-master
2018-03-23 21:56 UTC
Requires
- php: >=7.1
- dcarbone/gotime: @stable
- dcarbone/php-consul-api: @stable
- guzzlehttp/guzzle: ^6.3
- psr/log: @stable
Requires (Dev)
- myena/default-logger: @stable
This package is auto-updated.
Last update: 2024-08-26 06:32:50 UTC
README
用于从PHP-IPAM API消费的SDK
配置
要创建一个客户端,您必须首先构建一个实现了ConfigProvider的类。包含两种实现
标准配置
如果您将所有PHP IPAM配置细节都保存在您的应用程序本地,您可以使用Config类,传入配置细节的数组
$conf = [ // Required Parameters 'host' => 'service host', 'username' => 'bilbo-swaggins', 'password' => 'swaggerific', 'appid' => 'whatever', 'appcode' => 'crypticwhatever', // Optional Parameters 'https' => true, // defaults to true 'port' => 0, // recommended to set only if you don't use standard 80 / 443, 'silent' => false, // defaults to false, set to silence all logging output ]; $config = new \ENA\PHPIPAM\Config\Config($conf);
Consul派生配置
如果您有一个Consul设置并且您的PHPIPAM服务已注册,或者使用其KV存储其他配置项,您可以使用ConsulConfig类。此配置使用PHPConsulAPI与Consul交互。它接受与标准LocalConfig类相同的所有参数,以及以下额外的Consul特定参数
参数
$consulConf = $conf + [ 'servicename' => 'phpipam', // mutually exclusive to "host" and "port", and is required if those are not set 'servicetag' => '', // defaults to nothing 'healthyonly' => true, // defaults to true 'queryoptions' => null, // optionally allows setting of a [QueryOptions](https://github.com/dcarbone/php-consul-api/blob/master/src/QueryOptions.php) object to use in requests 'usernamekey' => '', // full path to KV store key containing username, mutually exclusive with "username" 'passwordkey' => '', // full path to KV store key containing password, mutually exclusive with "password" 'appidkey' => '', // full path to KV store key containing appid, mutually exclusive with "appid" 'appcodekey' => '', // full path to KV store key containing appcode, mutually exclusive with "appcode" ];
此类接受一个可选的第三个参数,即Consul的实例。如果没有定义,将使用默认配置值创建一个新实例。
HTTP客户端
两个配置类都接受一个可选的第二个参数,即实现了GuzzleHttp ClientInterface的任何类的实例。如果没有定义,将使用GuzzleHttp Client的新实例。
开发中
这个库仍在积极开发中。以下是各种控制器及其开发状态的表格
通用用法
所有操作遵循相同的基本流程
$client->Controller()->METHOD()->Action()->execute();
有些控制器的METHOD
也是可以直接执行的(例如 $client->User()->GET()->execute()
)
链中的每个步骤都是一个Part
,只有实现了ExecutablePart接口的部分才会携带execute
方法。