1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Html\Dom\Lists; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Html\Document; |
19
|
|
|
use O2System\Html\Dom\Element; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Asset |
23
|
|
|
* |
24
|
|
|
* @package O2System\HTML\DOM\Lists |
25
|
|
|
*/ |
26
|
|
|
class Asset extends \ArrayIterator |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Asset::$element |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $element = 'link'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Asset::$ownerDocument |
37
|
|
|
* |
38
|
|
|
* @var \O2System\Html\Document |
39
|
|
|
*/ |
40
|
|
|
public $ownerDocument; |
41
|
|
|
|
42
|
|
|
// ------------------------------------------------------------------------ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Asset::__construct |
46
|
|
|
* |
47
|
|
|
* @param \O2System\Html\Document $ownerDocument |
48
|
|
|
*/ |
49
|
|
|
public function __construct(Document $ownerDocument) |
50
|
|
|
{ |
51
|
|
|
$this->ownerDocument =& $ownerDocument; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// ------------------------------------------------------------------------ |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Asset::import |
58
|
|
|
* |
59
|
|
|
* @param \O2System\Html\Dom\Lists\Asset $assetNodes |
60
|
|
|
* |
61
|
|
|
* @return static |
62
|
|
|
*/ |
63
|
|
|
public function import(Asset $assetNodes) |
64
|
|
|
{ |
65
|
|
|
if (is_array($assetNodes = $assetNodes->getArrayCopy())) { |
|
|
|
|
66
|
|
|
foreach ($assetNodes as $name => $value) { |
67
|
|
|
$this->offsetSet($name, $value); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// ------------------------------------------------------------------------ |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Asset::offsetSet |
78
|
|
|
* |
79
|
|
|
* @param string $name |
80
|
|
|
* @param string $value |
81
|
|
|
*/ |
82
|
|
|
public function offsetSet($name, $value) |
83
|
|
|
{ |
84
|
|
|
if ($value instanceof Element) { |
|
|
|
|
85
|
|
|
parent::offsetSet($name, $value); |
86
|
|
|
} else { |
87
|
|
|
$meta = $this->ownerDocument->createElement($this->element); |
88
|
|
|
$meta->setAttribute($name, $value); |
89
|
|
|
|
90
|
|
|
parent::offsetSet($name, $meta); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// ------------------------------------------------------------------------ |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Asset::createElement |
98
|
|
|
* |
99
|
|
|
* @param array $attributes |
100
|
|
|
* |
101
|
|
|
* @return \DOMElement |
102
|
|
|
*/ |
103
|
|
|
public function createElement(array $attributes) |
104
|
|
|
{ |
105
|
|
|
$element = $this->ownerDocument->createElement($this->element); |
106
|
|
|
|
107
|
|
|
$name = null; |
|
|
|
|
108
|
|
|
foreach ($attributes as $key => $value) { |
109
|
|
|
$element->setAttribute($key, $value); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$this[] = $element; |
113
|
|
|
|
114
|
|
|
return $element; |
115
|
|
|
} |
116
|
|
|
} |