PHP code example of gamez / personio

1. Go to this page and download the library: Download gamez/personio 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/ */

    

gamez / personio example snippets


$requestFactory = new \Nyholm\Psr7\Factory\Psr17Factory();
$httpClient = new \Buzz\Client\FileGetContents($requestFactory);

$requestFactory = new \Laminas\Diactoros\RequestFactory();
$httpClient = new \GuzzleHttp\Client();

use Gamez\Personio\Api\HttpApiClient;

$clientId = 'xxx';
$clientSecret = 'xxx';

/**
 * @var \Psr\Http\Message\RequestFactoryInterface $requestFactory
 * @var \Psr\Http\Client\ClientInterface $httpClient
 */
$apiClient = HttpApiClient::with($clientId, $clientSecret, $httpClient, $requestFactory);

 

use Gamez\Personio\Exception\ApiClientError;
use Gamez\Personio\Exception\PersonioException;

try {
    /** @var \Gamez\Personio\Api\ApiClient $apiClient */
    $result = $apiClient->get('nice-try');
} catch (ApiClientError $e) {
    $message = "Something went wrong while accessing {$e->getRequest()->getUri()}";

    if ($response = $e->getResponse()) {
        $message .= " ({$response->getStatusCode()})";
    }

    $message .= ' : '.$e->getMessage();

    exit($message);
} catch (PersonioException $e) {
    exit('Something not API related went really wrong: '.$e->getMessage());
}