Yii Framework v1.1.10 绫诲弬鑰

CPradoViewRenderer

system.web.renderers
缁ф壙 class CPradoViewRenderer » CViewRenderer » CApplicationComponent » CComponent
瀹炵幇 IViewRenderer, IApplicationComponent
婧愯嚜 1.0
鐗堟湰 $Id: CPradoViewRenderer.php 2799 2011-01-01 19:31:13Z qiang.xue $
婧愮爜 framework/web/renderers/CPradoViewRenderer.php
CPradoViewRenderer瀹炵幇涓涓鍥炬覆鏌撳櫒锛屽畠鍏佽鐢ㄦ埛浣跨敤绫讳技浜嶱RADO妯℃澘鐨勬ā鏉胯娉曘

瑕佷娇鐢–PradoViewRenderer, 鍦ㄥ簲璇ョ▼搴忛厤缃枃浠朵腑閰嶇疆涓涓悕涓"viewRenderer"鐨勫簲鐢ㄧ粍浠讹細
array(
    'components'=>array(
        ......
        'viewRenderer'=>array(
            'class'=>'CPradoViewRenderer',
        ),
    ),
)


CPradoViewRenderer 鍏佽浣犵敤涓嬮潰鐨勮娉曟潵鍐欒鍥炬枃浠讹細
// PHP tags:
<%= expression %>
// <?php echo expression ?>
<% statement %>
// <?php statement ?></li>

// component tags:
<com:WigetClass name1="value1" name2='value2' name3={value3} >
// <?php $this->beginWidget('WigetClass',
// array('name1'=>"value1", 'name2'=>'value2', 'name3'=>value3)); ?>
</com:WigetClass >
// <?php $this->endWidget('WigetClass'); ?>
<com:WigetClass name1="value1" name2='value2' name3={value3} />
// <?php $this->widget('WigetClass',
// array('name1'=>"value1", 'name2'=>'value2', 'name3'=>value3)); ?>

// cache tags:
<cache:fragmentID name1="value1" name2='value2' name3={value3} >
// <?php if($this->beginCache('fragmentID',
// array('name1'=>"value1", 'name2'=>'value2', 'name3'=>value3))): ?>
</cache:fragmentID >
// <?php $this->endCache('fragmentID'); endif; ?>

// clip tags:
<clip:clipID >
// <?php $this->beginClip('clipID'); ?>
</clip:clipID >
// <?php $this->endClip('clipID'); ?>

// comment tags:
<!--- comments --->
// the whole tag will be stripped off

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
behaviors array 杩欎釜搴旂敤缁勪欢闄勫姞鐨勮涓恒 杩欐琛屼负灏嗗湪搴旂敤缁勪欢璋冪敤init鏃堕檮鍔犲湪搴旂敤缁勪欢涓娿 璇峰弬鐓CModel::behaviors濡備綍鎸囧畾姝ゅ睘鎬у笺 CApplicationComponent
fileExtension string 瑙嗗浘鏂囦欢鐨勬墿灞曞悕. CViewRenderer
filePermission integer 瑙f瀽鍚庣敓鎴愮殑涓存椂鐩綍鍜屼复鏃舵枃浠剁殑鏉冮檺銆 榛樿涓0755 (owner rwx, group rx and others rx). CViewRenderer
isInitialized boolean 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
useRuntimePath boolean 鏄惁灏嗚В鏋愮殑缁撴灉淇濆瓨鍦ㄥ簲鐢ㄧ▼搴忕殑runtime鐩綍銆 榛樿涓簍rue銆 濡傛灉璁剧疆涓篺alse锛岃В鏋愮粨鏋滃皢浠ユ枃浠跺舰寮忎繚瀛樺湪鍜屾簮瑙嗗浘鏂囦欢鐩稿悓鐨勭洰褰曚笅 鏂囦欢鍚嶅皢浼氭槸婧愯鍥炬枃浠跺悕鍔犱笂瀛楁瘝c銆 CViewRenderer

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIsInitialized() 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() 鍒濆鍖栧簲鐢ㄧ粍浠躲 CApplicationComponent
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
renderFile() 娓叉煋涓涓鍥炬枃浠躲 CViewRenderer

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
generateViewFile() 瑙f瀽婧愯鍥炬枃浠讹紝淇濆瓨缁撴灉鍒板彟涓涓枃浠躲 CPradoViewRenderer
getViewFile() 鐢熸垚缁撴灉瑙嗗浘鏂囦欢鐨勮矾寰勩 CViewRenderer

