]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/wikimedia/remex-html/RemexHtml/Tokenizer/PlainAttributes.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / Tokenizer / PlainAttributes.php
1 <?php
2
3 namespace RemexHtml\Tokenizer;
4
5 /**
6  * An Attributes implementation which is a simple array proxy.
7  */
8 class PlainAttributes implements Attributes  {
9         protected $data;
10         protected $attrObjects;
11
12         public function __construct( $data = [] ) {
13                 $this->data = $data;
14         }
15
16         public function merge( Attributes $other ) {
17                 foreach ( $other as $name => $value ) {
18                         if ( !isset( $this[$name] ) ) {
19                                 $this[$name] = $value;
20                         }
21                 }
22         }
23
24         public function offsetExists( $key ) {
25                 return isset( $this->data[$key] );
26         }
27
28         public function offsetGet( $key ) {
29                 return $this->data[$key];
30         }
31
32         public function offsetSet( $key, $value ) {
33                 $this->data[$key] = $value;
34         }
35
36         public function offsetUnset( $key ) {
37                 unset( $this->data[$key] );
38         }
39
40         public function getIterator() {
41                 return new ArrayIterator( $this->data );
42         }
43
44         public function getValues() {
45                 return $this->data;
46         }
47
48         public function getObjects() {
49                 if ( $this->attrObjects === null ) {
50                         $result = [];
51                         foreach ( $this->data as $name => $value ) {
52                                 $result[$name] = new Attribute( $name, null, null, $name, $value );
53                         }
54                         $this->attrObjects = $result;
55                 }
56                 return $this->attrObjects;
57         }
58
59         public function count() {
60                 return count( $this->data );
61         }
62 }