> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsun SDK for PHP

> This section describes how to use Upsun SDK for PHP.

The official **Upsun SDK for PHP**. This SDK provides a PHP interface that maps to the Upsun CLI commands.

For more information, read [the documentation](https://docs.upsun.com/api).

> **CAUTION**:
> This project is currently in **Beta**, meaning features and APIs may evolve over time.
>
> Please report bugs or request new features by creating a GitHub issue.

## Installation

Install the SDK via Composer:

```bash theme={null}
composer require upsun/upsun-sdk-php
```

Then include Composer's autoloader in your PHP application:

```php theme={null}
require __DIR__ . '/vendor/autoload.php';
```

## Authentication

You will need an [Upsun API token](https://docs.upsun.com/administration/cli/api-tokens.html) to use this SDK.
Store it securely, preferably in an environment variable.

```php theme={null}
use Upsun\UpsunConfig;
use Upsun\UpsunClient;

$config = new UpsunConfig(apiToken: getenv('UPSUN_API_TOKEN'));
$upsunClient = new UpsunClient($config);
```

## Usage

### Example: List organizations

```php theme={null}
$organizations = $upsunClient->organizations->list();
```

### Example: List projects in an organization

```php theme={null}
$projects = $upsunClient->projects->list('<organizationId>');
```

### Example: Redeploy an environment

```php theme={null}
$response = $upsunClient->environments->redeploy('<projectId>', '<environmentId>');
```

***

## Development

Clone the repository and install dependencies:

```bash theme={null}
git clone git@github.com:upsun/upsun-sdk-php.git
composer install
```

## Architecture of this SDK

The SDK is built as follows:

* From the [JSON specs of our API](https://docs.upsun.com/api/openapispec-upsun.json)
* Using [`@openapitools/openapi-generator-cli`](https://www.npmjs.com/package/%40openapitools/openapi-generator-cli)
* Which generates:
  * PHP **Models** (in `src/Model/`)
  * PHP **APIs** (in `src/Api/`)
* Higher-level PHP (Facade) oriented **Tasks** (in `src/Core/Tasks/`)

### Regenerating API & Model classes

API and Model classes are generated using [openapi-generator-cli](https://openapi-generator.tech)
from the [Upsun OpenAPI spec](https://docs.upsun.com/api/openapispec-upsun.json).

```bash theme={null}
composer run spec:install
composer run spec:full
```

## Contributing

Contributions are welcome!<br />
Please open a [pull request](https://github.com/upsun/upsun-sdk-php/compare) or an [issue](https://github.com/upsun/upsun-sdk-php/issues/new)
for any improvements, bug fixes, or new features.

## Tests

To run the tests, use:

```bash theme={null}
composer install
composer run test
```

## License

This project is licensed under the Apache License 2.0. See the [LICENSE](https://github.com/upsun/upsun-sdk-php/blob/main/LICENSE) and [NOTICE](https://github.com/upsun/upsun-sdk-php/blob/main/NOTICE) files for details.