鏂规硶璇︾粏

generateViewFile() 鏂规硶
protected void generateViewFile(string $sourceFile, string $viewFile)
$sourceFile string 婧愯鍥炬枃浠惰矾寰
$viewFile string 浣滀负缁撴灉鐨勮鍥炬枃浠惰矾寰
婧愮爜锛 framework/web/renderers/CPradoViewRenderer.php#81 (鏄剧ず)
protected function generateViewFile($sourceFile,$viewFile)
{
    static 
$regexRules=array(
        
'<%=?\s*(.*?)\s*%>',        // PHP statements or expressions
        
'<\/?(com|cache|clip):([\w\.]+)\s*((?:\s*\w+\s*=\s*\'.*?(?<!\\\\)\'|\s*\w+\s*=\s*".*?(?<!\\\\)"|\s*\w+\s*=\s*\{.*?\})*)\s*\/?>'// component tags
        
'<!---.*?--->',    // template comments
    
);
    
$this->_sourceFile=$sourceFile;
    
$this->_input=file_get_contents($sourceFile);
    
$n=preg_match_all('/'.implode('|',$regexRules).'/msS',$this->_input,$matches,PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
    
$textStart=0;
    
$this->_output="<?php /* source file: $sourceFile */ ?>\n";
    for(
$i=0;$i<$n;++$i)
    {
        
$match=&$matches[$i];
        
$str=$match[0][0];
        
$matchStart=$match[0][1];
        
$matchEnd=$matchStart+strlen($str)-1;

        if(
$matchStart>$textStart)
            
$this->_output.=substr($this->_input,$textStart,$matchStart-$textStart);
        
$textStart=$matchEnd+1;

        if(
strpos($str,'<com:')===0)    // opening component tag
        
{
            
$type=$match[3][0];
            if(
$str[strlen($str)-2]!=='/')  // open tag
                
$this->_output.=$this->processBeginWidget($type,$match[4][0],$match[2][1]);
            else
                
$this->_output.=$this->processWidget($type,$match[4][0],$match[2][1]);
        }
        else if(
strpos($str,'</com:')===0)    // closing component tag
            
$this->_output.=$this->processEndWidget($match[3][0],$match[2][1]);
        else if(
strpos($str,'<cache:')===0)    // opening cache tag
        
{
            
$id=$match[3][0];
            if(
$str[strlen($str)-2]!=='/')  // open tag
                
$this->_output.=$this->processBeginCache($id,$match[4][0],$match[2][1]);
            else
                
$this->_output.=$this->processCache($id,$match[4][0],$match[2][1]);
        }
        else if(
strpos($str,'</cache:')===0)    // closing cache tag
            
$this->_output.=$this->processEndCache($match[3][0],$match[2][1]);
        else if(
strpos($str,'<clip:')===0)    // opening clip tag
        
{
            
$id=$match[3][0];
            if(
$str[strlen($str)-2]!=='/')  // open tag
                
$this->_output.=$this->processBeginClip($id,$match[4][0],$match[2][1]);
            else
                
$this->_output.=$this->processClip($id,$match[4][0],$match[2][1]);
        }
        else if(
strpos($str,'</clip:')===0)    // closing clip tag
            
$this->_output.=$this->processEndClip($match[3][0],$match[2][1]);
        else if(
strpos($str,'<%=')===0)    // expression
            
$this->_output.=$this->processExpression($match[1][0],$match[1][1]);
        else if(
strpos($str,'<%')===0)    // statement
            
$this->_output.=$this->processStatement($match[1][0],$match[1][1]);
    }
    if(
$textStart<strlen($this->_input))
        
$this->_output.=substr($this->_input,$textStart);

    
file_put_contents($viewFile,$this->_output);
}

瑙f瀽婧愯鍥炬枃浠讹紝淇濆瓨缁撴灉鍒板彟涓涓枃浠躲 杩欎釜鏂规硶鏄埗绫绘墍蹇呴』鐨勩

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.