2017 © Pedro Peláez
 

library webfaction-php

PHP wrapper for the Webfaction XML-RPC API

image

fortytwo-studio/webfaction-php

PHP wrapper for the Webfaction XML-RPC API

  • Tuesday, April 3, 2018
  • by fortytwo-studio
  • Repository
  • 4 Watchers
  • 6 Stars
  • 357 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 6 % Grown

The README.md

Build Status, (*1)

webfaction-php

Simple PHP wrapper for the WebFaction XMLRPC API, (*2)

Installation

Install using composer, (*3)

composer require fortytwo-studio/webfaction-php, (*4)

or add to your composer.json file's "require" section, (*5)

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

(don't forget to run composer install or composer update), (*6)

Overview

This is a PHP wrapper for interacting with the WebFaction XMLRPC API. It's extremely thin, methods follow the naming conventions(camelCase rather than snake_case) and parameter ordering (ignoring session_id) of the XMLRPC API, (*7)

Usage

include the client in your project class., (*8)

<?php
    use FortyTwoStudio\WebFactionPHP\WebFactionClient;
    use FortyTwoStudio\WebFactionPHP\WebFactionException;

    class MyAwesomeClass {
        ...
    }

To create a connection to the API new up an instance of the WebFactionClient with your API credentials:, (*9)

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

You can then perform interactions with the API using the methods., (*10)

Example - Provision a new mysql database and user

<?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

Changelog

03/Apr/2018 - 1.1.4

  • Fixed bug on replaceInFile method where multiple replacements were erroring

06/Mar/2018 - 1.1.3

  • altered composer.json to require 4.* of phpxmlrpc
  • update ReadMe

19/Dec/2017 - 1.1.2

  • fixed "Unkown Error" exception on createWebsite on v1 and v2 of the API
  • update ReadMe

29/Nov/2017 - 1.1.1

  • small change to exception message when using an endpoint unavailable to the current version
  • update ReadMe

29/Nov/2017 - 1.1.0

  • update to handle Version 2 of the Webfaction API. This has support for SSL certificate management.
  • fixed bug where some email methods weren't returning a response
  • update ReadMe

01/Aug/2017 - 1.0.0

  • update phpunit
  • travis CI build integration
  • update ReadMe

23/Aug/2016 - initial release.

The Versions

03/04 2018

dev-development

dev-development

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires

03/04 2018

dev-master

9999999-dev

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires

03/04 2018

1.1.4

1.1.4.0

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires

06/03 2018

1.1.3

1.1.3.0

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires

19/12 2017

1.1.2

1.1.2.0

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires

29/11 2017

1.1.1

1.1.1.0

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires

29/11 2017

1.1.0

1.1.0.0

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires

01/08 2017

1.0.0

1.0.0.0

PHP wrapper for the Webfaction XML-RPC API

  Sources   Download

MIT

The Requires

 

The Development Requires