1
|
|
|
<?php namespace Arcanesoft\Media\Entities; |
2
|
|
|
|
3
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
4
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
5
|
|
|
use JsonSerializable; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class MediaItem |
9
|
|
|
* |
10
|
|
|
* @package Arcanesoft\Media\Entities |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
abstract class MediaItem implements Arrayable, Jsonable, JsonSerializable |
14
|
|
|
{ |
15
|
|
|
/* ----------------------------------------------------------------- |
16
|
|
|
| Constants |
17
|
|
|
| ----------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
const TYPE_DIRECTORY = 'directory'; |
21
|
|
|
const TYPE_FILE = 'file'; |
22
|
|
|
|
23
|
|
|
/* ----------------------------------------------------------------- |
24
|
|
|
| Properties |
25
|
|
|
| ----------------------------------------------------------------- |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
public $path; |
29
|
|
|
|
30
|
|
|
public $name; |
31
|
|
|
|
32
|
|
|
/* ----------------------------------------------------------------- |
33
|
|
|
| Constructor |
34
|
|
|
| ----------------------------------------------------------------- |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* MediaItem constructor. |
39
|
|
|
* |
40
|
|
|
* @param array $data |
41
|
|
|
* @param string $path |
42
|
|
|
*/ |
43
|
|
|
public function __construct(array $data, string $path) |
44
|
|
|
{ |
45
|
|
|
$this->path = $path; |
46
|
|
|
$this->name = $data['name']; |
47
|
|
|
|
48
|
|
|
$this->load($data, $path); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
abstract protected function load(array $data, string $path); |
52
|
|
|
|
53
|
|
|
/* ----------------------------------------------------------------- |
54
|
|
|
| Getters |
55
|
|
|
| ----------------------------------------------------------------- |
56
|
|
|
*/ |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get the item type. |
60
|
|
|
* |
61
|
|
|
* @return mixed |
62
|
|
|
*/ |
63
|
|
|
abstract public function type(): string; |
64
|
|
|
|
65
|
|
|
/* ----------------------------------------------------------------- |
66
|
|
|
| Other Methods |
67
|
|
|
| ----------------------------------------------------------------- |
68
|
|
|
*/ |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the instance as an array. |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function toArray() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
'type' => $this->type(), |
79
|
|
|
'name' => $this->name, |
80
|
|
|
'path' => $this->path, |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Convert the object to its JSON representation. |
86
|
|
|
* |
87
|
|
|
* @param int $options |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function toJson($options = 0) |
92
|
|
|
{ |
93
|
|
|
return json_encode($this->jsonSerialize(), $options); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get the instance as an array which should be serialized to JSON. |
98
|
|
|
* |
99
|
|
|
* @return array |
100
|
|
|
*/ |
101
|
|
|
public function jsonSerialize() |
102
|
|
|
{ |
103
|
|
|
return $this->toArray(); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|