當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Dwoo_Compiler::addPreProcessor方法代碼示例

本文整理匯總了PHP中Dwoo_Compiler::addPreProcessor方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dwoo_Compiler::addPreProcessor方法的具體用法?PHP Dwoo_Compiler::addPreProcessor怎麽用?PHP Dwoo_Compiler::addPreProcessor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Dwoo_Compiler的用法示例。


在下文中一共展示了Dwoo_Compiler::addPreProcessor方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSmartyCompat

 public function testSmartyCompat()
 {
     $tpl = new Dwoo_Template_String('{ldelim}{$smarty.version}{rdelim}');
     $tpl->forceCompilation();
     $cmp = new Dwoo_Compiler();
     $cmp->addPreProcessor('smarty_compat', true);
     $this->assertEquals('{' . Dwoo::VERSION . '}', $this->dwoo->get($tpl, array(), $cmp));
 }
開發者ID:apeschar,項目名稱:php-fw,代碼行數:8,代碼來源:FiltersTests.php

示例2: _parse_compiled

    /**
     *  Parse
     *
     * Parses pseudo-variables contained in the specified template,
     * replacing them with the data in the second param
     *
     * @access	public
     * @param	string
     * @param	array
     * @param	bool
     * @param	string
     * @return	string
     */
    public function _parse_compiled($string, $data, $return = FALSE, $cache_id = NULL)
    {
        // Start benchmark
        $this->_ci->benchmark->mark('dwoo_parse_start');
        // Convert from object to array
        if (!is_array($data)) {
            $data = (array) $data;
        }
        $data = array_merge($this->_ci->load->get_vars(), $data);
        foreach ($this->_parser_assign_refs as $ref) {
            $data[$ref] =& $this->_ci->{$ref};
        }
        // Object containing data
        $dwoo_data = new Dwoo_Data();
        $dwoo_data->setData($data);
        $parsed_string = '';
        try {
            // Object of the template
            $tpl = new Dwoo_Template_String($string, NULL, $cache_id, NULL);
            $dwoo = !isset($this->_dwoo) ? self::spawn() : $this->_dwoo;
            // check for existence of dwoo object... may not be there if folder is not writable
            // added by David McReynolds @ Daylight Studio 1/20/11
            if (!empty($dwoo)) {
                // Create the compiler instance
                $compiler = new Dwoo_Compiler();
                // added by David McReynolds @ Daylight Studio 1/22/12
                $compiler->setDelimiters($this->l_delim, $this->r_delim);
                //Add a pre-processor to help fix javascript {}
                // added by David McReynolds @ Daylight Studio 11/04/10
                $callback = create_function('$compiler', '
					$string = $compiler->getTemplateSource();
					
					$callback = create_function(\'$matches\',
						\'if (isset($matches[1]))
						{
							$str = "<script";
							$str .= preg_replace("#\\' . $this->l_delim . '([^s])#ms", "' . $this->l_delim . ' $1", $matches[1]);
							$str .= "</script>";
							return $str;
						}
						else
						{
							return $matches[0];
						}
						\'
						);

					$string = preg_replace_callback("#<script(.+)</script>#Ums", $callback, $string);
					$compiler->setTemplateSource($string);
					return $string;
				');
                $compiler->addPreProcessor($callback);
                // render the template
                $parsed_string = $dwoo->get($tpl, $dwoo_data, $compiler);
            } else {
                // load FUEL language file because it has the proper error
                // added by David McReynolds @ Daylight Studio 1/20/11
                $this->_ci->load->module_language(FUEL_FOLDER, 'fuel');
                throw new Exception(lang('error_folder_not_writable', $this->_ci->config->item('cache_path')));
            }
        } catch (Exception $e) {
            if (strtolower(get_class($e)) == 'dwoo_exception') {
                echo '<div class="error">' . $e->getMessage() . '</div>';
            } else {
                show_error($e->getMessage());
            }
        }
        // Finish benchmark
        $this->_ci->benchmark->mark('dwoo_parse_end');
        // Return results or not ?
        if (!$return) {
            $this->_ci->output->append_output($parsed_string);
            return;
        }
        return $parsed_string;
    }
開發者ID:kbjohnson90,項目名稱:FUEL-CMS,代碼行數:89,代碼來源:MY_Parser.php

示例3: testAddPreProcessorWithBadName

 /**
  * @expectedException Dwoo_Exception
  */
 public function testAddPreProcessorWithBadName()
 {
     $cmp = new Dwoo_Compiler();
     $cmp->addPreProcessor('__BAAAAD__', true);
     $tpl = new Dwoo_Template_String('');
     $tpl->forceCompilation();
     $this->dwoo->get($tpl, array(), $cmp);
 }
開發者ID:apeschar,項目名稱:php-fw,代碼行數:11,代碼來源:CompilerTests.php

示例4: foreach

    /**
     *  Parse
     *
     * Parses pseudo-variables contained in the specified template,
     * replacing them with the data in the second param
     *
     * @access	public
     * @param	string
     * @param	array
     * @param	bool
     * @return	string
     */
    function _parse($string, $data, $return = FALSE, $is_include = FALSE)
    {
        // Start benchmark
        $this->_ci->benchmark->mark('dwoo_parse_start');
        // Convert from object to array
        if (!is_array($data)) {
            $data = (array) $data;
        }
        $data = array_merge($data, $this->_ci->load->_ci_cached_vars);
        foreach ($this->_parser_assign_refs as $ref) {
            $data[$ref] =& $this->_ci->{$ref};
        }
        // Object containing data
        $dwoo_data = new Dwoo_Data();
        $dwoo_data->setData($data);
        try {
            // Object of the template
            $tpl = new Dwoo_Template_String($string);
            $dwoo = $is_include ? self::spawn() : $this->_dwoo;
            // Create the compiler instance
            $compiler = new Dwoo_Compiler();
            //Add a pre-processor to help fix javascript {}
            // added by David McReynolds @ Daylight Studio 11/04/10 to prevent problems of axing the entire directory
            $callback = create_function('$compiler', '
				$string = $compiler->getTemplateSource();
				$string = preg_replace("#{\\s*}#", "{\\n}", $string); 
				$compiler->setTemplateSource($string);
				return $string;
			');
            $compiler->addPreProcessor($callback);
            // render the template
            $parsed_string = $dwoo->get($tpl, $dwoo_data, $compiler);
        } catch (Exception $e) {
            show_error($e);
        }
        // Finish benchmark
        $this->_ci->benchmark->mark('dwoo_parse_end');
        // Return results or not ?
        if (!$return) {
            $this->_ci->output->append_output($parsed_string);
            return;
        }
        return $parsed_string;
    }
開發者ID:kieranklaassen,項目名稱:FUEL-CMS,代碼行數:56,代碼來源:MY_Parser.php


注:本文中的Dwoo_Compiler::addPreProcessor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。