Skip to content

Commit 936bc6d

Browse files
committed
Initial release
1 parent 923cae5 commit 936bc6d

10 files changed

+75
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
All notable changes to `laravel-cloudinary` will be documented in this file.
44

5-
## 0.0.0 - 2021-xx-xx
5+
## 0.0.0 - 2021-05-24
66

7-
- initial release
7+
- Initial release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ wip
1515
You can install the package via composer:
1616

1717
```bash
18-
composer require codebar-ag/laravel-cloudinary
18+
composer require codebar-ag/laravel-flysystem-cloudinary
1919
```
2020

2121
Add the following environment variables to your `.env` file:

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "codebar-ag/laravel-cloudinary",
2+
"name": "codebar-ag/laravel-flysystem-cloudinary",
33
"description": "Cloudinary integration with Laravel",
44
"keywords": [
55
"laravel",
66
"codebar-ag",
77
"cloudinary",
88
"laravel-cloudinary"
99
],
10-
"homepage": "https://github.com/codebar-ag/laravel-cloudinary",
10+
"homepage": "https://github.com/codebar-ag/laravel-flysystem-cloudinary",
1111
"license": "MIT",
1212
"authors": [
1313
{
@@ -39,12 +39,12 @@
3939
},
4040
"autoload": {
4141
"psr-4": {
42-
"CodebarAg\\Cloudinary\\": "src"
42+
"CodebarAg\\FlysystemCloudinary\\": "src"
4343
}
4444
},
4545
"autoload-dev": {
4646
"psr-4": {
47-
"CodebarAg\\Cloudinary\\Tests\\": "tests"
47+
"CodebarAg\\FlysystemCloudinary\\Tests\\": "tests"
4848
}
4949
},
5050
"scripts": {
@@ -59,7 +59,7 @@
5959
"extra": {
6060
"laravel": {
6161
"providers": [
62-
"CodebarAg\\Cloudinary\\CloudinaryServiceProvider"
62+
"CodebarAg\\FlysystemCloudinary\\FlysystemCloudinaryServiceProvider"
6363
]
6464
}
6565
},

config/cloudinary.php renamed to config/flysystem-cloudinary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
|--------------------------------------------------------------------------
77
| Cloudinary Configuration
88
|--------------------------------------------------------------------------
9-
|
109
*/
1110

12-
'folder' => env('CLOUDINARY_FOLDER', null),
11+
// 'folder' => env('CLOUDINARY_FOLDER'),
12+
1313
];

phpunit.xml.dist

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,4 @@
3333
<clover outputFile="build/logs/clover.xml"/>
3434
</report>
3535
</coverage>
36-
<logging>
37-
<junit outputFile="build/report.junit.xml"/>
38-
</logging>
39-
<php>
40-
<env name="TWILIO_URL" value="https://verify.twilio.com/v2/Services"/>
41-
<env name="TWILIO_ACCOUNT_SID" value="ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/>
42-
<env name="TWILIO_AUTH_TOKEN" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/>
43-
<env name="TWILIO_SERVICE_SID" value="VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/>
44-
</php>
4536
</phpunit>

src/Events/CloudinaryResponseLog.php renamed to src/Events/FlysystemCloudinaryResponseLog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace CodebarAg\Cloudinary\Events;
3+
namespace CodebarAg\FlysystemCloudinary\Events;
44

55
use Cloudinary\Api\ApiResponse;
66
use Illuminate\Broadcasting\InteractsWithSockets;
77
use Illuminate\Foundation\Events\Dispatchable;
88
use Illuminate\Queue\SerializesModels;
99

10-
class CloudinaryResponseLog
10+
class FlysystemCloudinaryResponseLog
1111
{
1212
use Dispatchable;
1313
use InteractsWithSockets;

src/CloudinaryAdapter.php renamed to src/FlysystemCloudinaryAdapter.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
22

3-
namespace CodebarAg\Cloudinary;
3+
namespace CodebarAg\FlysystemCloudinary;
44

5+
use Cloudinary\Api\ApiResponse;
56
use Cloudinary\Api\Exception\ApiError;
67
use Cloudinary\Api\Exception\NotFound;
78
use Cloudinary\Cloudinary;
8-
use CodebarAg\Cloudinary\Events\CloudinaryResponseLog;
9+
use CodebarAg\FlysystemCloudinary\Events\FlysystemCloudinaryResponseLog;
910
use Illuminate\Support\Str;
10-
use League\Flysystem\AdapterInterface;
11+
use League\Flysystem\Adapter\AbstractAdapter;
1112
use League\Flysystem\Config;
1213

13-
class CloudinaryAdapter implements AdapterInterface
14+
class FlysystemCloudinaryAdapter extends AbstractAdapter
1415
{
1516
public function __construct(
1617
public Cloudinary $cloudinary,
@@ -49,7 +50,7 @@ public function writeStream($path, $resource, Config $config): array | false
4950
return false;
5051
}
5152

52-
event(new CloudinaryResponseLog($response));
53+
event(new FlysystemCloudinaryResponseLog($response));
5354

5455
[
5556
'bytes' => $bytes,
@@ -90,7 +91,7 @@ public function rename($path, $newpath): bool
9091
return false;
9192
}
9293

93-
event(new CloudinaryResponseLog($response));
94+
event(new FlysystemCloudinaryResponseLog($response));
9495

9596
return true;
9697
}
@@ -104,7 +105,18 @@ public function copy($path, $newpath): bool
104105
/** @inheritdoc */
105106
public function delete($path): bool
106107
{
107-
// TODO: Implement delete() method.
108+
try {
109+
$response = $this
110+
->cloudinary
111+
->uploadApi()
112+
->destroy($path);
113+
} catch (NotFound) {
114+
return false;
115+
}
116+
117+
event(new FlysystemCloudinaryResponseLog($response));
118+
119+
return true;
108120
}
109121

110122
/** @inheritdoc */
@@ -141,7 +153,7 @@ public function has($path): array | bool | null
141153
return false;
142154
}
143155

144-
event(new CloudinaryResponseLog($response));
156+
event(new FlysystemCloudinaryResponseLog($response));
145157

146158
return true;
147159
}
@@ -193,4 +205,23 @@ public function getVisibility($path): array | false
193205
{
194206
// TODO: Implement getVisibility() method.
195207
}
208+
209+
public function getUrl(string $path): string
210+
{
211+
$options = [
212+
'type' => 'upload',
213+
];
214+
215+
/** @var ApiResponse $response */
216+
$response = $this
217+
->cloudinary
218+
->uploadApi()
219+
->explicit($path, $options);
220+
221+
event(new FlysystemCloudinaryResponseLog($response));
222+
223+
['url' => $url] = $response->getArrayCopy();
224+
225+
return $url;
226+
}
196227
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
<?php
22

