fortytwo-studio/webfaction-php

Webfaction XML-RPC API的PHP包装器

1.1.4 2018-04-03 13:39 UTC

This package is not auto-updated.

Last update: 2024-09-15 22:29:15 UTC


README

Build Status

webfaction-php

简单的PHP包装器,用于与WebFaction XMLRPC API交互

安装

使用composer安装

composer require fortytwo-studio/webfaction-php

或者将以下内容添加到您的composer.json文件的"require"部分

"require": {
  "fortytwo-studio/webfaction-php": "^1.0",
}

(别忘了运行composer installcomposer update)

概述

这是一个用于与WebFaction XMLRPC API交互的PHP包装器。它非常轻量,方法遵循命名约定(使用camelCase而不是snake_case)和参数顺序(忽略session_id),与XMLRPC API保持一致

用法

在您的项目类中包含客户端。

<?php
    use FortyTwoStudio\WebFactionPHP\WebFactionClient;
    use FortyTwoStudio\WebFactionPHP\WebFactionException;
    
    class MyAwesomeClass {
        ...
    }

要连接到API,请使用您的API凭据创建一个WebFactionClient实例

    $wf = new WebFactionClient('USERNAME', 'PASSWORD', 'MACHINE', 'VERSION');

然后您可以使用方法与API进行交互。

示例 - 配置新的mysql数据库和用户

<?php

// include composer's autoloader (this'll vary depending on your application)
// presuming this file is in a "webroot" type folder...
include(__DIR__ . '/../vendor/autoload.php');

use FortyTwoStudio\WebFactionPHP\WebFactionClient;
use FortyTwoStudio\WebFactionPHP\WebFactionException;

class MyAwesomeClass
{

    public function createDatabase($username = "new_db_user", $dbname = "my_new_db")
    {
        try
        {
            // create a connection to the API, use your own credentials here, obvs
            $wf = new WebFactionClient('USERNAME', 'PASSWORD', 'MACHINE', 'VERSION');

            // static method to generate random strings of given length
            $db_pass = WebFactionClient::generatePassword(21);

            // https://docs.webfaction.com/xmlrpc-api/apiref.html#method-create_db
            $database = $wf->createDb($dbname, 'mysql', $db_pass, $username);

            // https://docs.webfaction.com/xmlrpc-api/apiref.html#method-change_db_user_password
            //otherwise it doesn't seem to use it. Possibly because we're creating the user at the same time as the DB above
            $wf->changeDbUserPassword($username, $db_pass, 'mysql');

        } catch (WebFactionException $e)
        {
            // Something went wrong, find out what with $e->getMessage() but be warned, WebFaction exception messages are often
            // vague and unhelpful!
            return "rut roh, this went wrong: " . $e->getMessage();
        }

        // database created, keep a record of $db_pass if you want to use it somewhere!
        return "$db_pass";
    }

}

echo (new MyAwesomeClass())->createDatabase(); // if you didn't change the credentials in this example => rut roh, this went wrong: LoginError

变更日志

03/Apr/2018 - 1.1.4

  • 修复了在replaceInFile方法中多个替换导致错误的问题

06/Mar/2018 - 1.1.3

  • 修改composer.json以要求phpxmlrpc的4.*版本
  • 更新ReadMe

19/Dec/2017 - 1.1.2

  • 修复了在API v1和v2的createWebsite中出现的"未知错误"异常
  • 更新ReadMe

29/Nov/2017 - 1.1.1

  • 当使用当前版本不可用的端点时,对异常消息进行了微小修改
  • 更新ReadMe

29/Nov/2017 - 1.1.0

  • 更新以支持Webfaction API的版本2。这支持SSL证书管理。
  • 修复了某些邮件方法未返回响应的bug
  • 更新ReadMe

01/Aug/2017 - 1.0.0

  • 更新phpunit
  • travis CI构建集成
  • 更新ReadMe

23/Aug/2016 - 首次发布。