Simple PHP wrapper for the WebFaction XMLRPC API
Install using composer
composer require fortytwo-studio/webfaction-php
or add to your composer.json file's "require" section
"require": {
"fortytwo-studio/webfaction-php": "^1.0",
}
(don't forget to run composer install
or composer update
)
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
include the client in your project class.
<?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:
$wf = new WebFactionClient('USERNAME', 'PASSWORD', 'MACHINE', 'VERSION');
You can then perform interactions with the API using the methods.
<?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
- Fixed bug on replaceInFile method where multiple replacements were erroring
- altered composer.json to require 4.* of phpxmlrpc
- update ReadMe
- fixed "Unkown Error" exception on createWebsite on v1 and v2 of the API
- update ReadMe
- small change to exception message when using an endpoint unavailable to the current version
- update ReadMe
- 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
- update phpunit
- travis CI build integration
- update ReadMe