Skip to content

Commit 67e78f6

Browse files
committed
docs: agent-optimize README + add AGENTS.md/CLAUDE.md and IDE pointer files
1 parent 4b989f4 commit 67e78f6

5 files changed

Lines changed: 191 additions & 83 deletions

File tree

.cursor/rules/cloudinary.mdc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description: Cloudinary cloudinary_php — agent guide
3+
alwaysApply: true
4+
---
5+
6+
Read and follow `AGENTS.md` in the repository root. It is the single
7+
authoritative guide for this package: build/test commands, conventions,
8+
gotchas, and when to use this SDK versus a sibling Cloudinary package.

.github/copilot-instructions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Cloudinary cloudinary_php — instructions for AI coding agents
2+
3+
Read `AGENTS.md` in the repository root and follow it. It is the single
4+
authoritative guide for this package: build/test commands, conventions,
5+
gotchas, and when to use this SDK versus a sibling Cloudinary package.

AGENTS.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# AGENTS.md — cloudinary_php
2+
3+
## What this package is (one line)
4+
Official Cloudinary **PHP server-side SDK**: upload assets, build transformation/delivery URLs and HTML tags, and call the Admin API from your backend — the package that holds your `API_SECRET`.
5+
6+
## When to use this / when NOT to use this
7+
- **Use this when:** code runs on a **server** (Laravel, Symfony, plain PHP, a CLI worker) and needs signed/preset uploads, asset administration (search, rename, tag, delete, folders), or signed delivery URLs and tags where the `API_SECRET` must stay private.
8+
- **Do NOT use this when:** you are building **browser-side** delivery URLs — use [`@cloudinary/url-gen`](https://github.com/cloudinary/js-url-gen) in the frontend, never a PHP package; or you want the autonomous/no-code path — use the [Cloudinary MCP server](https://github.com/cloudinary/mcp-servers).
9+
- **Sibling packages:** this SDK already **bundles** the lower-level transformation builder [`php-transformation-builder-sdk`](https://github.com/cloudinary/php-transformation-builder-sdk) (Composer dep `cloudinary/transformation-builder-sdk: ^2`) — prefer this package over depending on it directly. A separate [`php-url-builder`](https://github.com/cloudinary/php-url-builder) exists as a low-level helper but is **not** a dependency of this SDK. Rule of thumb: server → this package; browser → `@cloudinary/url-gen`.
10+
11+
## Setup
12+
```bash
13+
composer require "cloudinary/cloudinary_php"
14+
```
15+
Required configuration / credentials (the SDK reads `CLOUDINARY_URL` automatically):
16+
```bash
17+
export CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME
18+
```
19+
20+
## Minimal runnable example
21+
```php
22+
use Cloudinary\Cloudinary;
23+
use Cloudinary\Transformation\Resize;
24+
use Cloudinary\Transformation\Format;
25+
26+
$cloudinary = new Cloudinary(); // reads CLOUDINARY_URL from env
27+
28+
// Upload a local file (server-side, signed)
29+
$cloudinary->uploadApi()->upload('my_image.jpg');
30+
31+
// Build a delivery URL for an uploaded asset
32+
echo $cloudinary->image('sample.jpg')
33+
->resize(Resize::fill()->width(100)->height(150))
34+
->format(Format::auto());
35+
```
36+
37+
## Build / test commands (run these after editing)
38+
Requires PHP 8.0+ and Composer. There is **no** `scripts` block in `composer.json`; invoke the dev binaries in `vendor/bin/` directly. **Only `simple-phpunit` runs in CI** (`.github/workflows/test.yaml`); `phpcs`/`php-cs-fixer` are local-only dev tools, not wired into any workflow.
39+
```bash
40+
composer install # or `composer update -n` as CI does
41+
vendor/bin/simple-phpunit # the test suite (symfony/phpunit-bridge) — this is what CI runs; run after any change to src/
42+
vendor/bin/phpcs # local lint against the committed phpcs.xml (squizlabs/php_codesniffer)
43+
```
44+
Tests hit a real cloud: CI sets `CLOUDINARY_URL` before running (`tools/get_test_cloud.sh`); locally export your own `CLOUDINARY_URL` first or the integration tests will fail.
45+
46+
## Conventions & gotchas
47+
- **Formatter/linter (local only, not in CI):** a PSR-style ruleset is committed as `phpcs.xml` (PHP_CodeSniffer). `friendsofphp/php-cs-fixer` is also a dev dep, but **no `.php-cs-fixer` config is committed at the repo root**, so it runs with its defaults.
48+
- **Autoload:** `src/` is classmap-autoloaded; tests are PSR-4 under `Cloudinary\Test\``tests/`. Public namespace root is `Cloudinary\`.
49+
- **`API_SECRET` stays on the server.** That is the entire reason this SDK exists — never ship it to a browser bundle. Signed uploads and signed URLs are server-only.
50+
- **Version support:** current release line is **3.x**, requires **PHP 8.0–8.4** (CI matrix: 8.0, 8.1, 8.2, 8.3, 8.4). 1.x lives on the `support/1.x` branch; see the version table in `README.md`.
51+
52+
## Canonical docs (leave the repo for depth)
53+
- PHP SDK guide: https://cloudinary.com/documentation/php_integration
54+
- Upload: https://cloudinary.com/documentation/php_image_and_video_upload — Admin/asset admin: https://cloudinary.com/documentation/php_asset_administration
55+
- Migration to 2.x/3.x: https://cloudinary.com/documentation/php2_migration
56+
- API & transformation reference: https://cloudinary.com/documentation/cloudinary_references
57+
- MCP server (agent/no-code path): https://github.com/cloudinary/mcp-servers
58+
59+
## Agent / MCP note
60+
If the capability you need is also exposed via the Cloudinary MCP servers, prefer the MCP tool for autonomous task execution and use this SDK for code generation. See cloudinary/mcp-servers.
61+
62+
## Commit / PR conventions
63+
- Ensure tests run locally before opening a PR, and ensure CI (`Tests` workflow, PHP 8.0–8.4 matrix) passes.
64+
- Issues: https://github.com/cloudinary/cloudinary_php/issues. Released under the MIT license.

CLAUDE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@AGENTS.md
2+
3+
# CLAUDE.md — cloudinary_php
4+
5+
## What this repo is
6+
7+
Official Cloudinary PHP server-side SDK (`cloudinary/cloudinary_php`, 3.x). Handles signed/preset uploads, Admin API calls, asset search, and server-generated transformation URLs and HTML tags — the package that holds your `API_SECRET`.
8+
9+
## Key constraints / gotchas
10+
11+
- **API surfaces are methods, not properties.** Call `$cloudinary->uploadApi()->upload(...)`, not `$cloudinary->uploadApi->upload(...)` — the latter throws.
12+
- **`API_SECRET` stays on the server.** Never ship it in a browser bundle. Use `ApiUtils::signParameters()` to produce a signature the browser posts directly to Cloudinary.
13+
- **`CLOUDINARY_URL` must be in the running process env.** The SDK does not parse `.env` files itself — if you use phpdotenv/Laravel/Symfony, load it before `new Cloudinary()`.
14+
- **No `scripts` block in `composer.json`** — invoke dev tools via `vendor/bin/` directly (see Build commands below).
15+
- **Only `simple-phpunit` runs in CI** (`.github/workflows/test.yaml`). `phpcs` and `php-cs-fixer` are local-only dev deps, not wired into any workflow.
16+
- **No `.php-cs-fixer` config at repo root** — it runs with defaults; the committed ruleset is `phpcs.xml` (PHP_CodeSniffer).
17+
- **Transformation builder is bundled.** `cloudinary/transformation-builder-sdk` is a Composer dep — do not add it separately. Classes live in `Cloudinary\Transformation\`.
18+
- **PHP 8.0+ required** for 3.x. CI matrix: 8.0, 8.1, 8.2, 8.3, 8.4. Legacy 1.x is on the `support/1.x` branch.
19+
- **Integration tests hit a real cloud.** Export `CLOUDINARY_URL=cloudinary://API_KEY:API_SECRET@CLOUD_NAME` before running the suite locally, or tests will fail.
20+
21+
## Verified build commands
22+
23+
```bash
24+
composer install # install deps (CI uses `composer update -n`)
25+
vendor/bin/simple-phpunit # test suite (symfony/phpunit-bridge) — what CI runs
26+
vendor/bin/phpcs # lint against phpcs.xml (local only)
27+
```
28+
29+
## Autoload layout
30+
31+
- `src/` — classmap-autoloaded; public namespace root `Cloudinary\`
32+
- `tests/` — PSR-4 under `Cloudinary\Test\`

README.md

Lines changed: 82 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,129 @@
1+
# Cloudinary PHP SDK
2+
13
[![Tests](https://github.com/cloudinary/cloudinary_php/actions/workflows/test.yaml/badge.svg)](https://github.com/cloudinary/cloudinary_php/actions/workflows/test.yaml)
2-
[![license](https://img.shields.io/github/license/cloudinary/cloudinary_php.svg?maxAge=2592000)](https://github.com/cloudinary/cloudinary_php/blob/master/LICENSE)
3-
[![Packagist](https://img.shields.io/packagist/v/cloudinary/cloudinary_php.svg?maxAge=2592000)](https://packagist.org/packages/cloudinary/cloudinary_php)
4-
[![Packagist](https://img.shields.io/packagist/dt/cloudinary/cloudinary_php.svg?maxAge=2592000)](https://packagist.org/packages/cloudinary/cloudinary_php/stats)
4+
[![license](https://img.shields.io/github/license/cloudinary/cloudinary_php.svg)](https://github.com/cloudinary/cloudinary_php/blob/master/LICENSE)
5+
[![Packagist](https://img.shields.io/packagist/v/cloudinary/cloudinary_php.svg)](https://packagist.org/packages/cloudinary/cloudinary_php)
56

6-
Cloudinary PHP SDK
7-
==================
7+
The `cloudinary/cloudinary_php` package is the server-side Cloudinary SDK for PHP. Use it on a server or in a build step to upload assets, build transformation and delivery URLs, and call the Admin API. It holds the API secret, so it handles the operations that can't run in a browser: signed uploads, signed delivery URLs, and asset administration. The current release (3.x) requires PHP 8.0 or later.
88

9-
## About
9+
## Installation
1010

11-
The Cloudinary PHP SDK allows you to quickly and easily integrate your application with Cloudinary.
12-
Effortlessly optimize, transform, upload and manage your cloud's assets.
11+
```bash
12+
composer require "cloudinary/cloudinary_php"
13+
```
1314

14-
#### Note
15+
This pulls in the bundled transformation builder (`cloudinary/transformation-builder-sdk`) automatically.
1516

16-
This Readme provides basic installation and usage information.
17-
For the complete documentation, see the [PHP SDK Guide](https://cloudinary.com/documentation/php_integration).
17+
## Configuration
1818

19-
## Table of Contents
19+
Construct a `Cloudinary` instance with no arguments and it reads credentials from the `CLOUDINARY_URL` environment variable:
2020

21-
- [Key Features](#key-features)
22-
- [Version Support](#Version-Support)
23-
- [Installation](#installation)
24-
- [Usage](#usage)
25-
- [Setup](#Setup)
26-
- [Transform and Optimize Assets](#Transform-and-Optimize-Assets)
21+
```bash
22+
CLOUDINARY_URL=cloudinary://<API_KEY>:<API_SECRET>@<CLOUD_NAME>
23+
```
2724

28-
## Key Features
25+
```php
26+
require 'vendor/autoload.php';
2927

30-
- [Transform](https://cloudinary.com/documentation/php_video_manipulation#video_transformation_examples) and
31-
[optimize](https://cloudinary.com/documentation/php_image_manipulation#image_optimizations) assets.
32-
- Generate [image](https://cloudinary.com/documentation/php_image_manipulation#deliver_and_transform_images) and
33-
[video](https://cloudinary.com/documentation/php_video_manipulation#php_video_transformation_code_examples) tags.
34-
- [Asset Management](https://cloudinary.com/documentation/php_asset_administration).
35-
- [Secure URLs](https://cloudinary.com/documentation/video_manipulation_and_delivery#generating_secure_https_urls_using_sdks).
28+
use Cloudinary\Cloudinary;
3629

37-
## Version Support
30+
$cloudinary = new Cloudinary(); // credentials come from CLOUDINARY_URL in the environment
31+
```
3832

39-
| SDK Version | PHP 5.4 | PHP 5.5 | PHP 5.6 | PHP 7.x | PHP 8.0 - 8.3 | PHP 8.4 |
40-
|-------------|---------|---------|---------|---------|---------------|---------|
41-
| 3.x |||||||
42-
| 2.x |||||| ✘ * |
43-
| 1.x |||||||
33+
To set them in code instead, pass a configuration array:
4434

45-
\* Deprecation warnings
35+
```php
36+
require 'vendor/autoload.php';
4637

47-
## Installation
38+
use Cloudinary\Cloudinary;
4839

49-
```bash
50-
composer require "cloudinary/cloudinary_php"
40+
$cloudinary = new Cloudinary([
41+
'cloud' => [
42+
'cloud_name' => 'my_cloud_name',
43+
'api_key' => 'my_key',
44+
'api_secret' => 'my_secret',
45+
],
46+
]);
5147
```
5248

53-
# Usage
54-
55-
### Migration
49+
Keep the API secret on the server. Don't put it in client-side code or commit it to version control.
5650

57-
See the [Cloudinary PHP SDK Migration guide](https://cloudinary.com/documentation/php2_migration) for more information
58-
on migrating to this version of the PHP SDK.
51+
## Quick examples
5952

60-
The previous (1.x) version of the SDK is located [here](https://github.com/cloudinary/cloudinary_php/tree/support/1.x).
53+
### Upload a file
6154

62-
### Setup
55+
`uploadApi()->upload()` takes a local path, a remote HTTP/HTTPS URL, raw data, or a base64 data URI as its first argument. It returns an array-accessible `ApiResponse` that includes `public_id` and `secure_url`:
6356

6457
```php
58+
require 'vendor/autoload.php';
59+
6560
use Cloudinary\Cloudinary;
6661

67-
$cloudinary = new Cloudinary();
62+
$cloudinary = new Cloudinary(); // credentials come from CLOUDINARY_URL in the environment
63+
64+
$result = $cloudinary->uploadApi()->upload('my_image.jpg', [
65+
'public_id' => 'cms/hero', // optional: where the asset lives in your media library
66+
]);
67+
68+
echo $result['public_id'], ' ', $result['secure_url'];
6869
```
6970

70-
### Transform and Optimize Assets
71+
### Transform and optimize a delivery URL
7172

72-
- [See full documentation](https://cloudinary.com/documentation/php_image_manipulation).
73+
`image()` returns a builder you can cast to a string — no network call. This resizes to a 100x150 fill crop and lets Cloudinary pick the format and quality for the requesting browser (`f_auto`, `q_auto`):
7374

7475
```php
75-
$cloudinary->image('sample.jpg')->resize(Resize::fill()->width(100)->height(150))->format(Format::auto());
76-
```
76+
require 'vendor/autoload.php';
7777

78-
### Upload
78+
use Cloudinary\Cloudinary;
79+
use Cloudinary\Transformation\Resize;
80+
use Cloudinary\Transformation\Format;
81+
use Cloudinary\Transformation\Quality;
7982

80-
- [See full documentation](https://cloudinary.com/documentation/php_image_and_video_upload).
81-
- [Learn more about configuring your uploads with upload presets](https://cloudinary.com/documentation/upload_presets).
83+
$cloudinary = new Cloudinary();
8284

83-
```php
84-
$cloudinary->uploadApi->upload('my_image.jpg');
85+
echo $cloudinary->image('sample.jpg')
86+
->resize(Resize::fill()->width(100)->height(150))
87+
->format(Format::auto())
88+
->quality(Quality::auto());
89+
// https://res.cloudinary.com/demo/image/upload/c_fill,h_150,w_100/f_auto/q_auto/sample.jpg
8590
```
8691

87-
### Security options
92+
### Retrieve asset details
8893

89-
- [See full documentation](https://cloudinary.com/documentation/solution_overview#security).
94+
`adminApi()->asset()` takes a public ID and returns the asset's metadata, including its format, dimensions, and `secure_url`:
9095

91-
## Contributions
96+
```php
97+
require 'vendor/autoload.php';
9298

93-
- Ensure tests run locally
94-
- Open a PR and ensure Travis tests pass
99+
use Cloudinary\Cloudinary;
95100

96-
## Get Help
101+
$cloudinary = new Cloudinary(); // credentials come from CLOUDINARY_URL in the environment
97102

98-
If you run into an issue or have a question, you can either:
103+
$asset = $cloudinary->adminApi()->asset('sample');
99104

100-
- Issues related to the SDK: [Open a GitHub issue](https://github.com/cloudinary/cloudinary_php/issues).
101-
- Issues related to your account: [Open a support ticket](https://cloudinary.com/contact)
105+
echo $asset['format'], ' ', $asset['width'], 'x', $asset['height'], ' ', $asset['secure_url'];
106+
```
102107

103-
## About Cloudinary
108+
## For AI agents
104109

105-
Cloudinary is a powerful media API for websites and mobile apps alike, Cloudinary enables developers to efficiently
106-
manage, transform, optimize, and deliver images and videos through multiple CDNs. Ultimately, viewers enjoy responsive
107-
and personalized visual-media experiences—irrespective of the viewing device.
110+
`cloudinary/cloudinary_php` is the PHP server-side SDK. Choose it for backend upload, asset administration, search, and signed URL or tag generation, where the API secret stays private. The API surfaces are methods, not properties: call `$cloudinary->uploadApi()->upload(...)`, not `$cloudinary->uploadApi->upload(...)`. For other Cloudinary tasks, choose a different package:
108111

109-
## Additional Resources
112+
| Task | Package |
113+
|---|---|
114+
| Build transformations at a lower level (already bundled here) | [`cloudinary/transformation-builder-sdk`](https://github.com/cloudinary/php-transformation-builder-sdk) |
115+
| Build delivery URLs with a low-level PHP helper | [`php-url-builder`](https://github.com/cloudinary/php-url-builder) |
116+
| Build delivery URLs in the browser | [`@cloudinary/url-gen`](https://github.com/cloudinary/js-url-gen) |
117+
| Run Cloudinary operations as agent tools | [Cloudinary MCP servers](https://github.com/cloudinary/mcp-servers) |
110118

111-
- [Cloudinary Transformation and REST API References](https://cloudinary.com/documentation/cloudinary_references):
112-
Comprehensive references, including syntax and examples for all SDKs.
113-
- [MediaJams.dev](https://mediajams.dev/): Bite-size use-case tutorials written by and for Cloudinary Developers
114-
- [DevJams](https://www.youtube.com/playlist?list=PL8dVGjLA2oMr09amgERARsZyrOz_sPvqw): Cloudinary developer podcasts on
115-
YouTube.
116-
- [Cloudinary Academy](https://training.cloudinary.com/): Free self-paced courses, instructor-led virtual courses, and
117-
on-site courses.
118-
- [Code Explorers and Feature Demos](https://cloudinary.com/documentation/code_explorers_demos_index): A one-stop shop
119-
for all code explorers, Postman collections, and feature demos found in the docs.
120-
- [Cloudinary Roadmap](https://cloudinary.com/roadmap): Your chance to follow, vote, or suggest what Cloudinary should
121-
develop next.
122-
- [Cloudinary Facebook Community](https://www.facebook.com/groups/CloudinaryCommunity): Learn from and offer help to
123-
other Cloudinary developers.
124-
- [Cloudinary Account Registration](https://cloudinary.com/users/register/free): Free Cloudinary account registration.
125-
- [Cloudinary Website](https://cloudinary.com): Learn about Cloudinary's products, partners, customers, pricing, and
126-
more.
119+
## Links
127120

128-
## Licence
121+
- [PHP SDK guide](https://cloudinary.com/documentation/php_integration)
122+
- [Upload](https://cloudinary.com/documentation/php_image_and_video_upload)
123+
- [Asset administration (Admin API)](https://cloudinary.com/documentation/php_asset_administration)
124+
- [Search API](https://cloudinary.com/documentation/search_api)
125+
- [Transformation and API references](https://cloudinary.com/documentation/cloudinary_references)
126+
- [Documentation llms.txt index](https://cloudinary.com/documentation/llms.txt)
127+
- [Package on Packagist](https://packagist.org/packages/cloudinary/cloudinary_php)
129128

130129
Released under the MIT license.

0 commit comments

Comments
 (0)