1
|
|
|
<?php namespace Arcanedev\EmbedVideo\Entities; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\HtmlString; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Iframe |
7
|
|
|
* |
8
|
|
|
* @package Arcanedev\EmbedVideo\Entities |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class Iframe |
12
|
|
|
{ |
13
|
|
|
/* ----------------------------------------------------------------- |
14
|
|
|
| Properties |
15
|
|
|
| ----------------------------------------------------------------- |
16
|
|
|
*/ |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $pattern; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $queries; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private $replacer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private $attributes; |
36
|
|
|
|
37
|
|
|
/* ----------------------------------------------------------------- |
38
|
|
|
| Constructor |
39
|
|
|
| ----------------------------------------------------------------- |
40
|
|
|
*/ |
41
|
|
|
/** |
42
|
|
|
* Iframe constructor. |
43
|
|
|
* |
44
|
|
|
* @param string $pattern |
45
|
|
|
* @param array $replacer |
46
|
|
|
* @param array $queries |
47
|
|
|
* @param array $attributes |
48
|
|
|
*/ |
49
|
21 |
|
public function __construct($pattern, array $replacer = [], array $queries = [], array $attributes = []) |
50
|
|
|
{ |
51
|
21 |
|
$this->pattern = $pattern; |
52
|
21 |
|
$this->replacer = $replacer; |
53
|
21 |
|
$this->queries = $queries; |
54
|
21 |
|
$this->attributes = $attributes; |
55
|
21 |
|
} |
56
|
|
|
|
57
|
|
|
/* ----------------------------------------------------------------- |
58
|
|
|
| Getters & Setters |
59
|
|
|
| ----------------------------------------------------------------- |
60
|
|
|
*/ |
61
|
|
|
/** |
62
|
|
|
* Get iframe src value. |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
21 |
|
public function src() |
67
|
|
|
{ |
68
|
21 |
|
$url = str_replace( |
69
|
21 |
|
array_keys($this->replacer), |
70
|
21 |
|
array_values($this->replacer), |
71
|
21 |
|
$this->pattern |
72
|
7 |
|
); |
73
|
|
|
|
74
|
21 |
|
return $url.'?'.http_build_query($this->queries); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/* ----------------------------------------------------------------- |
78
|
|
|
| Main Methods |
79
|
|
|
| ----------------------------------------------------------------- |
80
|
|
|
*/ |
81
|
|
|
/** |
82
|
|
|
* Render the iframe. |
83
|
|
|
* |
84
|
|
|
* @return \Illuminate\Support\HtmlString |
85
|
|
|
*/ |
86
|
21 |
|
public function render() |
87
|
|
|
{ |
88
|
21 |
|
return new HtmlString('<iframe src="'.$this->src().'"></iframe>'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Convert the object to string. |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function __toString() |
97
|
|
|
{ |
98
|
|
|
return $this->render()->toHtml(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|