1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Image view helper. |
5
|
|
|
* |
6
|
|
|
* @author Leandro Silva <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @category LosUi |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License |
11
|
|
|
* |
12
|
|
|
* @link http://github.com/LansoWeb/LosUi |
13
|
|
|
* @link http://getbootstrap.com/css/#images |
14
|
|
|
*/ |
15
|
|
|
namespace LosUi\View\Helper; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Image view helper. |
19
|
|
|
* |
20
|
|
|
* @author Leandro Silva <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @category LosUi |
23
|
|
|
* |
24
|
|
|
* @license https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License |
25
|
|
|
* |
26
|
|
|
* @link http://github.com/LansoWeb/LosUi |
27
|
|
|
* @link http://getbootstrap.com/css/#images |
28
|
|
|
*/ |
29
|
|
|
class Image |
30
|
|
|
{ |
31
|
|
|
protected $format = '<img src="%s"%s>'; |
32
|
|
|
|
33
|
|
|
protected $isResponsive = true; |
34
|
|
|
|
35
|
|
|
public function rounded($src) |
36
|
|
|
{ |
37
|
|
|
return $this->render($src, 'img-rounded'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function circle($src) |
41
|
|
|
{ |
42
|
|
|
return $this->render($src, 'img-circle'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function thumbnail($src) |
46
|
|
|
{ |
47
|
|
|
return $this->render($src, 'img-thumbnail'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function render($src, $class = '') |
51
|
|
|
{ |
52
|
|
|
$class = trim($class); |
53
|
|
|
|
54
|
|
|
if ($this->isResponsive) { |
55
|
|
|
if (! empty($class)) { |
56
|
|
|
$class .= ' '; |
57
|
|
|
} |
58
|
|
|
$class .= 'img-responsive'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return sprintf($this->format, $src, ! empty($class) ? " class=\"$class\"" : ''); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setResponsive($responsive) |
65
|
|
|
{ |
66
|
|
|
if (! is_bool($responsive)) { |
67
|
|
|
throw new \InvalidArgumentException('Argument must be a bool value.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->isResponsive = $responsive; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function __invoke($src = '', $class = '') |
76
|
|
|
{ |
77
|
|
|
if ($src) { |
78
|
|
|
return $this->render($src, $class); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|