1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
abstract class Ajde_Component extends Ajde_Object_Standard |
4
|
|
|
{ |
5
|
|
|
const AC_XMLNS = 'ac'; |
6
|
|
|
const AV_XMLNS = 'av'; |
7
|
|
|
|
8
|
|
|
public $attributes = []; |
9
|
|
|
public $innerXml = null; |
10
|
|
|
|
11
|
|
|
protected $_parseRules = []; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var Ajde_Template_Parser |
15
|
|
|
*/ |
16
|
|
|
protected $_parser = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param Ajde_Template_Parser $parser |
20
|
|
|
* @param array $attributes |
21
|
|
|
*/ |
22
|
|
|
public function __construct(Ajde_Template_Parser $parser, $attributes, $innerXml = null) |
23
|
|
|
{ |
24
|
|
|
$this->attributes = $attributes; |
25
|
|
|
$this->innerXml = $innerXml; |
26
|
|
|
$this->_parser = $parser; |
27
|
|
|
$this->_parseRules = $this->_init(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return Ajde_Template_Parser |
32
|
|
|
*/ |
33
|
|
|
public function getParser() |
34
|
|
|
{ |
35
|
|
|
return $this->_parser; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param DOMNode $node |
40
|
|
|
* |
41
|
|
|
* @return Ajde_Component |
42
|
|
|
*/ |
43
|
|
|
public static function fromNode(Ajde_Template_Parser $parser, DOMNode $node) |
44
|
|
|
{ |
45
|
|
|
$componentName = ucfirst(str_replace(self::AC_XMLNS.':', '', $node->nodeName)); |
46
|
|
|
$className = 'Ajde_Component_'.$componentName; |
47
|
|
|
$nodeAttributes = $node->attributes; |
48
|
|
|
$innerXml = $parser->innerXml($node); |
|
|
|
|
49
|
|
|
$attributes = []; |
50
|
|
|
foreach ($nodeAttributes as $attribute) { |
51
|
|
|
$attributes[$attribute->name] = $attribute->value; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return new $className($parser, $attributes, $innerXml); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
abstract public function process(); |
58
|
|
|
|
59
|
|
|
protected function _init() |
60
|
|
|
{ |
61
|
|
|
return []; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function _attributeParse() |
65
|
|
|
{ |
66
|
|
|
foreach ($this->_parseRules as $attributeSet => $rule) { |
67
|
|
|
if (array_key_exists($attributeSet, $this->attributes)) { |
68
|
|
|
return $rule; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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: