Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fe05b54
Update Makefile
kvz Nov 25, 2024
a281db6
Fix tests in php 8.2
kvz Nov 25, 2024
c66ae1c
wip
kvz Nov 25, 2024
2427833
Add cli tool
kvz Nov 25, 2024
dc909a4
Create smartcdn-sig.ts
kvz Nov 25, 2024
f04bdfe
Update smartcdn-sig.ts
kvz Nov 25, 2024
b08517a
wip
kvz Nov 25, 2024
dfcae9a
Update smartcdn-sig.ts
kvz Nov 25, 2024
6e1fe06
Update 8-sign-cdn-url.php
kvz Nov 25, 2024
a4245ff
Update Transloadit.php
kvz Nov 25, 2024
fc3d1f5
Create SmartCDNCompareTest.php
kvz Nov 25, 2024
fbe16cc
w
kvz Nov 25, 2024
dc46593
Update ci.yml
kvz Nov 25, 2024
3a09ac5
TEST_NODE_PARITY
kvz Nov 25, 2024
26b4b10
Consistent keys
kvz Nov 25, 2024
4d94f97
Wip
kvz Nov 25, 2024
9123f2e
signedSmartCDNUrl
kvz Nov 25, 2024
7315dde
Wip
kvz Nov 25, 2024
cc0372f
wip
kvz Nov 25, 2024
db180e2
Node parity
kvz Nov 25, 2024
f0287c1
Update Transloadit.php
kvz Nov 25, 2024
a0484c0
Cleanup
kvz Nov 25, 2024
2f1b348
Update config.php
kvz Nov 25, 2024
b34f593
Update TransloaditRequest.php
kvz Nov 25, 2024
c63b80a
Update config.php
kvz Nov 25, 2024
bd9d124
Better parity test
kvz Nov 25, 2024
4c36502
Update config.php
kvz Nov 25, 2024
3db8891
Update SmartCDNNodeParityTest.php
kvz Nov 25, 2024
1ce2b50
Update config.php
kvz Nov 25, 2024
8e57c8e
Wip
kvz Nov 25, 2024
3f97f65
CI fixes
kvz Nov 25, 2024
cd9930d
Update Transloadit.php
kvz Nov 25, 2024
78523ed
Update Transloadit.php
kvz Nov 25, 2024
61b2f64
Wip
kvz Nov 25, 2024
fe2748d
Update TransloaditTest.php
kvz Nov 25, 2024
80da639
Update ci.yml
kvz Nov 25, 2024
92bf6d3
Pass keys
kvz Nov 25, 2024
fc3c138
Cleanup
kvz Nov 25, 2024
ae915a0
Update README.md
kvz Nov 25, 2024
5a3c17a
Update php-sdk.code-workspace
kvz Nov 26, 2024
b25d5d0
Update ci.yml
kvz Nov 26, 2024
61df148
wip
kvz Nov 26, 2024
13ba481
Update ci.yml
kvz Nov 26, 2024
9f10f3a
Unify CI
kvz Nov 26, 2024
759421a
No input
kvz Nov 26, 2024
52d25b5
Input can be an empty string
kvz Nov 26, 2024
1c826e3
Update Transloadit.php
kvz Nov 26, 2024
db193ab
wip
kvz Nov 26, 2024
e37318c
Make empty string param show up in url
kvz Nov 26, 2024
3e75438
Update SmartCDNNodeParityTest.php
kvz Nov 26, 2024
a47e8b0
Harcode urls
kvz Nov 26, 2024
434548a
Merge parity testing into regular suite
kvz Nov 26, 2024
63ad07d
Update TransloaditTest.php
kvz Nov 26, 2024
9134cfd
Retire expireIn
kvz Nov 26, 2024
ab98888
Cleanup
kvz Nov 26, 2024
5d29972
Make expireAtMs a toplevel arg
kvz Nov 26, 2024
0510414
Check both implementation URLs against hardcoded version
kvz Nov 26, 2024
4b29168
Update .github/workflows/ci.yml
kvz Nov 26, 2024
09c9e2d
Update README.md
kvz Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coverage
name: Transloadit PHP SDK CI
on:
push:
branches:
Expand All @@ -10,29 +10,56 @@ on:
jobs:
ci:
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 1
matrix:
php:
- 8.1
- 8.2
dependencies:
- locked
- lowest
- highest
name: PHP ${{ matrix.php }} - ${{ matrix.dependencies }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install tsx
run: npm install -g tsx
- uses: shivammathur/setup-php@v2
# https://github.com/boyney123/github-actions/blob/HEAD/src/actions/setup-php.md
with:
php-version: '8.1'
php-version: ${{ matrix.php }}
tools: php-cs-fixer, phpunit
- uses: ramsey/composer-install@v2
coverage: ${{ matrix.php == '8.1' && matrix.dependencies == 'locked' && 'xdebug' || 'none' }}
- uses: ramsey/composer-install@v3
with:
dependency-versions: locked
dependency-versions: ${{ matrix.dependencies }}
composer-options: '--ignore-platform-reqs'
- name: Test
- name: Test with Coverage
if: matrix.php == '8.1' && matrix.dependencies == 'locked'
run: |
make test-all-coverage
env:
TEST_ACCOUNT_KEY: ${{secrets.TEST_ACCOUNT_KEY}}
TEST_ACCOUNT_SECRET: ${{secrets.TEST_ACCOUNT_SECRET}}
- uses: codecov/codecov-action@v2
TRANSLOADIT_KEY: ${{secrets.TEST_ACCOUNT_KEY}}
TRANSLOADIT_SECRET: ${{secrets.TEST_ACCOUNT_SECRET}}
TEST_NODE_PARITY: 1
- name: Test without Coverage
if: matrix.php != '8.1' || matrix.dependencies != 'locked'
run: |
make test-all
env:
TRANSLOADIT_KEY: ${{secrets.TEST_ACCOUNT_KEY}}
TRANSLOADIT_SECRET: ${{secrets.TEST_ACCOUNT_SECRET}}
TEST_NODE_PARITY: 1
- name: Publish Coverage Report
if: github.event_name == 'pull_request' && matrix.php == '8.1' && matrix.dependencies == 'locked'
uses: lucassabreu/comment-coverage-clover@v0.13.0
with:
files: ./build/logs/clover.xml
fail_ci_if_error: true
target: 90% # Desired coverage percentage
threshold: 2% # Allowed coverage percentage deviation
verbose: true
file: ./build/logs/clover.xml
with-table: true
with-chart: false
42 changes: 0 additions & 42 deletions .github/workflows/tests.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .vscode/php-sdk.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"path": ".."
}
],
"settings": {}
"settings": {
"workbench.colorCustomizations": {
"titleBar.activeForeground": "#232531",
"titleBar.activeBackground": "#8993be"
},
}
}
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

