1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: namespace MOC\Core\Xml;
39: use MOC\Api;
40: use MOC\Generic\Device\Core;
41:
42: 43: 44:
45: class Token implements Core {
46: 47: 48: 49: 50: 51:
52: public static function InterfaceDepending() {
53: return Api::Core()->Depending();
54: }
55:
56: 57: 58: 59: 60: 61:
62: public static function InterfaceInstance() {
63: return new Token();
64: }
65:
66: 67: 68: 69: 70: 71:
72: public static function InterfaceChangelog() {
73: return Api::Core()->Changelog()->Create( __CLASS__ );
74: }
75:
76:
77: const TYPE_OPEN = 1;
78: const TYPE_CLOSE = 2;
79: const TYPE_SHORT = 3;
80: const TYPE_CDATA = 4;
81: const = 5;
82:
83: private $Name = '';
84: private $AttributeList = array();
85: private $Position = 0;
86: private $Type = 0;
87:
88: private $PatternTagOpen = '!^[^\!/].*?[^/]$!is';
89: private $PatternTagClose = '!^/.*?!is';
90: private $PatternTagShort = '!^[^\!].*?/$!is';
91: private $PatternTagCDATA = '!^\!\[CDATA.*?\]\]$!is';
92: private = '!^\![^\[].*?--$!is';
93:
94: 95: 96: 97: 98:
99: public function Setup( &$Content ) {
100: $this->Read( $Content );
101: return $this;
102: }
103:
104: 105: 106:
107: private function Read( &$Content ) {
108: $this->Position = $Content[1];
109:
110: $Token = explode(' ', $Content[0] );
111: $this->Name = preg_replace( '!/$!is', '', array_shift( $Token ) );
112:
113: preg_match_all( '![\w]+="[^"]*?"!is', $Content[0], $Matches );
114: $Token = $Matches[0];
115:
116: $Attribute = array();
117: while( null !== ( $AttributeString = array_pop( $Token ) ) ) {
118: if( $AttributeString != '/' ) {
119: preg_match( '!(.*?)="(.*?)(?=")!is', $AttributeString, $Attribute );
120: if( count( $Attribute ) == 3 ) {
121: $this->AttributeList[$Attribute[1]] = $Attribute[2];
122: }
123: }
124: }
125: $this->ReadType( $Content[0] );
126: }
127:
128: 129: 130:
131: private function ReadType( &$Content ) {
132: if( preg_match( $this->PatternTagOpen, $Content ) ) {
133: $this->Type = self::TYPE_OPEN;
134: } else
135: if( preg_match( $this->PatternTagClose, $Content ) ) {
136: $this->Type = self::TYPE_CLOSE;
137: } else
138: if( preg_match( $this->PatternTagShort, $Content ) ) {
139: $this->Type = self::TYPE_SHORT;
140: } else
141: if( preg_match( $this->PatternTagCDATA, $Content ) ) {
142: $this->Type = self::TYPE_CDATA;
143: } else
144: if( preg_match( $this->PatternTagComment, $Content ) ) {
145: $this->Type = self::TYPE_COMMENT;
146: }
147: }
148:
149: 150: 151:
152: public function GetName() {
153: return $this->Name;
154: }
155:
156: 157: 158:
159: public function GetPosition() {
160: return $this->Position;
161: }
162:
163: 164: 165:
166: public function GetAttributeList() {
167: return $this->AttributeList;
168: }
169:
170: 171: 172:
173: public function isOpenTag() {
174: return $this->Type == self::TYPE_OPEN;
175: }
176:
177: 178: 179:
180: public function isCloseTag() {
181: return $this->Type == self::TYPE_CLOSE;
182: }
183:
184: 185: 186:
187: public function isShortTag() {
188: return $this->Type == self::TYPE_SHORT;
189: }
190:
191: 192: 193:
194: public function isCDATATag() {
195: return $this->Type == self::TYPE_CDATA;
196: }
197:
198: 199: 200:
201: public function () {
202: return $this->Type == self::TYPE_COMMENT;
203: }
204:
205: }
206: