Skip to content

Commit 0e5c744

Browse files
committed
WIP
1 parent 2e995e1 commit 0e5c744

15 files changed

+720
-863
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
4+
#
5+
# Source repository: https://github.com/actions/dependency-review-action
6+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
7+
name: 'Dependency Review'
8+
on: [pull_request]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
dependency-review:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 'Checkout Repository'
18+
uses: actions/checkout@v3
19+
- name: 'Dependency Review'
20+
uses: actions/dependency-review-action@v3

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
name: Check & fix styling
1+
name: Fix PHP code style issues
22

3-
on:
4-
push:
5-
branches:
6-
- styling
3+
on: [push]
74

85
jobs:
9-
php-cs-fixer:
6+
php-code-styling:
107
runs-on: ubuntu-latest
118

129
steps:
@@ -15,10 +12,8 @@ jobs:
1512
with:
1613
ref: ${{ github.head_ref }}
1714

18-
- name: Run PHP CS Fixer
19-
uses: docker://oskarstark/php-cs-fixer-ga
20-
with:
21-
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
15+
- name: Fix PHP code style issues
16+
uses: aglipanci/laravel-pint-action@2.2.0
2217

2318
- name: Commit changes
2419
uses: stefanzweifel/git-auto-commit-action@v4

.github/workflows/phpstan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: PHPStan
22

33
on:
44
push:
5-
paths:
6-
- '**.php'
7-
- 'phpstan.neon.dist'
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
88

99
jobs:
1010
phpstan:

.github/workflows/psalm.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
.idea
22
.php_cs
33
.php_cs.cache
4-
<<<<<<< HEAD
54
.php-cs-fixer.cache
6-
=======
7-
>>>>>>> 960822c (Initial commit)
85
.phpunit.result.cache
96
build
107
composer.lock
@@ -15,7 +12,4 @@ psalm.xml
1512
testbench.yaml
1613
vendor
1714
node_modules
18-
<<<<<<< HEAD
1915
phpstan.neon
20-
=======
21-
>>>>>>> 960822c (Initial commit)

README.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,7 @@ https://res.cloudinary.com/my-cloud-name/image/upload/v1/cat.jpg
9393

9494
### 🪐 How to use with Nova
9595

