Giter Site home page Giter Site logo

publicapi-php's Introduction

cPanel PublicAPI PHP Repository

This is the repository for the cPanel PublicAPI client written in PHP.

What's Included

The repository contains the following items. Each of which is explained in further detail below:

  • The cPanel PHP library
  • The PublicAPI client class
  • An examples directory
  • The PHPUnit tests for the cPanel PHP library and PublicAPI client class

QuickStart Example of the PublicAPI Client

This quick start example illustrates:

  1. Instantiating the PublicAPI client object with a configuration array.
  2. Invoking the whm_api() method for querying the XML-API::version function
  3. Getting the version string from the response object

Code: <?php

    // Include the autoloader
    require_once realpath( dirname(__FILE__) . '/Util/Autoload.php');
    
    // Make a configuration data array
    $config = array(
        'service' => array(
            'whm' => array(
                'config'    => array(
                    'host' => '10.1.4.191',
                    'user' => 'root',
                    'password' => 'rootsecret'
                ),
            ),
        ),
    );
    
    // Instantiate the PublicAPI client
    $cp = Cpanel_PublicAPI::getInstance($config);
    
    // Make a Whostmgr query
    $response = $cp->whm_api('version');
    
    // Print result string
    echo "WHM Version: {$response->version}\n";
    
?>

The cPanel PHP Library

The cPanel PHP library is a foundation for developers to build applications and scripts that interact with cPanel systems.

Version 0.1.0 is compatible with PHP >= 5.2

The library is divided into components. The follow list itemizes a few of the components, and their description, that are in the library:

  • Cpanel_Query

    Abstract classes for creating objects that can query a cPanel system

  • Cpanel_Service

    Concrete and abstract classes that represent cPanel Services like Whostmgr and cPanel

  • Cpanel_Parser

    Classes that allow for encoding and decoding common string and data structures

  • Cpanel_Util

    Utility files and scripts for developing with the cPanel library

  • ... and others

The PublicAPI Client Class

PublicAPI is the moniker for cPanel's defined, client interface: A contract if you will, that presents a language agnostic set of methods for interacting with cPanel systems.

The PublicAPI PHP client class in this repository is a PHP implementation of that interface. The client supports all methods of the PublicAPI interface as well as most of the methods available in previous PHP client classes, such as the XML-API client class.

Examples of how to code with the PublicAPI client class can be found:

  • In brief: The QuickStart Example of the PublicAPI Client section of this document
  • In detail: The examples directory, Cpanel/Examples/ within the repository

Version 0.1.0 is compatible with PHP >= 5.2

Examples Directory

There are several example files located in Cpanel/Examples/. Reading Introduction_to_PublicAPI.php is a good place to start. All other examples assume that you have read it.

Each example file is a working example if you substitute your own credentials and host information.

In fact, you can even run the LivePHP example, Using_the_LivePHP_Service.php, locally without having to download and install it respective of the LivePHP environment. This is possible due to a mock server that is part of the testing apparatus. Note: this is a very, very simple mock server and is not intended for anything other than example usage. So please, do not implement or rely on it.

Unit Tests

Unit tests for the cPanel PHP library and the PublicAPI client class are included in the Cpanel/Tests/ directory. They are written for use with PHPUnit >= 3.5 These test will require PHP 5.3 or greater, as they use specific Reflection functions that allow for assertions to be made on properties and methods whose visibility is private or protected.

publicapi-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

publicapi-php's Issues

Upload files using the Api

Hi,
I've been trying this for the last 2 days put can not figure it out.
As a reseller I want to create new cpanel account and upload my app in it.
I create the account, create database in it, create dbuser etc.

But how can I use the api to upload the files of the app?

Suggestion about __call method

On line 55 you could change
from:
return json_decode($this->APIcall($name, $arguments[0]));
to:
return json_decode($this->APIcall($name, $arguments[0]), true);
That will return a full array of arrays instead of a object of arrays and objects.

I changed on my local file.

Uncaught TypeError: array_key_exists(): Argument #2

I'm getting this error.

Fatal error:  Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, ArrayObject given in C:\xampp\htdocs\tests\cpanel\Cpanel\Core\Object.php:111
Stack trace:
#0 C:\xampp\htdocs\tests\cpanel\Cpanel\Core\Object.php(74): Cpanel_Core_Object->setOptions(Array)
#1 C:\xampp\htdocs\tests\cpanel\Cpanel\PublicAPI.php(102): Cpanel_Core_Object->__construct(Array)
#2 C:\xampp\htdocs\tests\cpanel\Cpanel\PublicAPI.php(140): Cpanel_PublicAPI->__construct(Array)
#3 C:\xampp\htdocs\tests\cpanel\index.php(11): Cpanel_PublicAPI::getInstance()
#4 {main}
  thrown in C:\xampp\htdocs\tests\cpanel\Cpanel\Core\Object.php on line 111

The code is:

 // Include the autoloader
 require_once realpath( dirname(__FILE__) . '/Cpanel/Util/Autoload.php');
    
 // Make a configuration data array
 $config=array(
    'service'=> array(
        'whm'=> array(
            'config'   => array(
                'host'=> '95.217.75.9',
                'user'=> 'transpas',
                'password'=> 'K05c?@eMpW8]'
            ),
        ),
    ),
);
$cp=Cpanel_PublicAPI::getInstance($config);
$accounts=$cp->whm_api('listaccts');
print_R($accounts);

Releasing composer package

Hi,
Everyone uses composer these days, why not release public API as a composer package and let composer handle the auto loading with it's optimized class map?
Thanks

Cpanel

t.me/samuel_leach_fxtm

autoloader issue

hi,

the autoloader break due to open_basedir() option enabled in some environment

PHP 5.4 - Strict Standard Error

Hi Team,

I am using PHP 5.4 and getting below error.

PHP Strict standards: Only variables should be passed by reference in D:\tmp\publicapi-php-master\publicapi-php-master\Cpanel\Ser
vice\Abstract.php on line 518

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.