3-
namespace CodebarAg\Cloudinary;
3+
namespace CodebarAg\FlysystemCloudinary;
44

5+
use Cloudinary\Cloudinary;
56
use Illuminate\Foundation\Application;
67
use Illuminate\Support\Facades\Storage;
78
use League\Flysystem\Filesystem;
89
use Spatie\LaravelPackageTools\Package;
910
use Spatie\LaravelPackageTools\PackageServiceProvider;
1011

11-
class CloudinaryServiceProvider extends PackageServiceProvider
12+
class FlysystemCloudinaryServiceProvider extends PackageServiceProvider
1213
{
1314
public function configurePackage(Package $package): void
1415
{
1516
$package
16-
->name('laravel-cloudinary')
17-
->hasConfigFile('cloudinary');
17+
->name('laravel-flysystem-cloudinary')
18+
->hasConfigFile('flysystem-cloudinary');
1819
}
1920

2021
public function bootingPackage(): void
2122
{
2223
Storage::extend('cloudinary', function (Application $app, array $config) {
23-
$cloudinary = new \Cloudinary\Cloudinary($config);
24+
$cloudinary = new Cloudinary($config);
2425

25-
return new Filesystem(new CloudinaryAdapter($cloudinary));
26+
return new Filesystem(new FlysystemCloudinaryAdapter($cloudinary));
2627
});
2728
}
2829
}

tests/Feature/ExampleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace CodebarAg\FlysystemCloudinary\Tests\Feature;
4+
5+
use CodebarAg\FlysystemCloudinary\Tests\TestCase;
6+
7+
class ExampleTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_does_test()
11+
{
12+
$this->assertTrue(true);
13+
}
14+
}

tests/TestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22

3-
namespace CodebarAg\Cloudinary\Tests;
3+
namespace CodebarAg\FlysystemCloudinary\Tests;
44

5-
use CodebarAg\Cloudinary\CloudinaryServiceProvider;
5+
use CodebarAg\FlysystemCloudinary\FlysystemCloudinaryServiceProvider;
66
use Orchestra\Testbench\TestCase as Orchestra;
77

88
class TestCase extends Orchestra
99
{
1010
protected function getPackageProviders($app): array
1111
{
1212
return [
13-
CloudinaryServiceProvider::class,
13+
FlysystemCloudinaryServiceProvider::class,
1414
];
1515
}
1616

0 commit comments

Comments
 (0)