|
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\FileManager; |
|
18
|
|
|
|
|
19
|
|
|
class CloudManager |
|
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 (!$clouds) { |
|
|
|
|
|
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if (!is_array(current($clouds))) { |
|
32
|
|
|
$clouds = [$clouds]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
foreach ($clouds as $cloud) { |
|
36
|
|
|
static::transfer($cloud, __FUNCTION__, $tmp_dir); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param array $cloud |
|
42
|
|
|
* @param string|null $save_to |
|
43
|
|
|
* @return array |
|
44
|
|
|
* @throws \Streaming\Exception\Exception |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function download(array $cloud, string $save_to = null): array |
|
47
|
|
|
{ |
|
48
|
|
|
list($save_to, $is_tmp) = $save_to ? [$save_to, false] : [FileManager::tmpFile(), true]; |
|
49
|
|
|
static::transfer($cloud, __FUNCTION__, $save_to); |
|
50
|
|
|
|
|
51
|
|
|
return [$save_to, $is_tmp]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param $cloud |
|
56
|
|
|
* @param $method |
|
57
|
|
|
* @param $path |
|
58
|
|
|
*/ |
|
59
|
|
|
private static function transfer($cloud, $method, $path): void |
|
60
|
|
|
{ |
|
61
|
|
|
if (is_array($cloud) && $cloud['cloud'] instanceof CloudInterface) { |
|
62
|
|
|
$options = (isset($cloud['options']) && is_array($cloud['options'])) ? $cloud['options'] : []; |
|
63
|
|
|
call_user_func_array([$cloud['cloud'], $method], [$path, $options]); |
|
64
|
|
|
} else { |
|
65
|
|
|
throw new InvalidArgumentException('You must pass an array of clouds to the save method. |
|
66
|
|
|
and the cloud must be instance of CloudInterface'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.