forked from Silvanite/nova-field-cloudinary
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCloudinaryAdapter.php
More file actions
68 lines (57 loc) · 1.75 KB
/
CloudinaryAdapter.php
File metadata and controls
68 lines (57 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Silvanite\NovaFieldCloudinary\Adapters;
use Cloudinary\Uploader;
use League\Flysystem\Config;
use CarlosOCarvalho\Flysystem\Cloudinary\CloudinaryAdapter as CloudinaryBaseAdapter;
class CloudinaryAdapter extends CloudinaryBaseAdapter
{
/**
* Write a new file using a stream.
*
* @param string $path
* @param resource $resource
* @param Config $config Config object
*
* @return array|false false on failure file meta data on success
*/
public function writeStream($path, $resource, Config $config)
{
$pathinfo = pathinfo($path);
$folder = $pathinfo['dirname'];
$path = $pathinfo['filename'];
$options = ['public_id' => $path, 'resource_type' => 'auto'];
if ($folder != '.') {
$options['folder'] = $folder;
}
$resource_metadata = stream_get_meta_data($resource);
$uploaded_metadata = Uploader::upload($resource_metadata['uri'], $options);
return $uploaded_metadata;
}
/**
* Write a new file.
*
* @param string $path
* @param resource $resource
* @param Config $config Config object
*
* @return array|false false on failure file meta data on success
*/
public function write($path, $resource, Config $config)
{
$path = pathinfo($path)['filename'];
return parent::write($path, $resource, $config);
}
/**
* Get the URL of an image with optional transformation parameters
*
* @param string|array $path
* @return string
*/
public function getUrl($path)
{
if (is_array($path)) {
return cloudinary_url($path['public_id'], $path['options']);
}
return cloudinary_url($path);
}
}