Download the PHP package praxisnetau/serverpilot-api without Composer
On this page you can find all versions of the php package praxisnetau/serverpilot-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download praxisnetau/serverpilot-api
More information about praxisnetau/serverpilot-api
Files in praxisnetau/serverpilot-api
Package serverpilot-api
Short Description A wrapper and data model for the ServerPilot API implemented in PHP.
License BSD-3-Clause
Homepage https://github.com/praxisnetau/serverpilot-api
Informations about the package serverpilot-api
ServerPilot API
A wrapper and data model for the ServerPilot API implemented in PHP.
Requires
- PHP 5.3.3 or newer
- curl/curl 1.4 or newer
- PHP JSON extension
- an account with ServerPilot (+ valid Client ID and API Key)
Installation
You can install the API in your project either via Composer on the command-line:
...or by adding it to your project composer.json file:
...followed by this command:
Usage
You will need to create a Client ID and API Key via your ServerPilot control panel. Once you have these, you may create an instance of the API by passing in your credentials like so:
The API will throw an Exception
if the credentials are invalid, or if it encounters any other problem, so it's
a good idea to wrap your API code in a try/catch block, e.g.:
You may also set the credentials via the config object if you like:
Commands
The API works by routing property calls to a series of command objects. By default, these property names and methods match those given by the ServerPilot API documentation, i.e.:
Servers
Handles server-related operations.
System Users
Handles operations on system users.
Apps
Handles operations on apps.
Databases
Handles database-related operations.
Actions
Retrieve the status of an action.
Data Model
While the API commands are powerful, it can sometimes be clumsy to issue a series of commands directly via the API. Enter the data model. Model objects are provided for each of the API command areas, including:
Action
ActionStatus
App
Database
DatabaseUser
Server
SystemUser
Rather than returning decoded JSON data, the API returns either individual instances of data model classes, or arrays of data model classes (when multiple results are returned).
These model objects are API-aware and can be manipulated directly without making a separate call
to the API. All model objects have an update()
and a delete()
method. For example:
Or, consider the following:
Tired of that old app? Why not delete it!
Retrieving Action Status
Every time the API performs an operation where something is changed, an Action
is
recorded. It can be handy to see the last action that was performed, and
you can retrieve this object by calling getLastAction()
on the API:
If you just need the ID of the last action, you can use getLastActionID()
:
You can go a step further and check the status of the action using the getStatus
method, which returns an ActionStatus
object:
Alternatively, you can retrieve the status of the last action directly from the API using getLastActionStatus()
:
DateTime Accessors
DateTime
accessor methods are present for all properties returned as a timestamp via the API. For example:
To Do
- implement paid plan SSL functionality for Apps
- expand data model to support additional functionality