| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 /** 11 * class WactBlockAnalizer. 12 * 13 * @package wact 14 * @version $Id$ 15 */ 16 class WactBlockAnalizer 17 { 18 const BEFORE_CONTENT = 1; 19 const EXPRESSION = 2; 20 const AFTER_CONTENT = 5; 21 22 protected $variable_reference_pattern; 23 24 function __construct() 25 { 26 $this->variable_reference_pattern = $this->_getVariableReferentPattern(); 27 } 28 29 protected function _getVariableReferentPattern() 30 { 31 $pattern = 32 // start at the beginning 33 '/^' . 34 // Pick up the portion of the string before the variable reference 35 '((?s).*?)' . 36 // Beginning of a variable reference 37 preg_quote('{$', '/') . 38 // Collect the entire variable reference into one subexpression 39 '(' . 40 // capture the contents of one or more fragments. 41 '(' . 42 // Anything thats not a quote or the end of the variable 43 // reference can be in a fragment 44 '[^"\'}]+' . 45 // OR 46 '|' . 47 // A string inside quotes is also a fragment 48 '(\'|").*?\4' . 49 ')+' . 50 ')' . 51 // end of a variable reference 52 preg_quote('}', '/') . 53 // Pick up the portion of the string after the variable reference 54 // This portion may contain additional references; we only match 55 // one at a time. 56 '((?s).*)' . 57 // Match until the end of the string 58 '$/'; 59 60 return $pattern; 61 } 62 63 function parse($text, $observer) 64 { 65 // if there is no expression (common case), shortcut this process 66 if (strpos($text, '{$') === FALSE) 67 { 68 $observer->addLiteralFragment($text); 69 return; 70 } 71 72 while (preg_match($this->variable_reference_pattern, $text, $match)) 73 { 74 if (strlen($match[self :: BEFORE_CONTENT]) > 0) 75 $observer->addLiteralFragment($match[self :: BEFORE_CONTENT]); 76 77 $observer->addExpressionFragment($match[self :: EXPRESSION]); 78 79 $text = $match[self :: AFTER_CONTENT]; 80 } 81 82 if (strlen($text) > 0) 83 $observer->addLiteralFragment($text); 84 } 85 } 86 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Dec 1 03:56:46 2008 | Cross-referenced by PHPXref 0.7 |