Skip to content

remarkablemark/janephp-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

janephp-template

packagist build test

PHP library for Petstore. Code is generated using the OpenAPI spec.

Requirements

Version

PHP >=8.0

Install

Install the package with Composer:

composer require petstore/sdk

If you're missing a package providing psr/http-client-implementation:

composer require php-http/guzzle7-adapter

Add autoloading:

require_once 'vendor/autoload.php';

Usage

Instantiate the SDK:

use Petstore\Petstore;

$petstore = new Petstore('YOUR_API_KEY', 'YOUR_API_URL');

$client = $petstore->client;

Or create a custom client:

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:

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:

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:

composer build

composer clean

Delete the lib/ directory:

composer clean

composer test

Run the tests:

composer test

About This Package

This package is automatically generated by Jane.