Overview

Namespaces

  • MOC
    • Adapter
    • Core
      • Changelog
      • Depending
      • Drive
        • Directory
        • File
      • Error
        • Register
        • Type
      • Journal
      • Proxy
      • Template
      • Xml
    • Extension
      • Excel
      • Flot
      • Mail
      • Pdf
      • Word
      • Xml
      • YUICompressor
      • Zip
    • Generic
      • Common
      • Device
        • Extension
        • Widget
    • Module
      • Database
        • Driver
      • Drive
      • Image
        • Font
      • Installer
      • Network
        • Ftp
          • Directory
          • File
          • Transport
        • Http
        • ParcelTracker
          • Carrier
      • Office
        • Chart
          • Axis
        • Document
          • Excel
            • Cell
              • Format
              • Style
                • Border
                  • Bottom
                  • Left
                  • Right
                  • Top
                • Font
            • Close
            • Page
            • Worksheet
          • Pdf
            • Close
            • Font
            • Page
              • Margin
              • Position
            • Text
          • Xml
            • Close
        • Image
        • Mail
          • Address
          • Content
      • Packer
        • Yui
        • Zip
      • Template
    • Plugin
      • Gateway
      • Repository
      • Shared
  • PHP

Classes

  • Node
  • Parser
  • Token
  • Tokenizer
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * LICENSE (BSD)
  4:  *
  5:  * Copyright (c) 2013, Gerd Christian Kunze
  6:  * All rights reserved.
  7:  *
  8:  * Redistribution and use in source and binary forms, with or without
  9:  * modification, are permitted provided that the following conditions are
 10:  * met:
 11:  *
 12:  *  * Redistributions of source code must retain the above copyright
 13:  *    notice, this list of conditions and the following disclaimer.
 14:  *
 15:  *  * Redistributions in binary form must reproduce the above copyright
 16:  *    notice, this list of conditions and the following disclaimer in the
 17:  *    documentation and/or other materials provided with the distribution.
 18:  *
 19:  *  * Neither the name of Gerd Christian Kunze nor the names of the
 20:  *    contributors may be used to endorse or promote products derived from
 21:  *    this software without specific prior written permission.
 22:  *
 23:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 24:  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 25:  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 26:  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 27:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 28:  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 29:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 30:  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 31:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 32:  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 33:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 34:  *
 35:  * Token
 36:  * 06.01.2013 15:28
 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:      * Get Dependencies
 48:      *
 49:      * @static
 50:      * @return \MOC\Core\Depending
 51:      */
 52:     public static function InterfaceDepending() {
 53:         return Api::Core()->Depending();
 54:     }
 55: 
 56:     /**
 57:      * Get Singleton/Instance
 58:      *
 59:      * @static
 60:      * @return Token
 61:      */
 62:     public static function InterfaceInstance() {
 63:         return new Token();
 64:     }
 65: 
 66:     /**
 67:      * Get Changelog
 68:      *
 69:      * @static
 70:      * @return \MOC\Core\Changelog
 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 TYPE_COMMENT = 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 $PatternTagComment = '!^\![^\[].*?--$!is';
 93: 
 94:     /**
 95:      * @param $Content
 96:      *
 97:      * @return Token
 98:      */
 99:     public function Setup( &$Content ) {
100:         $this->Read( $Content );
101:         return $this;
102:     }
103: 
104:     /**
105:      * @param $Content
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:      * @param $Content
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:      * @return string
151:      */
152:     public function GetName() {
153:         return $this->Name;
154:     }
155: 
156:     /**
157:      * @return int
158:      */
159:     public function GetPosition() {
160:         return $this->Position;
161:     }
162: 
163:     /**
164:      * @return array
165:      */
166:     public function GetAttributeList() {
167:         return $this->AttributeList;
168:     }
169: 
170:     /**
171:      * @return bool
172:      */
173:     public function isOpenTag() {
174:         return $this->Type == self::TYPE_OPEN;
175:     }
176: 
177:     /**
178:      * @return bool
179:      */
180:     public function isCloseTag() {
181:         return $this->Type == self::TYPE_CLOSE;
182:     }
183: 
184:     /**
185:      * @return bool
186:      */
187:     public function isShortTag() {
188:         return $this->Type == self::TYPE_SHORT;
189:     }
190: 
191:     /**
192:      * @return bool
193:      */
194:     public function isCDATATag() {
195:         return $this->Type == self::TYPE_CDATA;
196:     }
197: 
198:     /**
199:      * @return bool
200:      */
201:     public function isCommentTag() {
202:         return $this->Type == self::TYPE_COMMENT;
203:     }
204: 
205: }
206: 
API documentation generated by ApiGen 2.8.0