|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HustleWorks\ChuteLaravel\Services; |
|
4
|
|
|
|
|
5
|
|
|
use HustleWorks\Chute\Contracts\StorageInterface; |
|
6
|
|
|
use Storage; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Storage Service |
|
10
|
|
|
* |
|
11
|
|
|
* @category Services |
|
12
|
|
|
* @package App\Services |
|
13
|
|
|
* @author Don Herre <[email protected]> |
|
14
|
|
|
* @license Proprietary and confidential |
|
15
|
|
|
* @link http://patronart.com |
|
16
|
|
|
*/ |
|
17
|
|
|
class StorageService implements StorageInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Put |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $file |
|
23
|
|
|
* @param string $disk |
|
24
|
|
|
* @param string $path |
|
25
|
|
|
* @param string|null $filename |
|
26
|
|
|
* @return mixed |
|
27
|
|
|
*/ |
|
28
|
|
|
public function put($file, $disk, $path, $filename = null) |
|
29
|
|
|
{ |
|
30
|
|
|
$path = $filename ? "$path/$filename" : $path; |
|
31
|
|
|
Storage::disk($disk)->put($path, $file); |
|
32
|
|
|
|
|
33
|
|
|
return $this->sizeOnDisk($disk, $path); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Size On Disk |
|
38
|
|
|
* |
|
39
|
|
|
* @param $disk |
|
40
|
|
|
* @param $path |
|
41
|
|
|
* @return bool|int |
|
42
|
|
|
*/ |
|
43
|
|
|
public function sizeOnDisk($disk, $path) |
|
44
|
|
|
{ |
|
45
|
|
|
if (Storage::disk($disk)->exists($path)) { |
|
46
|
|
|
return Storage::disk($disk)->size($path); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $disk |
|
56
|
|
|
* @param string $path |
|
57
|
|
|
* @return false|string |
|
58
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function get($disk, $path) |
|
61
|
|
|
{ |
|
62
|
|
|
if (Storage::disk($disk)->exists($path)) { |
|
63
|
|
|
return Storage::disk($disk)->get($path); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Move |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $source_path |
|
73
|
|
|
* @param string $destination_path |
|
74
|
|
|
* @param string|null $source_disk |
|
75
|
|
|
* @param string|null $destination_disk |
|
76
|
|
|
* @return mixed |
|
77
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
|
78
|
|
|
*/ |
|
79
|
|
|
public function move($source_path, $destination_path, $source_disk = null, $destination_disk = null) |
|
80
|
|
|
{ |
|
81
|
|
|
if (!($source_disk and $destination_disk)) { |
|
|
|
|
|
|
82
|
|
|
return Storage::disk($source_disk)->move($source_path, $destination_path); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (Storage::disk($source_disk)->exists($source_path)) { |
|
86
|
|
|
$file_stream = $this->get($source_disk, $source_path); |
|
87
|
|
|
if ($this->put($file_stream, $destination_disk, $destination_path)) { |
|
|
|
|
|
|
88
|
|
|
return $this->delete($source_disk, $source_path); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return false; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function delete($disk, $path) |
|
96
|
|
|
{ |
|
97
|
|
|
return Storage::disk($disk)->delete($path); |
|
98
|
|
|
} |
|
99
|
|
|
} |
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.