PHP code example of ivan-novakov / php-perun-api

1. Go to this page and download the library: Download ivan-novakov/php-perun-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/ */

    

ivan-novakov / php-perun-api example snippets


    $clientConfig = array(
        
        'client' => array(
            'url' => 'https://api.example.org/rest'
        ), 
        
        'http_client' => array(
            'adapter' => 'Zend\Http\Client\Adapter\Curl', 
            'useragent' => 'Perun Client', 
            'curloptions' => array(
                CURLOPT_SSL_VERIFYPEER => true, 
                CURLOPT_SSL_VERIFYHOST => 2, 
                CURLOPT_CAINFO => '/etc/ssl/certs/ca-bundle.pem'
            )
        ), 
     
        'authenticator' => array(
            'class' => 'InoPerunApi\Client\Authenticator\ClientCertificate',
            'options' => array(
                'key_file' => '/tmp/key.pem',
                'crt_file' => '/tmp/crt.pem',
                'key_pass' => 'secret'
            )
        )
    );

    use InoPerunApi\Client\ClientFactory;
    
    $clientConfig = array(...);
    
    $clientFactory = new ClientFactory();
    $client = $clientFactory->createClient($config);

    try {
        $perunResponse = $client->sendRequest('usersManager', 'getUserById', array(
            'id' => 1234
        ));
    } catch (\Exception $e) {
        // handle exception
    }

    if ($perunResponse->isError()) {
        printf("Perun error [%s]: %s (%s)\n", $perunResponse->getErrorId(), 
            $perunResponse->getErrorType(), $perunResponse->getErrorMessage());
    }

    $payload = $perunResponse->getPayload();
    printf("User: %s %s\n", $payload->getParam('firstName'), $payload->getParam('lastName));

    $usersManager = new GenericManager($client);
    $usersManager->setManagerName('usersManager');
    
    $user = $usersManager->getUserById(array(
        'user' => 1234
    ));
    
    printf("User: %s %s\n", $user->getFirstName(), $user->getLastName());