1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Ajde_Component_Css extends Ajde_Component_Resource |
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
|
|
|
'action' => 'local', |
16
|
|
|
'filename' => 'public', |
17
|
|
|
'url' => 'remote', |
18
|
|
|
'fontFamily' => 'font', |
19
|
|
|
]; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function process() |
23
|
|
|
{ |
24
|
|
|
switch ($this->_attributeParse()) { |
25
|
|
|
case 'local': |
26
|
|
|
$this->requireResource( |
27
|
|
|
Ajde_Resource_Local::TYPE_STYLESHEET, |
28
|
|
|
$this->attributes['action'], |
29
|
|
|
issetor($this->attributes['format'], null), |
30
|
|
|
issetor($this->attributes['base'], null), |
31
|
|
|
issetor($this->attributes['position'], null), |
32
|
|
|
issetor($this->attributes['arguments'], '') |
33
|
|
|
); |
34
|
|
|
break; |
35
|
|
View Code Duplication |
case 'public': |
|
|
|
|
36
|
|
|
$this->requirePublicResource( |
37
|
|
|
Ajde_Resource_Local::TYPE_STYLESHEET, |
38
|
|
|
$this->attributes['filename'], |
39
|
|
|
issetor($this->attributes['position'], null), |
40
|
|
|
issetor($this->attributes['arguments'], '') |
41
|
|
|
); |
42
|
|
|
break; |
43
|
|
View Code Duplication |
case 'remote': |
|
|
|
|
44
|
|
|
$this->requireRemoteResource( |
45
|
|
|
Ajde_Resource_Local::TYPE_STYLESHEET, |
46
|
|
|
$this->attributes['url'], |
47
|
|
|
issetor($this->attributes['position'], null), |
48
|
|
|
issetor($this->attributes['arguments'], '') |
49
|
|
|
); |
50
|
|
|
break; |
51
|
|
|
case 'font': |
52
|
|
|
$url = Ajde_Resource_GWebFont::getUrl( |
53
|
|
|
$this->attributes['fontFamily'], |
54
|
|
|
issetor($this->attributes['fontWeight'], [400]), |
|
|
|
|
55
|
|
|
issetor($this->attributes['fontSubset'], ['latin']) |
|
|
|
|
56
|
|
|
); |
57
|
|
|
$resource = new Ajde_Resource_Remote(Ajde_Resource::TYPE_STYLESHEET, $url); |
58
|
|
|
$this->getParser()->getDocument()->addResource($resource, |
|
|
|
|
59
|
|
|
Ajde_Document_Format_Html::RESOURCE_POSITION_TOP); |
60
|
|
|
break; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.