96-
To customize the name of the stored file, you may use the `storeAs` methods
97-
of the `Image` field:
98-
99-
```php
100-
use Laravel\Nova\Http\Requests\NovaRequest;
101-
use Laravel\Nova\Fields\Image;
102-
103-
Image::make('Image')
104-
->disk('cloudinary')
105-
->storeAs(function (NovaRequest $request) {
106-
return sha1($request->image->getClientOriginalName());
107-
}),
108-
```
96+
We have a package for use with Laravel Nova: [Laravel Flysystem Cloudinary Nova](https://github.com/codebar-ag/laravel-flysystem-cloudinary-nova)
10997

11098
## 🗂 How to use folder prefix
11199

@@ -157,6 +145,26 @@ Keep this in mind because the admin API is rate limited to 500 calls per hour.
157145
The package does check in following sequence:
158146
- `image` ➡️ `raw` ➡️ `video`
159147

148+
## ⚙️ Optional Parameters
149+
150+
Cloudinary has a lot of optional parameters to customize the upload.
151+
You can find all options in the [official documentation](https://cloudinary.com/documentation/image_upload_api_reference#upload_optional_parameters) optional parameters section.
152+
153+
You can pass all parameters as an array to the `put` method:
154+
155+
```php
156+
use Illuminate\Support\Facades\Storage;
157+
158+
Storage::disk('cloudinary')->put('meow', $contents, [
159+
'options' [
160+
'notification_url' => 'https://mysite.example.com/notify_endpoint',
161+
'async' => true,
162+
]
163+
]);
164+
```
165+
166+
`Note: if you find yourself using the same parameters for all requests, you should consider adding them to the config file. (see below)`
167+
160168
## 🔧 Configuration file
161169

162170
You can publish the config file with:
@@ -210,6 +218,21 @@ return [
210218
*/
211219

212220
'secure_url' => (bool) env('CLOUDINARY_SECURE_URL', true),
221+
222+
/*
223+
|--------------------------------------------------------------------------
224+
| Cloudinary Global Upload Options
225+
|--------------------------------------------------------------------------
226+
|
227+
| Here you may specify the upload options that will be applied to all
228+
| your assets. This will be merged with the options that you may
229+
| define in the `Storage::disk('cloudinary')` call.
230+
|
231+
*/
232+
233+
'options' => [
234+
//
235+
],
213236

214237
];
215238
```

config/flysystem-cloudinary.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,18 @@
4141

4242
'secure_url' => (bool) env('CLOUDINARY_SECURE_URL', true),
4343

44+
/*
45+
|--------------------------------------------------------------------------
46+
| Cloudinary Global Upload Options
47+
|--------------------------------------------------------------------------
48+
|
49+
| Here you may specify the upload options that will be applied to all
50+
| your assets. This will be merged with the options that you may
51+
| define in the `Storage::disk('cloudinary')` call.
52+
|
53+
*/
54+
55+
'options' => [
56+
// 'async' => true,
57+
],
4458
];

phpunit.xml.dist

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
backupGlobals="false"
6-
backupStaticAttributes="false"
7-
bootstrap="vendor/autoload.php"
8-
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnFailure="false"
14-
executionOrder="random"
15-
failOnWarning="true"
16-
failOnRisky="true"
17-
failOnEmptyTestSuite="true"
18-
beStrictAboutOutputDuringTests="true"
19-
verbose="true"
20-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" backupGlobals="false"
4+
bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false"
5+
executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true"
6+
beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
217
<testsuites>
228
<testsuite name="codebar Solutions AG Test Suite">
239
<directory>tests</directory>
2410
</testsuite>
2511
</testsuites>
2612
<coverage>
27-
<include>
28-
<directory suffix=".php">./src</directory>
29-
</include>
3013
<report>
3114
<html outputDirectory="build/coverage"/>
3215
<text outputFile="build/coverage.txt"/>
@@ -35,8 +18,13 @@
3518
</coverage>
3619
<php>
3720
<env name="FILESYSTEM_DRIVER" value="cloudinary"/>
38-
<env name="CLOUDINARY_CLOUD_NAME" value="my-cloud-name"/>
39-
<env name="CLOUDINARY_API_KEY" value="my-api-key"/>
40-
<env name="CLOUDINARY_API_SECRET" value="my-api-secret"/>
21+
<env name="CLOUDINARY_CLOUD_NAME" value="cloudinary_cloud_name"/>
22+
<env name="CLOUDINARY_API_KEY" value="cloudinary_api_key"/>
23+
<env name="CLOUDINARY_API_SECRET" value="cloudinary_api_secret"/>
4124
</php>
25+
<source>
26+
<include>
27+
<directory suffix=".php">./src</directory>
28+
</include>
29+
</source>
4230
</phpunit>

src/Cloudinary.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/FlysystemCloudinaryAdapter.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,31 @@ public function __construct(
5353
*/
5454
public function write(string $path, string $contents, Config $config): void
5555
{
56-
$this->meta = $this->upload($path, $contents);
56+
$this->meta = $this->upload($path, $contents, $config);
5757
}
5858

5959
/**
6060
* {@inheritDoc}
6161
*/
6262
public function writeStream(string $path, $resource, Config $config): void
6363
{
64-
$this->meta = $this->upload($path, $resource);
64+
$this->meta = $this->upload($path, $resource, $config);
6565
}
6666

6767
/**
6868
* {@inheritDoc}
6969
*/
7070
public function update($path, $contents, Config $config): array|false
7171
{
72-
return $this->upload($path, $contents);
72+
return $this->upload($path, $contents, $config);
7373
}
7474

7575
/**
7676
* {@inheritDoc}
7777
*/
7878
public function updateStream($path, $resource, Config $config): array|false
7979
{
80-
return $this->upload($path, $resource);
80+
return $this->upload($path, $resource, $config);
8181
}
8282

8383
/**
@@ -87,7 +87,7 @@ public function updateStream($path, $resource, Config $config): array|false
8787
*
8888
* @param string|resource $body
8989
*/
90-
protected function upload(string $path, $body): array|false
90+
protected function upload(string $path, $body, Config $config): array|false
9191
{
9292
if (is_string($body)) {
9393
$tempFile = tmpfile();
@@ -116,6 +116,14 @@ protected function upload(string $path, $body): array|false
116116
$options['upload_preset'] = config('flysystem-cloudinary.upload_preset');
117117
}
118118

119+
if (config('flysystem-cloudinary.options')) {
120+
$options = array_merge($options, config('flysystem-cloudinary.options'));
121+
}
122+
123+
if ($config->get('options')) {
124+
$options = array_merge($options, $config->get('options'));
125+
}
126+
119127
try {
120128
$response = $this
121129
->cloudinary
@@ -176,7 +184,7 @@ public function copy(string $path, string $newpath, Config $config): void
176184
return;
177185
}
178186

179-
$metaUpload = $this->upload($newpath, $metaRead['contents']);
187+
$metaUpload = $this->upload($newpath, $metaRead['contents'], $config);
180188

181189
if ($metaUpload === false) {
182190
$this->copied = false;

src/FlysystemCloudinaryServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace CodebarAg\FlysystemCloudinary;
44

55
use Cloudinary\Cloudinary;
6+
use Illuminate\Filesystem\FilesystemAdapter;
67
use Illuminate\Foundation\Application;
78
use Illuminate\Support\Facades\Storage;
89
use League\Flysystem\Filesystem;
9-
use Illuminate\Filesystem\FilesystemAdapter;
1010
use Spatie\LaravelPackageTools\Package;
1111
use Spatie\LaravelPackageTools\PackageServiceProvider;
1212

@@ -22,7 +22,7 @@ public function configurePackage(Package $package): void
2222
public function bootingPackage(): void
2323
{
2424
Storage::extend('cloudinary', function (Application $app, array $config) {
25-
$adapter = new FlysystemCloudinaryAdapter( new Cloudinary($config));
25+
$adapter = new FlysystemCloudinaryAdapter(new Cloudinary($config));
2626

2727
return new FilesystemAdapter(new Filesystem($adapter, $config), $adapter, $config);
2828
});

0 commit comments

Comments
 (0)