1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the PHP-FFmpeg-video-streaming package. |
5
|
|
|
* |
6
|
|
|
* (c) Amin Yazdanpanah <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
namespace Streaming\Clouds; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
use Streaming\Exception\InvalidArgumentException; |
17
|
|
|
use Streaming\File; |
18
|
|
|
|
19
|
|
|
class Cloud |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @param array $clouds |
23
|
|
|
* @param string $tmp_dir |
24
|
|
|
*/ |
25
|
|
|
public static function uploadDirectory(array $clouds, string $tmp_dir): void |
26
|
|
|
{ |
27
|
|
|
if (isset($clouds['cloud'])) { |
28
|
|
|
$clouds = [$clouds]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
foreach ($clouds as $cloud) { |
32
|
|
|
static::transfer($cloud, __FUNCTION__, $tmp_dir); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param array $cloud |
38
|
|
|
* @param string|null $save_to |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public static function download(array $cloud, string $save_to = null): array |
42
|
|
|
{ |
43
|
|
|
$prefix = $cloud['options']['Key'] ?? $cloud['options']['object_name'] ?? $cloud['options']['blob'] ?? uniqid('stream_', true); |
44
|
|
|
list($save_to, $is_tmp) = $save_to ? [$save_to, false] : [File::tmp($prefix), true]; |
45
|
|
|
static::transfer($cloud, __FUNCTION__, $save_to); |
46
|
|
|
|
47
|
|
|
return [$save_to, $is_tmp]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $cloud_c |
52
|
|
|
* @param $method |
53
|
|
|
* @param $path |
54
|
|
|
*/ |
55
|
|
|
private static function transfer(array $cloud_c, string $method, string $path): void |
56
|
|
|
{ |
57
|
|
|
extract($cloud_c); |
58
|
|
|
if (isset($cloud) && $cloud instanceof CloudInterface) { |
59
|
|
|
call_user_func_array([$cloud, $method], [$path, $options ?? []]); |
60
|
|
|
} else { |
61
|
|
|
throw new InvalidArgumentException('The cloud key must be instance of the CloudInterface'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |