PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/Upload/DoYouHaoBaby/LibPHP/App/Package/Template/TemplateObj_.php

http://dyhb-frame.googlecode.com/
PHP | 216 lines | 190 code | 24 blank | 2 comment | 12 complexity | 44bb5efcb371455d62aa07fa1772535e MD5 | raw file
  1. <?php
  2. /* [DoYouHaoBaby!] (C)Dianniu From 2010.
  3. ?????($)*/
  4. !defined('DYHB_PATH') && exit;
  5. class TemplateObj{
  6. private $_oTemplate;
  7. private $_oParser;
  8. private $_oCompiler;
  9. private $_sSourceStream;
  10. private $_sCompiledStream;
  11. public $_arrChildTemplateObj=array();
  12. private $_sTemplateFile='';
  13. private $_nStartLine=0;
  14. private $_nEndLine=0;
  15. private $_nStartByte=0;
  16. private $_nEndByte=0;
  17. private $_nStartByteInLine=0;
  18. private $_nEndByteInLine=0;
  19. protected $_arrGet=array();
  20. protected $_arrSet=array();
  21. const LOCAL_MIN=1;
  22. const LOCAL_IN=1;
  23. const LOCAL_OUT=2;
  24. const LOCAL_FRONT=3;
  25. const LOCAL_BEHIND=4;
  26. const LOCAL_MAX=1;
  27. public function __construct($sSourceStream){
  28. $this->setSource($sSourceStream);
  29. $this->setCompiled($sSourceStream);
  30. $this->_arrGet['getTemplateFile']=&$this->_sTemplateFile;
  31. $this->_arrGet['getStartLine']=&$this->_nStartLine;
  32. $this->_arrGet['getEndLine']=&$this->_nEndLine;
  33. $this->_arrGet['getStartByte']=&$this->_nStartByte;
  34. $this->_arrGet['getEndByte']=&$this->_nEndByte;
  35. $this->_arrGet['getStartByteInLine']=&$this->_nStartByteInLine;
  36. $this->_arrGet['getEndByteInLine']=&$this->_nEndByteInLine;
  37. $this->_arrSet['setTemplateFile']=&$this->_sTemplateFile;
  38. $this->_arrSet['setStartLine']=&$this->_nStartLine;
  39. $this->_arrSet['setEndLine']=&$this->_nEndLine;
  40. $this->_arrSet['setStartByte']=&$this->_nStartByte;
  41. $this->_arrSet['setEndByte']=&$this->_nEndByte;
  42. $this->_arrSet['setStartByteInLine']=&$this->_nStartByteInLine;
  43. $this->_arrSet['setEndByteInLine']=&$this->_nEndByteInLine;
  44. }
  45. public function setTemplate(Template $oTempate){
  46. $oOldVal=$this->_oTemplate;
  47. $this->_oTemplate=$oTempate;
  48. return $oOldVal;
  49. }
  50. public function getTemplate(){
  51. return $this->_oTemplate;
  52. }
  53. public function setParser($oParser){
  54. $oOldVar=$this->_oParser;
  55. $this->_oParser=$oParser;
  56. return $oOldVar;
  57. }
  58. public function getParser(){
  59. return $this->_oParser;
  60. }
  61. public function setCompiler($Compiler){
  62. if(is_string($Compiler)){
  63. $oCompiler=Dyhb::instance($Compiler);
  64. }else{
  65. $oCompiler=$Compiler;
  66. }
  67. $oOldVar=$this->_oCompiler;
  68. $this->_oCompiler=$oCompiler;
  69. return $oOldVar;
  70. }
  71. public function getCompiler(){
  72. return $this->_oCompiler;
  73. }
  74. public function getSource(){
  75. return $this->_sSourceStream;
  76. }
  77. protected function setSource($sSource){
  78. A::STRING($sSource);
  79. $sOldValue=$this->_sSourceStream;
  80. $this->_sSourceStream=$sSource;
  81. return $sOldValue;
  82. }
  83. public function getCompiled(){
  84. return $this->_sCompiledStream;
  85. }
  86. public function setCompiled($sStream){
  87. A::STRING($sStream);
  88. $sOldVar=$this->_sCompiledStream;
  89. $this->_sCompiledStream=$sStream;
  90. return $sOldVar;
  91. }
  92. public function __call($sMethod, $arrArgs){
  93. if(isset($this->_arrGet[$sMethod])){return $this->_arrGet[$sMethod];}// ????
  94. if(isset($this->_arrSet[$sMethod])){// ????
  95. A::ASSERT_(isset($arrArgs[0]),G::L('??????','Dyhb'));
  96. $sOldValue=$this->_arrSet[$sMethod];
  97. $this->_arrSet[$sMethod]=$arrArgs[0];
  98. return $sOldValue;
  99. }
  100. G::E(G::L('??????????%s','Dyhb',null,$sMethod));
  101. }
  102. public function compareLocal(TemplateObj $oTemplateObj){
  103. if($oTemplateObj->getEndByte()<=$this->getStartByte()){return self::LOCAL_FRONT;}// ?
  104. if($oTemplateObj->getStartByte()>=$this->getEndByte()){return self::LOCAL_BEHIND;}// ?
  105. if($oTemplateObj->getStartByte()>=$this->getStartByte()){return self::LOCAL_IN;}// ?
  106. if($oTemplateObj->getStartByte()<= $this->getStartByte()){return self::LOCAL_OUT;}// ?
  107. G::E(G::L('?????Template???','Dyhb'));
  108. }
  109. public function addTemplateObj(TemplateObj $oTemplateObj){
  110. $arrNewList=array();
  111. foreach($this->_arrChildTemplateObj as $oMyTemplateObj){
  112. A::INSTANCE($oMyTemplateObj,'TemplateObj');
  113. if($oTemplateObj){
  114. $nLocal=$oMyTemplateObj->compareLocal($oTemplateObj);
  115. switch($nLocal){
  116. case self::LOCAL_FRONT:
  117. $arrNewList[]=$oTemplateObj;// ???????
  118. $arrNewList[]=$oMyTemplateObj;
  119. $oTemplateObj=null;
  120. break;
  121. case self::LOCAL_BEHIND:
  122. $arrNewList[]=$oMyTemplateObj;
  123. break;
  124. case self::LOCAL_IN:
  125. $oMyTemplateObj->addTemplateObj($oTemplateObj);
  126. $arrNewList[]=$oMyTemplateObj;
  127. $oTemplateObj=null;
  128. break;
  129. case self::LOCAL_OUT:
  130. $oTemplateObj->addTemplateObj($oMyTemplateObj);
  131. break;
  132. }
  133. }
  134. else
  135. $arrNewList[]=$oMyTemplateObj;
  136. }
  137. if($oTemplateObj){// ?????
  138. $arrNewList[]=$oTemplateObj;
  139. }
  140. $this->_arrChildTemplateObj=$arrNewList;
  141. }
  142. public function removeTemplateObj($nIdx){
  143. A::INT($nIdx);
  144. if(isset($this->_arrChildTemplateObj[$nIdx])){
  145. $oRet=$this->_arrChildTemplateObj[$nIdx];
  146. unset($this->_arrChildTemplateObj[$nIdx]);
  147. return $oRet;
  148. }
  149. }
  150. public function getTemplateObj($nIdx){
  151. A::INT($nIdx);
  152. return isset($this->_arrChildTemplateObj[$nIdx])? $this->_arrChildTemplateObj[$nIdx]: null;
  153. }
  154. public function locate($sTemplateStream, $nStart){
  155. A::STRING($sTemplateStream);
  156. A::INT($nStart);
  157. $sSourceStream=$this->getSource();
  158. if(empty($sSourceStream)){// ???
  159. $this->setStartByte(-1);
  160. $this->setEndByte(-1);
  161. $this->setStartLine(-1);
  162. $this->setEndLine(-1);
  163. $this->setEndLine(-1);
  164. $this->setStartByteInLine(-1);
  165. $this->setEndByteInLine(-1);
  166. return;
  167. }
  168. $nTotalByte=strlen($sTemplateStream);
  169. $nStartByte=strpos($sTemplateStream,$sSourceStream,$nStart);// ??????
  170. $nEndByte=$nStartByte+strlen($sSourceStream)-1;
  171. $this->setStartByte($nStartByte);
  172. $this->setEndByte($nEndByte);
  173. $nStartLine=($nStartByte<=0)?0:substr_count($sTemplateStream,"\n",0,$nStartByte);// ????
  174. $nEndLine =($nEndByte<=0)?0:substr_count($sTemplateStream,"\n",0,$nEndByte);
  175. $this->setStartLine($nStartLine);
  176. $this->setEndLine($nEndLine);
  177. $nLineHeadOfStart=strrpos(substr($sTemplateStream,0,$nStartByte),"\n")+1;// ????????&&??? ??? ?????
  178. $nLineHeadOfEnd=strrpos(substr($sTemplateStream,0,$nEndByte),"\n")+1;// ??? ??? ?????
  179. $nStartInLine=$nStartByte-$nLineHeadOfStart;
  180. $nEndInLine=$nEndByte-$nLineHeadOfEnd;
  181. $this->setStartByteInLine($nStartInLine);
  182. $this->setEndByteInLine($nEndInLine);
  183. }
  184. public function compile(){
  185. while($oCompiler=$this->setCompiler(null)){// ????
  186. $oCompiler->compile($this);
  187. }
  188. }
  189. public function getLocationDescription(){
  190. return G::L('?: %s; ?: %s; ??: %s','Dyhb',null,$this->getStartLine(),$this->getStartByteInLine(),$this->getTemplateFile());
  191. }
  192. }