### [main](https://github.com/transloadit/php-sdk/tree/main)

diff: https://github.com/transloadit/php-sdk/compare/3.1.0...main
diff: https://github.com/transloadit/php-sdk/compare/3.2.0...main

### [3.2.0](https://github.com/transloadit/php-sdk/tree/3.2.0)

- Implement `signedSmartCDNUrl`

diff: https://github.com/transloadit/php-sdk/compare/3.1.0...3.2.0

### [3.1.0](https://github.com/transloadit/php-sdk/tree/3.1.0)

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /usr/bin/env bash

export PATH := $(PATH):bin

phpUnit = vendor/phpunit/phpunit/phpunit --colors --verbose --stderr --configuration phpunit.xml $(2) $(1)
phpUnit = vendor/bin/phpunit --colors --verbose --stderr --configuration phpunit.xml $(2) $(1)

.PHONY: install
install:
Expand Down
146 changes: 122 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ require 'vendor/autoload.php';
use transloadit\Transloadit;

$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);

$response = $transloadit->createAssembly([
Expand Down Expand Up @@ -90,8 +90,8 @@ require 'vendor/autoload.php';
use transloadit\Transloadit;

$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);

// Check if this request is a Transloadit redirect_url notification.
Expand Down Expand Up @@ -139,7 +139,10 @@ To integrate Uppy with your PHP backend:
1. Include Uppy in your HTML:

```html
<link href="https://releases.transloadit.com/uppy/v3.3.1/uppy.min.css" rel="stylesheet">
<link
href="https://releases.transloadit.com/uppy/v3.3.1/uppy.min.css"
rel="stylesheet"
/>
<script src="https://releases.transloadit.com/uppy/v3.3.1/uppy.min.js"></script>
```

Expand All @@ -156,8 +159,8 @@ To integrate Uppy with your PHP backend:
})
.use(Uppy.Transloadit, {
params: {
auth: { key: 'YOUR_TRANSLOADIT_KEY' },
template_id: 'YOUR_TEMPLATE_ID',
auth: { key: 'MY_TRANSLOADIT_KEY' },
template_id: 'MY_TEMPLATE_ID',
notify_url: 'https://your-site.com/transloadit_notify.php'
}
})
Expand All @@ -179,26 +182,26 @@ require 'vendor/autoload.php';
use transloadit\Transloadit;

