本文整理汇总了PHP中Expression::getExpression方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::getExpression方法的具体用法?PHP Expression::getExpression怎么用?PHP Expression::getExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::getExpression方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetExpression
/**
* @covers Phramework\Testphase\Expression::getExpression
*/
public function testGetExpression()
{
$types = [Expression::EXPRESSION_TYPE_PLAIN, Expression::EXPRESSION_TYPE_REPLACE, Expression::EXPRESSION_TYPE_INLINE_REPLACE];
foreach ($types as $type) {
$expression = Expression::getExpression($type);
$this->assertInternalType('string', $expression);
//Check if expression is correct (no errors or exceptions fired)
preg_match($expression, 'my-key');
}
}
示例2: parse
/**
* Parse the template. The process here is basically to create sub-templates
* for some of the language constructs, and tie them in with placeholders in
* their parent template. Later, when we call render(), we can put the
* output of sub-templates back into their parents.
*/
private function parse()
{
if ($this->cache) {
$this->cacheFile = $this->CACHE_DIR . '/' . $this->name . $this->checksum();
// Make sure we have a cache directory to write to
if (!is_dir($this->CACHE_DIR)) {
mkdir($this->CACHE_DIR);
}
// If our cache file already exists, load it up
if (file_exists($this->cacheFile)) {
$this->cacheTemplate = unserialize(file_get_contents($this->cacheFile));
return;
}
}
$count = count($this->strings);
for ($i = 0; $i < $count; $i++) {
$matches = null;
// Remove all comments
$n = preg_match(self::RE_COM_BEG, $this->strings[$i], $matches);
if ($n > 0) {
$this->parseRecursive($i, array(self::RE_COM_BEG, self::RE_COM_END), 'comment');
$this->strings[$i] = '';
}
// Find all the variables. If the variable doesn't exist in our
// dictionary, stub it out.
preg_match_all(self::RE_VAR, $this->strings[$i], $matches);
if (!empty($matches[0])) {
foreach ($matches[1] as $match) {
if (!isset($this->vars[$match])) {
$this->vars[$match] = '';
}
}
}
// Find all foreach-loops. Every time we find one, make a new
// template with the contents of that loop, and put a placeholder
// where it used to be.
$n = preg_match(self::RE_FOR_BEG, $this->strings[$i], $matches);
if ($n > 0) {
$forName = $matches[1];
if (!isset($this->forTemplates[$forName])) {
$this->forTemplates[$forName] = array();
}
$n = count($this->forTemplates[$forName]);
$this->forTemplates[$forName][$n] = $this->parseRecursive($i, array(self::RE_FOR_BEG, self::RE_FOR_END), "{$this->name}_for_{$forName}_{$n}");
$this->strings[$i] = '{for:' . $forName . ':' . $n . '}';
}
// Do the same general process for our if statement.
$n = preg_match(self::RE_IF_BEG, $this->strings[$i], $matches);
if ($n > 0) {
$ifExpr = new expression($matches[1]);
$exprId = $ifExpr->getExpressionId();
if (!isset($this->expressions[$exprId])) {
$this->expressions[$exprId] = $ifExpr;
}
if (!isset($this->ifTemplates[$exprId])) {
$this->ifTemplates[$exprId] = array();
}
$n = count($this->ifTemplates[$exprId]);
$this->ifTemplates[$exprId][$n] = $this->parseRecursive($i, array(self::RE_IF_BEG, self::RE_IF_END), "{$this->name}_if_{$exprId}_{$n}");
$this->strings[$i] = '{if:' . $exprId . ':' . $n . '}';
}
// Currently, we have the same general process for includes. But..
// there are problems with this approach. In the future, this could
// be refactored.
//
// TODO: Move this block of code to the beginning, and instead of
// creating a template, just replace the include statement with
// the file contents of the include.
preg_match_all(self::RE_INC, $this->strings[$i], $matches);
if (!empty($matches[0])) {
foreach ($matches[1] as $match) {
if (!isset($this->incTemplates[$match])) {
$info = pathinfo($match);
if ($info['extension'] == 'php') {
ob_start();
$this->require_file($match);
$output = array(ob_get_clean());
$this->incTemplates[$match] = new Scurvy($output, $this->template_dir, false, $this->name);
} else {
$this->incTemplates[$match] = new Scurvy($match, $this->template_dir, false, $this->name);
}
}
}
}
// Find all expressions. We could probably get rid of this feature
// because expressions probably won't be used outside of
// if-statements.
preg_match_all(self::RE_EXPR, $this->strings[$i], $matches);
if (!empty($matches[0])) {
foreach ($matches[1] as $match) {
$expr = new Expression($match);
$exprId = $expr->getExpressionId();
if (!isset($this->expressions[$exprId])) {
$this->expressions[$exprId] = $expr;
//.........这里部分代码省略.........