gamez / personio
Interact with Personio (https://www.personio.de) from your PHP application.
Fund package maintenance!
jeromegamez
Installs: 37 539
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=7.4
- ext-json: *
- ext-mbstring: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.3
- kriswallsmith/buzz: ^1.2
- laminas/laminas-diactoros: ^2.5
- nyholm/psr7: ^1.4
- symfony/var-dumper: ^5.2
Suggests
- guzzlehttp/guzzle: Allows the usage of the Guzzle Api Client
- psr/http-client-implementation: Allows the usage of the PSR-18 Api Client
- psr/http-factory-implementation: Required for the PSR-18 Api Client
README
Interact with Personio from your PHP application.
Requirements
- A Client ID and Client Secret (You can generate them at https://xxx.personio.de/configuration/api/credentials)
Installation
In order to use this library, you need a PSR-18 HTTP Client, and a PSR-17 HTTP Message Factory.
Example using kriswallsmith/buzz
and nyholm/psr7
composer require kriswallsmith/buzz nyholm/psr7 gamez/personio
$requestFactory = new \Nyholm\Psr7\Factory\Psr17Factory(); $httpClient = new \Buzz\Client\FileGetContents($requestFactory);
Example using guzzlehttp/guzzle
and laminas/laminas-diactoros
composer require guzzlehttp/guzzle laminas/laminas-diactoros gamez/personio
$requestFactory = new \Laminas\Diactoros\RequestFactory(); $httpClient = new \GuzzleHttp\Client();
Usage
Basic API client
Once you have created an HTTP Client and Request Factory as described in the installation section, you can create an API client with them:
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);
This API client allows you to make authenticated HTTP requests to the API of your Personio account - see Personio's REST API documentation for the endpoints you can use.
Simple API
Gamez\Personio\SimpleApi
is the easiest and fastest way to access the data in your
Personio account. Its methods are named after the available REST API endpoints
and return arrays of data. You can inspect the available methods by looking at the
source code of the Gamez\Personio\SimpleApi
class or by using the
autocompletion features of your IDE.
The Simple API doesn't get in your way when accessing the Personio API, but it doesn't provide additional features either. It will, for example, not tell you if you used a wrong query parameter or invalid field value, so you will have to rely on the returned API responses.
For information on which query parameters and field values are allowed, see Personio Developer Hub.
Catching errors
All exceptions thrown by this library implement the \Gamez\Personio\Exception\PersonioException
interface.
Exceptions thrown while using an API Client will throw a \Gamez\Personio\Exception\ApiClientError
.
<?php 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()); }
Caching HTTP requests
To cache HTTP requests to the API, you can add a caching middleware/plugin to the HTTP client before injecting it into the API client instance. See the documentation of the respective component for instructions on how to do that.
- Guzzle: kevinrob/guzzle-cache-middleware
- HTTPlug: Cache Plugin
Creating your own API client
If you want to create your own API client, implement the \Gamez\Personio\Api\ApiClient
interface
and use your implementation.
License
gamez/personio
is licensed under the MIT License.
Your use of Personio is governed by the Terms of Service for Personio.