PHP code example of foobarfighters / zend-server-web-api

1. Go to this page and download the library: Download foobarfighters/zend-server-web-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

foobarfighters / zend-server-web-api example snippets




$config = [
    'baseUrl' => 'https://your.zend.server.url',

    //== ZendServer admin > Administration > Web API Keys > UserName
    'username' => 'foobar',

    //== ZendServer admin > Administration > Web API Keys > Hash
    'hash' => 'f1ghtErs6fddd00ccec4eb1b261a8f6cc2dad94c1eb100eab',

    //== see https://help.zend.com/zend/current/content/web_api_reference_guide.htm
    'version' => 1.23,
];

use FooBarFighters\ZendServer\WebApi\Client\ClientFactory;

try{
    //== instantiate a core client
    $client = ClientFactory::createClient($config);
    
    //== get the raw API data as an associative array
    $res = $client->applicationGetStatus();
    
    //== do something useful with it
    print_r($res['responseData']);
}

//== one size fits all
catch(Exception $e){
    error_log($e);
    echo 'stay calm, the internet police has been notified!';
}


use FooBarFighters\ZendServer\WebApi\Client\ClientFactory;

try{
    //== instantiate an extended client
    $client = ClientFactory::createExtendedClient($config);
    
    //== reduce the list of applications to a single app model
    $myApp = $client->getAppList()->filterByName('myAppName');
    
    //== do something very exciting with it
    echo $myApp->getId();
}

//== several types of specific exceptions can be thrown, like Guzzle or Api related
catch(\FooBarFighters\ZendServer\WebApi\Exception\ApiException $e){
    echo 'You broke the API!';
}

$handlerStack = HandlerStack::create();
//== add middleware or custom handlers
...
$client = ClientFactory::createExtendedClient($config, new Guzzle(['handler' => $handlerStack]));
`bash
cd vendor/foobarfighters/ZendServer
php -S localhost:8080 -t examples