Skip to content

Commit eec01f2

Browse files
authored
Merge pull request #196 from uploadcare/develop
Update to REST API 0.7 and lib version to 4.0
2 parents 24a275e + af0ad62 commit eec01f2

File tree

185 files changed

+3726
-3315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+3726
-3315
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: true
1010
matrix:
11-
php-versions: [ "7.4", "8.0" ]
11+
php-versions: [ "7.4", "8.0", "8.1" ]
1212
phpunit-versions: [ "9" ]
1313
steps:
1414
- uses: actions/checkout@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/tests/.env.local
66
/psalm.phar
77
.phpunit.result.cache
8+
.php-cs-fixer.cache

.php_cs.dist renamed to .php-cs-fixer.dist.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'single_import_per_statement' => false,
2525
'concat_space' => ['spacing' => 'one'],
2626
'array_syntax' => ['syntax' => 'short'],
27-
'no_superfluous_phpdoc_tags' => false,
27+
'no_superfluous_phpdoc_tags' => true,
2828
'blank_line_after_opening_tag' => false,
2929
'linebreak_after_opening_tag' => false,
3030
'global_namespace_import' => [
@@ -34,11 +34,19 @@
3434
],
3535
'phpdoc_separation' => true,
3636
'yoda_style' => false,
37+
'native_function_invocation' => [
38+
'exclude' => [],
39+
'include' => ['@internal'],
40+
'scope' => 'all',
41+
'strict' => false,
42+
],
43+
'types_spaces' => ['space' => 'single'],
3744
];
3845

3946
$config = new PhpCsFixer\Config();
4047

