1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Code from CambioCMS project |
5
|
|
|
* @link http://code.google.com/p/cambiocms/source/browse/trunk/cms/includes/602_html.image.php |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class Ajde_Resource_FileIcon extends Ajde_Resource |
9
|
|
|
{ |
10
|
|
|
private $_iconCdn = 'http://p.yusukekamiyamane.com/icons/search/fugue/icons/%s.png'; |
11
|
|
|
private $_iconDictionary = [ |
12
|
|
|
'*' => 'document', |
13
|
|
|
'jpg' => 'document-image', |
14
|
|
|
'gif' => 'document-image', |
15
|
|
|
'png' => 'document-image', |
16
|
|
|
'bmp' => 'document-image', |
17
|
|
|
'xls' => 'document-excel', |
18
|
|
|
'xlsx' => 'document-excel', |
19
|
|
|
'ppt' => 'document-powerpoint', |
20
|
|
|
'pptx' => 'document-powerpoint', |
21
|
|
|
'doc' => 'document-word', |
22
|
|
|
'docx' => 'document-word', |
23
|
|
|
'pdf' => 'document-pdf', |
24
|
|
|
'mp3' => 'document-music', |
25
|
|
|
'wav' => 'document-music', |
26
|
|
|
'zip' => 'folder-zipper', |
27
|
|
|
'mpg' => 'film', |
28
|
|
|
'avi' => 'film', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
public function __construct($fileExtension) |
32
|
|
|
{ |
33
|
|
|
$this->set('extension', $fileExtension); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function _($fileExtension) |
37
|
|
|
{ |
38
|
|
|
$tmp = new self($fileExtension); |
39
|
|
|
|
40
|
|
|
return (string) $tmp; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getFilename() |
44
|
|
|
{ |
45
|
|
|
return $this->getLinkUrl(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function __toString() |
49
|
|
|
{ |
50
|
|
|
return $this->getFilename(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function getLinkUrl() |
54
|
|
|
{ |
55
|
|
|
return sprintf($this->_iconCdn, |
56
|
|
|
isset($this->_iconDictionary[$this->getExtension()]) ? $this->_iconDictionary[$this->getExtension()] : $this->_iconDictionary['*']); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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: