Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cliVersion": "5.91.0",
"generatorName": "fernapi/fern-php-sdk",
"generatorVersion": "2.18.1",
"generatorConfig": {
"namespace": "Cloudpdf",
"packageName": "cloudpdf/cloudpdf",
"composerJson": {
"license": "Apache-2.0",
"homepage": "https://www.cloudpdf.com"
}
},
"originGitCommit": "232d5e0240d5673a73c9ea7c7ae9e7b937fdd5b3",
"originGitCommitIsDirty": false,
"invokedBy": "ci",
"requestedVersion": "3.0.0-alpha.1",
"ciProvider": "github",
"sdkVersion": "3.0.0-alpha.1"
}
22 changes: 22 additions & 0 deletions .github/workflows/sdk-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: SDK CI

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
build:
name: Build and validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer
- run: find src -type f -name '*.php' -print0 | xargs -0 -P 4 -n1 php -l >/dev/null
- run: composer validate --no-check-publish --no-interaction
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
vendor/
120 changes: 120 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Contributing

Thanks for your interest in contributing to this SDK! This document provides guidelines for contributing to the project.

## Getting Started

### Prerequisites

- PHP 8.1+
- Composer

### Installation

Install the project dependencies:

```bash
composer install
```

### Testing

Run the test suite:

```bash
composer test
```

Or run PHPUnit directly:

```bash
./vendor/bin/phpunit
```

### Linting & Formatting

Fix code style issues:

```bash
./vendor/bin/php-cs-fixer fix
```

### Static Analysis

Run static analysis:

```bash
./vendor/bin/phpstan analyse
```

## About Generated Code

**Important**: Most files in this SDK are automatically generated by [Fern](https://buildwithfern.com) from the API definition. Direct modifications to generated files will be overwritten the next time the SDK is generated.

### Generated Files

The following directories contain generated code:
- `src/` - API client classes and types
- Most PHP files in the project

### How to Customize

If you need to customize the SDK, you have two options:

#### Option 1: Use `.fernignore`

For custom code that should persist across SDK regenerations:

1. Create a `.fernignore` file in the project root
2. Add file patterns for files you want to preserve (similar to `.gitignore` syntax)
3. Add your custom code to those files

Files listed in `.fernignore` will not be overwritten when the SDK is regenerated.

For more information, see the [Fern documentation on custom code](https://buildwithfern.com/learn/sdks/overview/custom-code).

#### Option 2: Contribute to the Generator

If you want to change how code is generated for all users of this SDK:

1. The PHP SDK generator lives in the [Fern repository](https://github.com/fern-api/fern)
2. Generator code is located at `generators/php/`
3. Follow the [Fern contributing guidelines](https://github.com/fern-api/fern/blob/main/CONTRIBUTING.md)
4. Submit a pull request with your changes to the generator

This approach is best for:
- Bug fixes in generated code
- New features that would benefit all users
- Improvements to code generation patterns

## Making Changes

### Workflow

1. Create a new branch for your changes
2. Make your modifications
3. Run tests to ensure nothing breaks: `composer test`
4. Run formatting: `./vendor/bin/php-cs-fixer fix`
5. Run static analysis: `./vendor/bin/phpstan analyse`
6. Commit your changes with a clear commit message
7. Push your branch and create a pull request

### Commit Messages

Write clear, descriptive commit messages that explain what changed and why.

### Code Style

This project uses PHP CS Fixer for automated code formatting. Run `./vendor/bin/php-cs-fixer fix` before committing to ensure your code meets the project's style guidelines.

## Questions or Issues?

If you have questions or run into issues:

1. Check the [Fern documentation](https://buildwithfern.com)
2. Search existing [GitHub issues](https://github.com/fern-api/fern/issues)
3. Open a new issue if your question hasn't been addressed

## License

By contributing to this project, you agree that your contributions will be licensed under the same license as the project.
41 changes: 16 additions & 25 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
Copyright 2026 CloudPDF LTD

Licensed under the Apache License, Version 2.0 (the "License");
you may not use files in this distribution except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-----------------------------------------------------------------------

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -174,28 +190,3 @@
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
151 changes: 150 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,150 @@
# cloudpdf-sdk-php
# Cloudpdf PHP Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=Cloudpdf%2FPHP)
[![php shield](https://img.shields.io/badge/php-packagist-pink)](https://packagist.org/packages/cloudpdf/cloudpdf)

The Cloudpdf PHP library provides convenient access to the Cloudpdf APIs from PHP.

## Table of Contents

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Exception Handling](#exception-handling)
- [Advanced](#advanced)
- [Custom Client](#custom-client)
- [Retries](#retries)
- [Timeouts](#timeouts)
- [Contributing](#contributing)

## Requirements

This SDK requires PHP ^8.1.

## Installation

```sh
composer require cloudpdf/cloudpdf
```

## Usage

Instantiate and use the client with the following:

```php
<?php

namespace Example;

use Cloudpdf\CloudpdfClient;
use Cloudpdf\Tenants\Requests\TenantsCreateRequest;

$client = new CloudpdfClient(
token: '<token>',
);
$client->tenants->create(
new TenantsCreateRequest([
'id' => 'id',
]),
);

```

## Exception Handling

When the API returns a non-success status code (4xx or 5xx response), an exception will be thrown.

```php
use Cloudpdf\Exceptions\CloudpdfApiException;
use Cloudpdf\Exceptions\CloudpdfException;

try {
$response = $client->tenants->create(...);
} catch (CloudpdfApiException $e) {
echo 'API Exception occurred: ' . $e->getMessage() . "\n";
echo 'Status Code: ' . $e->getCode() . "\n";
echo 'Response Body: ' . $e->getBody() . "\n";
// Optionally, rethrow the exception or handle accordingly.
}
```

## Advanced

### Custom Client

This SDK is built to work with any HTTP client that implements the [PSR-18](https://www.php-fig.org/psr/psr-18/) `ClientInterface`.
By default, if no client is provided, the SDK will use `php-http/discovery` to find an installed HTTP client.
However, you can pass your own client that adheres to `ClientInterface`:

```php
use Cloudpdf\CloudpdfClient;

// Pass any PSR-18 compatible HTTP client implementation.
// For example, using Guzzle:
$customClient = new \GuzzleHttp\Client([
'timeout' => 5.0,
]);

$client = new CloudpdfClient(options: [
'client' => $customClient
]);

// Or using Symfony HttpClient:
// $customClient = (new \Symfony\Component\HttpClient\Psr18Client())
// ->withOptions(['timeout' => 5.0]);
//
// $client = new CloudpdfClient(options: [
// 'client' => $customClient
// ]);
```

### Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (Internal Server Error)

The `retryStatusCodes` configuration controls which [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) status codes are retried:

- `legacy` (default): Retries `408`, `429`, and all `>= 500`
- `recommended`: Retries `408`, `429`, `502`, `503`, `504` only (excludes `500 Internal Server Error` to avoid retrying non-idempotent failures)

Use the `maxRetries` request option to configure this behavior.

```php
$response = $client->tenants->create(
...,
options: [
'maxRetries' => 0 // Override maxRetries at the request level
]
);
```

### Timeouts

The SDK defaults to a 30 second timeout. Use the `timeout` option to configure this behavior.

```php
$response = $client->tenants->create(
...,
options: [
'timeout' => 3.0 // Override timeout at the request level
]
);
```

## Contributing

While we value open-source contributions to this SDK, this library is generated programmatically.
Additions made directly to this library would have to be moved over to our generation code,
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!
17 changes: 17 additions & 0 deletions cloudpdf-generation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"language": "php",
"canonicalVersion": "3.0.0-next.1",
"sdkVersion": "3.0.0-alpha.1",
"source": {
"repository": "embedpdf/embed-pdf-viewer",
"openapi": "cloudpdf/contract/openapi.json",
"openapiSha256": "6858ce7912e9063d8fb171ade95fc473db01c5971a3af241a612dda79cc05100",
"gitCommit": "232d5e0240d5673a73c9ea7c7ae9e7b937fdd5b3",
"gitCommitIsDirty": false
},
"fern": {
"cliVersion": "5.91.0",
"generatorName": "fernapi/fern-php-sdk",
"generatorVersion": "2.18.1"
}
}
Loading
Loading