1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Ajde_Component_Image extends Ajde_Component |
4
|
|
|
{ |
5
|
|
|
public static function processStatic(Ajde_Template_Parser $parser, $attributes) |
6
|
|
|
{ |
7
|
|
|
$instance = new self($parser, $attributes); |
8
|
|
|
|
9
|
|
|
return $instance->process(); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
protected function _init() |
13
|
|
|
{ |
14
|
|
|
return [ |
15
|
|
|
'base64' => 'base64', |
16
|
|
|
'filename' => 'html', |
17
|
|
|
'output' => 'image', |
18
|
|
|
]; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function process() |
22
|
|
|
{ |
23
|
|
|
switch ($this->_attributeParse()) { |
24
|
|
|
case 'base64': |
25
|
|
|
$image = new Ajde_Resource_Image($this->attributes['filename']); |
26
|
|
|
$image->setWidth(issetor($this->attributes['width'])); |
|
|
|
|
27
|
|
|
$image->setHeight(issetor($this->attributes['height'])); |
|
|
|
|
28
|
|
|
$image->setCrop(Ajde_Component_String::toBoolean(issetor($this->attributes['crop'], true))); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('_core/component:imageBase64')); |
31
|
|
|
$controller->setImage($image); |
|
|
|
|
32
|
|
|
$controller->setWidth(issetor($this->attributes['width'], null)); |
|
|
|
|
33
|
|
|
$controller->setHeight(issetor($this->attributes['height'], null)); |
|
|
|
|
34
|
|
|
$controller->setExtraClass(issetor($this->attributes['class'], '')); |
|
|
|
|
35
|
|
|
|
36
|
|
|
return $controller->invoke(); |
37
|
|
|
break; |
|
|
|
|
38
|
|
|
case 'html': |
39
|
|
|
return self::getImageTag( |
40
|
|
|
$this->attributes['filename'], |
41
|
|
|
issetor($this->attributes['width']), |
42
|
|
|
issetor($this->attributes['height']), |
43
|
|
|
Ajde_Component_String::toBoolean(issetor($this->attributes['crop'], true)), |
44
|
|
|
issetor($this->attributes['class'], ''), |
45
|
|
|
issetor($this->attributes['lazy'], false), |
|
|
|
|
46
|
|
|
issetor($this->attributes['absoluteUrl'], false) |
|
|
|
|
47
|
|
|
); |
48
|
|
|
break; |
|
|
|
|
49
|
|
|
case 'image': |
50
|
|
|
return false; |
51
|
|
|
break; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
// TODO: |
54
|
|
|
throw new Ajde_Component_Exception('Missing required attributes for component call'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function getImageTag( |
58
|
|
|
$filename, |
59
|
|
|
$width = null, |
60
|
|
|
$height = null, |
61
|
|
|
$crop = true, |
62
|
|
|
$class = '', |
63
|
|
|
$lazy = false, |
64
|
|
|
$absoluteUrl = false |
65
|
|
|
) { |
66
|
|
|
$image = new Ajde_Resource_Image($filename); |
67
|
|
|
$image->setWidth($width); |
|
|
|
|
68
|
|
|
$image->setHeight($height); |
|
|
|
|
69
|
|
|
$image->setCrop($crop); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$controller = Ajde_Controller::fromRoute(new Ajde_Core_Route('_core/component:image')); |
72
|
|
|
$controller->setImage($image); |
|
|
|
|
73
|
|
|
$controller->setExtraClass($class); |
|
|
|
|
74
|
|
|
$controller->setLazy($lazy); |
|
|
|
|
75
|
|
|
$controller->setAbsoluteUrl($absoluteUrl); |
|
|
|
|
76
|
|
|
|
77
|
|
|
return $controller->invoke(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: