leo108 / php_sdk_skeleton
A skeleton for PHP SDK development
Installs: 1 016
Dependents: 5
Suggesters: 0
Security: 0
Stars: 26
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^6.3
- psr/log: ^1.0
This package is auto-updated.
Last update: 2025-01-08 21:34:05 UTC
README
A skeleton for PHP SDK development.
Installation
composer require leo108/php_sdk_skeleton -vvv
Quick Start
Let's get started with creating a simple github sdk using REST Api.
Create a class extends Leo108\SDK\AbstractApi
,
override the getFullApiUrl
method.
class RepositoryApi extends Leo108\SDK\AbstractApi {
protected function getFullApiUrl($api)
{
return 'https://api.github.com/'.$api;
}
}
Create a method called list
which will list all repos of a user.
class RepositoryApi extends Leo108\SDK\AbstractApi {
public function list($username)
{
return $this->apiGet('users/'.$username.'/repos');
}
}
Create a class extends Leo108\SDK\SDK
, implement the getApiMap
method.
class GithubSDK extends Leo108\SDK\SDK {
protected function getApiMap()
{
return [
'repository' => RepositoryApi::class,
];
}
}
All Done. Let's try it out.
$sdk = new GithubSDK();
// $resp is a Psr\Http\Message\ResponseInterface object
$resp = $sdk->repository->list('leo108');
var_dump($resp->getBody()->getContents());