Download the PHP package haveapi/client without Composer

On this page you can find all versions of the php package haveapi/client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package client

haveapi-client-php

haveapi-client-php is a PHP client for HaveAPI based APIs.

Requirements

Installation

haveapi-client-php can be installed with composer, add haveapi/client to your composer.json:

{
    "require": {
        "haveapi/client": "*"
    }
}

You can also clone this repository and use a PSR-4 compatible autoloader, or include bootstrap.php, which loads all necessary classes. When using the repository, you have to install Httpful yourself.

Usage

First check out the API documentation, see how it works and what resources/actions are available.

Create a client instance:

$api = new \HaveAPI\Client("http://your.api.tld");

Request translated API messages and translate local client-side validation errors by passing language in the options array:

$api = new \HaveAPI\Client(
    "http://your.api.tld",
    null,
    "haveapi-client-php",
    ["language" => "cs"]
);

The value is sent in Accept-Language by default. Use language_header in the options array when the API is configured with a custom language header. Set the language before setup() or authenticate() so translated validator descriptions are loaded from the server.

Authenticate with HTTP basic:

$api->authenticate('basic', ['user' => 'yourname', 'password' => 'password']);

Authenticate with token:

$api->authenticate('token', ['user' => 'yourname', 'password' => 'password']);

When using the token authentication, it is usually necessary to save the token for later use:

$token = $api->getAuthenticationProvider()->getToken();

Next time, authenticate with the previously received token:

$api->authenticate('token', ['token' => $token]);

Access resources and actions as array indexes

$api['vps']['index']->call();
$api['vps']['show']->call(101);

or

$api['vps.index']->call();
$api['vps.show']->call(101);

Access resources and actions as properties/methods

$api->vps->list();

Arguments can be supplied to resources and/or to the action.

$api->vps->find(101);
$api->vps->ip_address->delete(101, 10);

$api->vps(101)->find();
$api->vps(101)->ip_address(10)->delete();
$api->vps(101)->ip_address->delete(10);

Parameters

Parameters are given as an array to action. It is the last argument given to action. Object IDs must be in front of it.

$api->vps->create([
    'hostname' => 'myhostname',
    'template' => 1
]);

$api->vps->ip_address->create(101, ['version' => 4]);
$api->vps(101)->ip_address->create(['version' => 4]);

Object-like behaviour

Fetch existing resource:

$vps = $api->vps->find(101);
echo $vps->id . "<br>";
echo $vps->hostname . "<br>";
$vps->hostname = 'gotcha';
$vps->save();

Create a new instance:

$vps = $api->vps->newInstance();
$vps->hostname = 'new vps';
$vps->save();
echo $vps->id . "<br>";

List of resources:

$vpses = $api->vps->list();

foreach($vpses as $vps) {
    echo $vps->id ." = ". $vps->hostname ."<br>";
}

Response

If the action does not return object or object list, \HaveAPI\Client\Response class is returned instead.

$vps = $api->vps->find(101);
$response = $vps->custom_action();

print_r($response->getResponse());

Parameters can be accessed directly as:

echo $response['hostname'];

Error handling

If an action fails, exception \HaveAPI\Client\Exception\ActionFailed is thrown. Authentication errors result in exception \HaveAPI\Client\Exception\AuthenticationFailed.

try {
    $api->vps->create();

} catch(\HaveAPI\Client\Exception\ActionFailed $e) {
    echo $e->getMessage();
    print_r($e->getErrors());
}

When trying to access a resource or an action that does not exist, \HaveAPI\Client\Exception\ObjectNotFound is thrown. Also, invoking an action without all necessary arguments (object IDs) results in \HaveAPI\Client\Exception\UnresolvedArguments exception.

All exceptions thrown by the client are a subclass of \HaveAPI\Client\Exception\Base.

Development

From the HaveAPI repository root, enter the locked Nix shell and check formatting:

Remove --dry-run to apply formatting to authored PHP sources and tests. The configuration uses @PER-CS3x0 without PHP migration rules, preserving the PHP 8.0 syntax requirement. The generated src/Client/I18nMessages.php catalog is excluded; update its source through the repository's localization workflow.

CI runs the same formatting command and checks all shipped src/ PHP files and bootstrap.php with PHP 8.0's syntax checker. This syntax lane needs no Composer dependencies. PHPUnit runs separately on PHP 8.3 and 8.4 because PHPUnit 10 needs PHP 8.1 or newer. See the repository's development commands for test setup.

Documentation

https://projects.vpsfree.cz/haveapi-client-php/ref/

License

haveapi-client-php is released under the MIT license.


All versions of client with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.0
league/oauth2-client Version ~2.7.0
vpsfreecz/httpful Version ~0.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package haveapi/client contains the following files

Loading the files please wait ...