https://github.com/remarkablemark/janephp-template
🌱 JanePHP template
https://github.com/remarkablemark/janephp-template
composer janephp openapi petstore petstore-api php php-library php-sdk swagger template
Last synced: 12 months ago
JSON representation
🌱 JanePHP template
- Host: GitHub
- URL: https://github.com/remarkablemark/janephp-template
- Owner: remarkablemark
- License: mit
- Created: 2025-02-25T03:35:55.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-02-25T03:43:30.000Z (12 months ago)
- Last Synced: 2025-02-25T04:29:17.708Z (12 months ago)
- Topics: composer, janephp, openapi, petstore, petstore-api, php, php-library, php-sdk, swagger, template
- Language: PHP
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# janephp-template
[](https://packagist.org/packages/petstore/sdk)
[](https://github.com/remarkablemark/janephp-template/actions/workflows/build.yml)
[](https://github.com/remarkablemark/janephp-template/actions/workflows/test.yml)
PHP library for [Petstore](https://petstore3.swagger.io/). Code is generated using the [OpenAPI spec](https://petstore3.swagger.io/api/v3/openapi.json).
## Requirements
### Version
PHP >=8.0
## Install
Install with [Composer](http://getcomposer.org/):
```sh
composer require petstore/sdk
```
Use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
```php
require_once 'vendor/autoload.php';
```
## Usage
Instantiate the client:
```php
use Petstore\Petstore;
$petstore = new Petstore('YOUR_API_KEY', 'YOUR_API_URL');
$client = $petstore->client;
```
Or create a custom client:
```php
use Petstore\Client;
$httpClient = \Http\Discovery\Psr18ClientDiscovery::find();
$uri = \Http\Discovery\Psr17FactoryDiscovery::findUriFactory()->createUri('YOUR_API_URL');
$bearer = new \Http\Message\Authentication\Bearer('YOUR_API_KEY');
$plugins = [
new \Http\Client\Common\Plugin\AddHostPlugin($uri),
new \Http\Client\Common\Plugin\AuthenticationPlugin($bearer),
];
$httpClient = new \Http\Client\Common\PluginClient($httpClient, $plugins);
$client = Client::create($httpClient);
```
Add a pet:
```php
use Petstore\Petstore;
use Petstore\Model\Pet;
$petstore = new Petstore('YOUR_API_KEY');
$pet = new Pet();
$pet->setName('Neo');
$pet->setPhotoUrls(['https://placecats.com/neo/300/200']);
$response = $petstore->client->addPet($pet);
```
Handle an API error:
```php
use Petstore\Petstore;
$petstore = new Petstore('YOUR_API_KEY');
try {
$petstore->client->getPetById(0);
} catch (Throwable $exception) {
echo $exception->getMessage();
echo $exception->getCode();
}
```
## Scripts
### `composer build`
Generate the code:
```sh
composer build
```
### `composer clean`
Delete the `lib/` directory:
```sh
composer clean
```
### `composer test`
Run the tests:
```sh
composer test
```
## About This Package
This package is automatically generated by [Jane](https://github.com/janephp/janephp).