-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideo.php
More file actions
187 lines (141 loc) · 3.99 KB
/
Copy pathVideo.php
File metadata and controls
187 lines (141 loc) · 3.99 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/main/blob/master/LICENSE
*/
namespace Quid\Main;
use Quid\Base;
// video
// class for an object representing a video with some meta-data
class Video extends Map
{
// config
protected static array $config = [
'name'=>'name',
'date'=>'date',
'description'=>'description',
'absolute'=>'absolute',
'thumbnail'=>'thumbnail',
'html'=>'html'
];
// dynamique
protected ?array $mapAllow = ['overwrite','serialize','clone']; // méthodes permises
// construct
// créer l'objet video, le premier argument doit être un tableau ou une chaîne json
final public function __construct($value,?array $attr=null)
{
$this->makeAttr($attr);
if(is_string($value))
$value = Base\Json::decode($value);
if(!is_array($value))
static::throw('requires','jsonStringOrArray');
$this->overwrite($value);
}
// toString
// affiche l'objet comme string, retourne le html
final public function __toString():string
{
return $this->html();
}
// grab
// retourne une valeur de la map, en utilisation la clé tel que défini dans attr
final public function grab(string $key)
{
$return = null;
$realKey = $this->getAttr($key);
if(is_string($realKey))
$return = $this->get($realKey);
elseif(static::isCallable($realKey))
$return = $realKey($this);
return $return;
}
// name
// retourne le nom de la vidéo
// est facultatif
final public function name():?string
{
$return = null;
$name = $this->grab('name');
if(is_string($name))
$return = $name;
return $return;
}
// date
// retourne la date de la vidéo
// possible de spécifier un format
// est facultatif
final public function date($format=null)
{
$return = null;
$date = $this->grab('date');
if(is_string($date))
{
$date = Base\Datetime::time($date,'sql');
if(is_int($date))
{
$return = $date;
if(is_scalar($format))
$return = Base\Datetime::format($format,$return);
}
}
return $return;
}
// description
// retourne la description de la vidéo
// possible de spécifier une longueur d'excerpt
// est facultatif
final public function description(?int $length=null):?string
{
$return = null;
$description = $this->grab('description');
if(is_string($description))
{
$return = $description;
if(is_int($length))
$return = Base\Str::excerpt($length,$return);
}
return $return;
}
// absolute
// retourne le lien absolue de la vidéo
// est obligatoire
final public function absolute():string
{
$return = null;
$absolute = $this->grab('absolute');
if(is_string($absolute))
$return = Base\Uri::absolute($absolute);
return $return;
}
// thumbnail
// retourne le lien vers le thumbnail de la vidéo
// est facultatif
final public function thumbnail():?string
{
$return = null;
$thumbnail = $this->grab('thumbnail');
if(is_string($thumbnail))
$return = Base\Uri::absolute($thumbnail);
return $return;
}
// html
// retourne le code html de la vidéo
// est obligatoire
final public function html():string
{
$return = null;
$html = $this->grab('html');
if(is_string($html))
$return = $html;
return $return;
}
// input
// retourne la string input si existante
final public function input():?string
{
return $this->get('input');
}
}
?>