o2system /
html
| 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 Meta |
||||
| 23 | * |
||||
| 24 | * @package O2System\HTML\DOM\Lists |
||||
| 25 | */ |
||||
| 26 | class Meta extends \ArrayIterator |
||||
| 27 | {
|
||||
| 28 | /** |
||||
| 29 | * Meta::$ownerDocument |
||||
| 30 | * |
||||
| 31 | * @var \O2System\Html\Document |
||||
| 32 | */ |
||||
| 33 | public $ownerDocument; |
||||
| 34 | |||||
| 35 | // ------------------------------------------------------------------------ |
||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * Meta::__construct |
||||
| 39 | * |
||||
| 40 | * @param \O2System\Html\Document $ownerDocument |
||||
| 41 | */ |
||||
| 42 | public function __construct(Document $ownerDocument) |
||||
| 43 | {
|
||||
| 44 | $this->ownerDocument =& $ownerDocument; |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | // ------------------------------------------------------------------------ |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * Meta::import |
||||
| 51 | * |
||||
| 52 | * @param \O2System\Html\Dom\Lists\Meta $metaNodes |
||||
| 53 | * |
||||
| 54 | * @return $this |
||||
| 55 | */ |
||||
| 56 | public function import(Meta $metaNodes) |
||||
| 57 | {
|
||||
| 58 | if (is_array($metaNodes = $metaNodes->getArrayCopy())) {
|
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
| 59 | foreach ($metaNodes as $name => $value) {
|
||||
| 60 | $this->offsetSet($name, $value); |
||||
| 61 | } |
||||
| 62 | } |
||||
| 63 | |||||
| 64 | return $this; |
||||
| 65 | } |
||||
| 66 | |||||
| 67 | // ------------------------------------------------------------------------ |
||||
| 68 | |||||
| 69 | /** |
||||
| 70 | * Meta::offsetSet |
||||
| 71 | * |
||||
| 72 | * @param string $name |
||||
| 73 | * @param string $value |
||||
| 74 | */ |
||||
| 75 | public function offsetSet($name, $value) |
||||
| 76 | {
|
||||
| 77 | if ($value instanceof Element) {
|
||||
|
0 ignored issues
–
show
|
|||||
| 78 | parent::offsetSet($name, $value); |
||||
| 79 | } else {
|
||||
| 80 | $meta = $this->ownerDocument->createElement('meta');
|
||||
| 81 | $meta->setAttribute($name, $value); |
||||
| 82 | |||||
| 83 | parent::offsetSet($name, $meta); |
||||
|
0 ignored issues
–
show
$meta of type DOMElement is incompatible with the type string expected by parameter $newval of ArrayIterator::offsetSet().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 84 | } |
||||
| 85 | } |
||||
| 86 | |||||
| 87 | // ------------------------------------------------------------------------ |
||||
| 88 | |||||
| 89 | /** |
||||
| 90 | * Meta::createElement |
||||
| 91 | * |
||||
| 92 | * @param array $attributes |
||||
| 93 | * |
||||
| 94 | * @return \DOMElement |
||||
| 95 | */ |
||||
| 96 | public function createElement(array $attributes) |
||||
| 97 | {
|
||||
| 98 | $meta = $this->ownerDocument->createElement('meta');
|
||||
| 99 | |||||
| 100 | $name = null; |
||||
|
0 ignored issues
–
show
|
|||||
| 101 | foreach ($attributes as $key => $value) {
|
||||
| 102 | $meta->setAttribute($key, $value); |
||||
| 103 | } |
||||
| 104 | |||||
| 105 | $this[] = $meta; |
||||
| 106 | |||||
| 107 | return $meta; |
||||
| 108 | } |
||||
| 109 | } |