PHP Classes

File: examples/README.md

Recommend this page to a friend!
  Classes of PHPLicengine   PHPLicengine API   examples/README.md   Download  
File: examples/README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHPLicengine API
Send HTTP requests to call REST Web service APIs
Author: By
Last change:
Date: 6 years ago
Size: 2,644 bytes
 

Contents

Class file image Download

API

Contents

Usage

You can use this API library for any needs, not necessarily for PHPLicengine API. To do so, you should call Api class directly or implement your own service class. You can call setApiKeyVar() method of Api class to change the Api key header variable according to requirements of your Api server, and setValidResponseHeader() method of Result class, if your Api server returns a response Api header, and you need to get it. You can get it with getReference() method. By default these are setup according to requirements of PHPLicengine API.

You can directly call Api class for your PHPLicengine API, but for your convenience we've created service classes that you can call them instead of Api class, for example see Client service class.

Custom cURL Options

If you need to add some CURLOPT_* constants that are not enabled by default, you can call setCurlCallback() method to add them.

use PHPLicengine\Api\Api;
$api = new Api();
$api->setCurlCallback(function($ch, $params, $headers, $method) { 
      curl_setopt($ch, CURLOPT_USERAGENT, 'some agent'); 
      curl_setopt($ch, CURLOPT_COOKIE, 'foo=bar'); 
      curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
      curl_setopt($ch, CURLOPT_USERPWD, "username:password");
}); 
$api->post($url, $params, $headers);

Upload Files

You can upload files with POST method and with this array structure as post parameter. Note that 'filename' must be absolute path to file.

Array
(
    [files] => Array
        (
            [0] => Array
                (
                    [filename] => /path/to/file1.txt
                )
            [1] => Array
                (
                    [filename] => /path/to/file2.txt
                )
        )
    [foo] => bar
)