示例#1
0
 /**
  * 解析模板内容并返回
  * 
  * 将输入的模板内容解析为方法数组{@example <pre>
  * 以下模板内容将解析为:
  * <hook-action name="testHook" args='a,c'>
  * <div>
  * hi, i am testHook
  * </div>
  * </hook-action>
  * <hook-action name="testHook1">
  * <div>
  * hi, i am testHook
  * </div>
  * </hook-action>
  * 
  * $content = array(
  * 'testHook' => array('content', array('a','c')),
  * 'testHook1' => array('content', array('data'))
  * );
  * </pre>}
  * @param string $template
  * @return array
  */
 private static function _resolveTemplate($template, $_prefix)
 {
     if (false === ($content = WindFile::read($template))) {
         throw new PwException('template.path.fail', array('{parm1}' => 'wekit.engine.hook.PwHook._resolveTemplate', '{parm2}' => $template));
     }
     self::$methods = array();
     $content = preg_replace_callback('/<(\\/)?hook-action[=,\\w\\s\'\\"]*>(\\n)*/i', 'PwHook::_pregContent', $content);
     $content = explode("</hook-action>", $content);
     $_content = array();
     $_i = 0;
     //如果该模板中只有一段片段没有使用hook-action,则该方法名将会设为该模板名称,接受的参数为$data
     if (count(self::$methods) == 0) {
         $_content[$_prefix] = array($content[0], array('data'));
     } else {
         $_i = 0;
         foreach (self::$methods as $method) {
             $key = $method['name'] ? $_prefix . '_' . strtoupper($method['name']) : $_prefix . '_' . ($_i + 1);
             $args = $method['args'] ? explode(',', $method['args']) : array('data');
             $_content[$key] = array($content[$_i], $args);
             $_i++;
         }
     }
     return $_content;
 }