当前位置: 首页>>代码示例>>PHP>>正文


PHP Variable::resolve方法代码示例

本文整理汇总了PHP中Variable::resolve方法的典型用法代码示例。如果您正苦于以下问题:PHP Variable::resolve方法的具体用法?PHP Variable::resolve怎么用?PHP Variable::resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Variable的用法示例。


在下文中一共展示了Variable::resolve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 public function render($context)
 {
     try {
         $expire_time = $this->expire_time_var->resolve($context);
     } catch (VariableDoesNotExist $e) {
         throw new TemplateSyntaxError('"cache" tag got an unknown variable: ' . $this->expire_time_var->var);
     }
     if (!is_numeric($expire_time)) {
         throw new TemplateSyntaxError('"cache" tag got a non-integer timeout value: ' . print_r($expire_time, true));
     }
     $expire_time = (int) $expire_time;
     // Build a unicode key for this fragment and all vary-on's.
     $vs_ = array();
     foreach ($this->vary_on as $var) {
         $v_ = new Variable($var);
         $vs_[] = urlencode($v_->resolve($context));
     }
     $args = join(':', $vs_);
     unset($vs_);
     $cache_key = 'template.cache.' . $this->fragment_name . '.' . md5($args);
     $manager = Dja::getCacheManager();
     $value = $manager->get($cache_key);
     if ($value === null) {
         $value = $this->nodelist->render($context);
         $manager->set($cache_key, $value, $expire_time);
     }
     return $value;
 }
开发者ID:idlesign,项目名称:dja,代码行数:28,代码来源:cache.php

示例2: testVariableParsing

 public function testVariableParsing()
 {
     $c = array('article' => array('section' => 'News'));
     $v = new Variable('article.section');
     $this->assertEquals('News', $v->resolve($c));
     $v = new Variable('"News"');
     $this->assertEquals('News', $v->resolve($c));
     $v = new Variable("'News'");
     $this->assertEquals('News', $v->resolve($c));
     // Translated strings are handled correctly.
     $v = new Variable('_(article.section)');
     $this->assertEquals('News', $v->resolve($c));
     $v = new Variable('_("Good News")');
     $this->assertEquals('Good News', $v->resolve($c));
     $v = new Variable("_('Better News')");
     $this->assertEquals('Better News', $v->resolve($c));
     // Escaped quotes work correctly as well.
     $v = new Variable('"Some \\"Good\\" News"');
     $this->assertEquals('Some "Good" News', $v->resolve($c));
     $v = new Variable("'Some 'Better' News'");
     $this->assertEquals("Some 'Better' News", $v->resolve($c));
     // Variables should reject access of attributes beginning with underscores.
     $this->setExpectedException('TemplateSyntaxError');
     new Variable('article._hidden');
 }
开发者ID:idlesign,项目名称:dja,代码行数:25,代码来源:parser.php

示例3: resolve

 /**
  * @param Context $context
  * @param bool $ignore_failures
  *
  * @return mixed
  */
 public function resolve($context, $ignore_failures = False)
 {
     if ($this->var instanceof Variable) {
         try {
             $obj = $this->var->resolve($context);
         } catch (VariableDoesNotExist $e) {
             if ($ignore_failures) {
                 $obj = null;
             } else {
                 if (Dja::getSetting('TEMPLATE_STRING_IF_INVALID')) {
                     if (DjaBase::$invalid_var_format_string === null) {
                         DjaBase::$invalid_var_format_string = strpos(Dja::getSetting('TEMPLATE_STRING_IF_INVALID'), '%s') !== False;
                     }
                     if (DjaBase::$invalid_var_format_string) {
                         return sprintf(Dja::getSetting('TEMPLATE_STRING_IF_INVALID'), $this->var);
                     }
                     return Dja::getSetting('TEMPLATE_STRING_IF_INVALID');
                 } else {
                     $obj = Dja::getSetting('TEMPLATE_STRING_IF_INVALID');
                 }
             }
         }
     } else {
         $obj = $this->var;
     }
     foreach ($this->filters as $filter) {
         list($func, $args, $n_) = $filter;
         $arg_vals = array();
         foreach ($args as $arg_data) {
             /** @var $arg Variable|string */
             list($lookup, $arg) = $arg_data;
             if (!$lookup) {
                 $arg_vals[] = mark_safe($arg);
             } else {
                 $arg_vals[] = $arg->resolve($context);
             }
         }
         if (py_getattr($func, 'expects_localtime', False)) {
             $obj = localtime($obj, $context->use_tz);
         }
         $func_ = $func->closure;
         if (py_getattr($func, 'needs_autoescape', False)) {
             $new_obj = call_user_func_array($func_, array_merge(array($obj, $context->autoescape), $arg_vals));
         } else {
             $new_obj = call_user_func_array($func_, array_merge(array($obj), $arg_vals));
         }
         if (py_getattr($func, 'is_safe', False) && $obj instanceof SafeData) {
             $obj = mark_safe($new_obj);
         } else {
             if ($obj instanceof EscapeData) {
                 $obj = mark_for_escaping($new_obj);
             } else {
                 $obj = $new_obj;
             }
         }
     }
     return $obj;
 }
开发者ID:idlesign,项目名称:dja,代码行数:64,代码来源:base.php


注:本文中的Variable::resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。