$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);

$response = Transloadit::response();
if ($response) {
// Process the assembly result
$assemblyId = $response->data['assembly_id'];
$assemblyStatus = $response->data['ok'];

// You can store the assembly information in your database
// or perform any other necessary actions here

// Log the response for debugging
error_log('Transloadit Assembly Completed: ' . $assemblyId);
error_log('Assembly Status: ' . ($assemblyStatus ? 'Success' : 'Failed'));

// Optionally, you can write the response to a file
file_put_contents('transloadit_response_' . $assemblyId . '.json', json_encode($response->data));

// Send a 200 OK response to Transloadit
http_response_code(200);
echo 'OK';
Expand All @@ -221,11 +224,11 @@ You can use the `getAssembly` method to get the <dfn>Assembly</dfn> Status.
```php
<?php
require 'vendor/autoload.php';
$assemblyId = 'YOUR_ASSEMBLY_ID';
$assemblyId = 'MY_ASSEMBLY_ID';

$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);

$response = $transloadit->getAssembly($assemblyId);
Expand All @@ -251,14 +254,14 @@ require 'vendor/autoload.php';
use transloadit\Transloadit;

$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);

$response = $transloadit->createAssembly([
'files' => ['/PATH/TO/FILE.jpg'],
'params' => [
'template_id' => 'YOUR_TEMPLATE_ID',
'template_id' => 'MY_TEMPLATE_ID',
],
]);

Expand All @@ -269,12 +272,57 @@ echo '</pre>';

```

<!-- End of generated doc section -->

### Signature Auth
### Signature Auth (Assemblies)

<dfn>Signature Authentication</dfn> is done by the PHP SDK by default internally so you do not need to worry about this :)

### Signature Auth (Smart CDN)

You can use the `signedSmartCDNUrl` method to generate signed URLs for Transloadit's [Smart CDN](https://transloadit.com/services/content-delivery/):

```php
<?php
require 'vendor/autoload.php';

use transloadit\Transloadit;

$transloadit = new Transloadit([
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);

// Basic usage
$url = $transloadit->signedSmartCDNUrl(
'your-workspace-slug',
'your-template-slug',
'avatars/jane.jpg'
);

// Advanced usage with custom parameters and expiry
$url = $transloadit->signedSmartCDNUrl(
'your-workspace-slug',
'your-template-slug',
'avatars/jane.jpg',
['width' => 100, 'height' => 100], // Additional parameters
1732550672867, // Expiry date in milliseconds since epoch
);

echo $url;
```

The generated URL will be in the format:

```
https://{workspace-slug}.tlcdn.com/{template-slug}/{input-field}?{query-params}&sig=sha256:{signature}
```

Note that:

- The URL will expire after the specified time (default: 1 hour)
- All parameters are properly encoded
- The signature is generated using HMAC SHA-256
- Query parameters are sorted alphabetically before signing

## Example

For fully working examples take a look at [`examples/`](https://github.com/transloadit/php-sdk/tree/HEAD/examples).
Expand Down Expand Up @@ -480,7 +528,57 @@ Feel free to fork this project. We will happily merge bug fixes or other small
improvements. For bigger changes you should probably get in touch with us
before you start to avoid not seeing them merged.

## Versioning
### Testing

#### Basic Tests

```bash
make test
```

#### System Tests

System tests require:

1. Valid Transloadit credentials in environment:

```bash
export TRANSLOADIT_KEY='your-auth-key'
export TRANSLOADIT_SECRET='your-auth-secret'
```

Then run:

```bash
make test-all
```

#### Node.js Reference Implementation Parity Assertions

The SDK includes assertions that compare URL signing with our reference Node.js implementation. To run these tests:

1. Requirements:

- Node.js installed
- tsx installed globally (`npm install -g tsx`)

2. Install dependencies:

```bash
npm install -g tsx
```

3. Run the test:

```bash
export TRANSLOADIT_KEY='your-auth-key'
export TRANSLOADIT_SECRET='your-auth-secret'
TEST_NODE_PARITY=1 make test-all
```

CI opts-into `TEST_NODE_PARITY=1`, and you can optionally do this locally as well.

### Versioning

This project implements the Semantic Versioning guidelines.

Expand All @@ -496,7 +594,7 @@ And constructed with the following guidelines:

For more information on SemVer, please visit http://semver.org/.

## Releasing a new version
### Releasing a new version

```bash
# 1. update CHANGELOG.md
Expand Down
Loading