PHP code example of juststeveking / php-sdk

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

    

juststeveking / php-sdk example snippets


use JustSteveKing\Sdk\Client;

final class YourSDK extends Client
{
    //
}

use JustSteveKing\Sdk\Client;
use JustSteveKing\Sdk\Tests\Stubs\Resources\ProjectResource;

final class YourSDK extends Client
{
    public function projects()
    {
        return new ProjectResource(
            client: $this,
        );
    }
}

final class ProjectResource
{
    //
}

use Exception;
use JustSteveKing\Sdk\Concerns\Resources;
use JustSteveKing\Tools\Http\Enums\Method;
use Ramsey\Collection\Collection;
use Throwable;

final class ProjectResource
{
    use Resources\CanAccessClient;
    use Resources\CanCreateDataObjects;
    use Resources\CanCreateRequests;

    public function all(): Collection
    {
        $request = $this->request(
            method: Method::GET,
            uri: '/projects',
        );

        try {
            $response = $this->client->send(
                request: $request,
            );
        } catch (Throwable $exception) {
            throw new Exception(
                message: 'Failed to list test.',
                code: $exception->getCode(),
                previous: $exception,
            );
        }

        return (new Collection(
            collectionType: Project::class,
            data: array_map(
                callback: static fn(array $data): Project => Project::make(
                    data: $data,
                ),
                array: (array) json_decode(
                    json: $response->getBody()->getContents(),
                    associative: true,
                    flags: JSON_THROW_ON_ERROR,
                ),
            ),
        ));
    }
}
shell
composer