4148
return $config
4249
->setRiskyAllowed(true)
4350
->setRules($rules)
44-
->setFinder($finder);
51+
->setFinder($finder)
52+
;

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ The format is based now on [Keep a
55
Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to
66
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [4.0.0]
9+
### Removed
10+
- PHP 7.1 support (now minimal version is 7.4, PHP 8.0 is also supported)
11+
- `FileInfoInterface::getImageInfo()`, `FileInfoInterface::getVideoInfo()`, `FileInfoInterface::getRekognitionInfo()` — see `FileInfoInterface::getContentInfo()`
12+
### Added
13+
- Support for [REST API 0.7](https://uploadcare.com/api-refs/rest-api/v0.7.0/)
14+
- `FileInfoInterface::getContentInfo()`: returns `ContentInfoInterface` with `getMime()` (information about MimeType), `getImage` (`ImageInfoInterface` in case of an image) and `getVideo` (`VideoInfoInterface` in case of a video) methods;
15+
- `FileInfoInterface::getMetadata()` method returns file associated metadata array-accessible object;
16+
- Addons (`AddonsApiInterface`): execute and check status of an add-on application:
17+
- `requestAwsRecognition($id)`: execute AWS Rekognition Add-On for a given target to detect labels in an image
18+
- `checkAwsRecognition(string $id)`: check the status of an Add-On execution request that had been started using the Execute Add-On operation
19+
- `requestAntivirusScan($id, bool $purge = false)`: execute ClamAV virus checking Add-On for a given target
20+
- `checkAntivirusScan(string $id)`: check the status of an Add-On execution request that had been started using the Execute Add-On operation
21+
- `requestRemoveBackground($id, ?RemoveBackgroundRequestInterface $backgroundRequest = null)`: execute remove.bg background image removal Add-On for a given target
22+
- `checkRemoveBackground(string $id)`: check the status of an Add-On execution request that had been started using the Execute Add-On operation
23+
- Application data `FileInfoInterface::getAppdata()`: method returns `AppDataInterface` with information about addon-applications and associated data:
24+
- `AwsRecognitionLabelsInterface`: information from previously executed `requestAwsRecognition` of image;
25+
- `ClamAvVirusScanInterface`: information from [ClamAV](https://www.clamav.net/) antivirus scan
26+
- `RemoveBgInterface`: data from previously executed `requestRemoveBackground` [remove.bg](https://remove.bg/) addon
27+
828
## [3.2.4]
929
### Added
1030
- Allow to use guzzlehttp/psr7:^2.

README.md

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Uploadcare PHP integration handles uploads and further operations with files by
1414
* [Usage](#usage)
1515
* [Uploading files](#uploading-files)
1616
* [File operations](#file-operations)
17+
* [Addons operations](#addons-operations)
1718
* [Group operations](#group-operations)
1819
* [Project operations](#project-operations)
1920
* [Webhooks](#webhooks)
@@ -24,7 +25,7 @@ Uploadcare PHP integration handles uploads and further operations with files by
2425

2526
## Requirements
2627

27-
- `php7.1+`
28+
- `php7.4+` or `php8.0+`
2829
- `php-curl`
2930
- `php-json`
3031

@@ -36,7 +37,7 @@ Prior to installing `uploadcare-php` get the [Composer](https://getcomposer.org)
3637

3738
```json
3839
"require": {
39-
"uploadcare/uploadcare-php": "^3.0"
40+
"uploadcare/uploadcare-php": "^4.0"
4041
}
4142
```
4243

@@ -114,21 +115,18 @@ $configuration = \Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'
114115
$uploader = (new \Uploadcare\Api($configuration))->uploader();
115116
```
116117

117-
First of all, files can be uploaded **from URL**. The following code returns an instance of `Uploadcare\File`,
118+
First of all, files can be uploaded **from URL**. The following code returns a token to check file upload status,
118119

119120
```php
120121
$url = 'https://httpbin.org/image/jpeg';
121-
$result = $uploader->fromUrl($url, 'image/jpeg'); // If success, $result will contain instance of Uploadcare\File class (see below)
122-
123-
echo \sprintf("File from URL %s uploaded successfully \n", $url);
124-
echo \sprintf("Uploaded file ID: %s\n", $result);
122+
$result = $uploader->fromUrl($url, 'image/jpeg'); // If success, $result will be string to check upload status (see below)
125123
```
126124

127125
Another way of uploading files is by using **a path**,
128126

129127
```php
130128
$path = __DIR__ . '/squirrel.jpg';
131-
$result = $uploader->fromPath($path, 'image/jpeg'); // In success $result will contains uploaded Uploadcare\File class
129+
$result = $uploader->fromPath($path, 'image/jpeg'); // In success $result will contain uploaded Uploadcare\File class
132130
```
133131

134132
It’s also relevant when using file pointers,
@@ -145,6 +143,25 @@ $path = __DIR__ . '/squirrel.jpg';
145143
$result = $uploader->fromContent(\file_get_contents($path), 'image/jpeg');
146144
```
147145

146+
Check upload file status:
147+
148+
```php
149+
$url = 'https://httpbin.org/image/jpeg';
150+
$result = $uploader->fromUrl($url, 'image/jpeg');
151+
$status = $uploader->checkStatus($result); // Will be 'waiting', 'progress', 'success', 'error' or 'unknown'
152+
```
153+
154+
#### File metadata
155+
156+
Every upload method can set a [file metadata](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-metadata). For example:
157+
158+
```php
159+
$path = __DIR__ . '/squirrel.jpg';
160+
$result = $uploader->fromPath($path, 'image/jpeg', null, '1', ['type' => 'animal', 'kind' => 'squirrel']);
161+
```
162+
163+
You will see this values in a `metadata` object of `Uploadcare\File` response.
164+
148165
### Multipart upload
149166

150167
If you have a large file (more than 100Mb / 10485760 bytes), the uploader will automatically process it with a [multipart upload](https://uploadcare.com/api-refs/upload-api/#operation/multipartFileUploadStart). It'll take more time to upload, and also we don’t recommend it for a web environment.
@@ -205,7 +222,7 @@ After that, you can access to file operation methods:
205222
- `$makePublic` — `true` to make copied files available via public links, `false` to reverse the behavior.
206223
- `$pattern` — The parameter is used to specify file names Uploadcare passes to a custom storage. In case when the parameter is omitted, we use a pattern of your custom storage. Use any combination of allowed values.
207224

208-
See the [API documentation](https://uploadcare.com/api-refs/rest-api/v0.6.0/#tag/File) for more details.
225+
See the [API documentation](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File) for more details.
209226

210227
### `Uploadcare\FileCollection` class
211228

@@ -226,6 +243,74 @@ This class implements `FileInfoInterface` and has additional methods for file op
226243

227244
As you can see, additional methods help you to call API methods without direct API calls.
228245

246+
## Addons operations
247+
248+
Uploadcare provide a few additional operations with images.
249+
250+
### [Object Recognition](https://uploadcare.com/docs/intelligence/object-recognition/)
251+
252+
To call object recognition from library:
253+
254+
```php
255+
$configuration = \Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY']);
256+
257+
$api = new \Uploadcare\Api($configuration);
258+
/** @var \Uploadcare\Interfaces\File\FileInfoInterface $file */
259+
$file = $api->file()->listFiles()->getResults()->first();
260+
261+
# Request recognition, get token to check status
262+
$token = $api->addons()->requestAwsRecognition($file);
263+
while (($status = $api->addons()->checkAwsRecognition($token)) !== 'done') {
264+
\usleep(1000);
265+
if ($status === 'error') {
266+
throw new \Exception('Error in process');
267+
}
268+
}
269+
270+
$recognitionData = $api->file()->fileInfo($file->getUuid())->getAppdata()->getAwsRekognitionDetectLabels(); // Instance of \Uploadcare\Interfaces\File\AppData\AwsRecognitionLabelsInterface
271+
```
272+
273+
### [Remove background](https://uploadcare.com/docs/remove-bg/)
274+
275+
Remove background from image:
276+
277+
```php
278+
$configuration = \Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY']);
279+
280+
$api = new \Uploadcare\Api($configuration);
281+
/** @var \Uploadcare\Interfaces\File\FileInfoInterface $file */
282+
$file = $api->file()->listFiles()->getResults()->first();
283+
284+
# Request recognition, get token to check status
285+
$token = $api->addons()->requestRemoveBackground($file);
286+
while (($status = $api->addons()->checkRemoveBackground($token)) !== 'done') {
287+
\usleep(1000);
288+
if ($status === 'error') {
289+
throw new \Exception('Error in process');
290+
}
291+
}
292+
293+
$removeBackgroundData = $api->file()->fileInfo($file->getUuid())->getAppdata()->getRemoveBg(); // Instance of \Uploadcare\Interfaces\File\AppData\RemoveBgInterface
294+
```
295+
296+
### [Antivirus scan](https://www.clamav.net/)
297+
298+
```php
299+
$configuration = \Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY']);
300+
$api = new \Uploadcare\Api($configuration);
301+
/** @var \Uploadcare\Interfaces\File\FileInfoInterface $file */
302+
$file = $api->file()->listFiles()->getResults()->first();
303+
304+
# Request antivirus scan and get token:
305+
$token = $api->addons()->requestAntivirusScan($file);
306+
while (($status = $api->addons()->checkAntivirusScan($token)) !== 'done') {
307+
\usleep(1000);
308+
if ($status === 'error') {
309+
throw new \Exception('Error in process');
310+
}
311+
}
312+
```
313+
229314
## Group operations
230315

231316
For any type of group operation you need to create an `Uploadcare\Api` instance with a configuration object and call the `group()` method:
@@ -318,7 +403,7 @@ The default arguments and examples are:
318403
- `$store = true` — The conversion results will go to your default storage.
319404
- `$pageNumber = 1` — Specifies pages to convert in multi-page documents.
320405

321-
After that, you can covert your file:
406+
After that, you can convert your file:
322407

323408
```php
324409
$config = \Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY']);

composer.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@
2424
},
2525
"minimum-stability": "stable",
2626
"require": {
27-
"php": ">=7.1 || >=8.0",
27+
"php": ">=7.4 || >=8.0",
2828
"ext-curl": "*",
2929
"ext-json": "*",
30-
"guzzlehttp/guzzle": "^6.5||^7",
31-
"guzzlehttp/psr7": "^1.6||^2",
32-
"symfony/polyfill-uuid": "^1.17"
30+
"guzzlehttp/guzzle": "^7.5",
31+
"guzzlehttp/psr7": "^2.4",
32+
"symfony/polyfill-php80": "^1.26",
33+
"symfony/polyfill-uuid": "^1.26"
3334
},
3435
"require-dev": {
35-
"fakerphp/faker": "^1.9",
36-
"friendsofphp/php-cs-fixer": "^2.16",
37-
"phpunit/phpunit": "^5.7||^7||^9",
38-
"symfony/dotenv": "^3.4",
39-
"symfony/var-dumper": "^3.4||^5",
40-
"vimeo/psalm": "^4.7"
36+
"fakerphp/faker": "^1.20",
37+
"friendsofphp/php-cs-fixer": "^3.11",
38+
"phpunit/phpunit": "^9.5",
39+
"symfony/dotenv": "^5.4",
40+
"symfony/var-dumper": "^5.4",
41+
"vimeo/psalm": "^4.27"
4142
},
4243
"autoload": {
4344
"psr-4": {
@@ -54,6 +55,9 @@
5455
"preferred-install": {
5556
"*": "dist"
5657
},
57-
"sort-packages": true
58+
"sort-packages": true,
59+
"allow-plugins": {
60+
"composer/package-versions-deprecated": true
61+
}
5862
}
5963
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
FROM composer:latest as composer
2-
FROM php:7.1-fpm-alpine as php
2+
FROM php:7.4-fpm-alpine as php
33

44
RUN apk add --no-cache git
55

66
RUN set -xe \
77
&& apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \
8-
&& pecl install xdebug-2.9.8 \
8+
&& pecl install xdebug \
99
&& docker-php-ext-enable xdebug \
1010
&& apk del --no-network .phpize-deps
1111

phpunit.xml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
backupGlobals="false"
6-
verbose="true">
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
backupGlobals="false" verbose="true">
7+
<coverage processUncoveredFiles="true">
8+
<include>
9+
<directory suffix=".php">src</directory>
10+
</include>
11+
</coverage>
712
<testsuite name="default">
813
<directory suffix="Test.php">tests</directory>
914
</testsuite>
10-
11-
<filter>
12-
<whitelist processUncoveredFilesFromWhitelist="true">
13-
<directory suffix=".php">src</directory>
14-
</whitelist>
15-
</filter>
1615
</phpunit>

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="3"
3+
errorLevel="2"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"

0 commit comments

Comments
 (0)