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


PHP Twig_Environment::getFilter方法代码示例

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


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

示例1: lazyInit

 /**
  * Initializes arrays of filters and functions.
  */
 private function lazyInit()
 {
     $stringyClass = new \ReflectionClass('Stringy\\Stringy');
     $methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC);
     $names = array_map(function ($value) {
         return $value->getName();
     }, $methods);
     foreach ($names as $name) {
         if (in_array($name, self::EXCLUDE_FUNCTIONS)) {
             continue;
         }
         $method = $stringyClass->getMethod($name);
         // Get the return type from the doc comment
         $doc = $method->getDocComment();
         if (strpos($doc, '@return bool')) {
             // Don't add functions which have the same name as any already in the environment
             if ($this->environment->getFunction($name)) {
                 continue;
             }
             $this->functions[$name] = new \Twig_SimpleFunction($name, function () use($name) {
                 return call_user_func_array(['Stringy\\StaticStringy', $name], func_get_args());
             });
         } else {
             // Don't add filters which have the same name as any already in the environment
             if ($this->environment->getFilter($name)) {
                 continue;
             }
             $this->filters[$name] = new \Twig_SimpleFilter($name, function () use($name) {
                 return call_user_func_array(['Stringy\\StaticStringy', $name], func_get_args());
             });
         }
     }
 }
开发者ID:superdesk,项目名称:web-publisher,代码行数:36,代码来源:StringyExtension.php

示例2: leaveNode

 public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_Expression_Constant) {
         // constants are marked safe for all
         $this->setSafe($node, array('all'));
     } elseif ($node instanceof Twig_Node_Expression_Conditional) {
         // intersect safeness of both operands
         $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3')));
         $this->setSafe($node, $safe);
     } elseif ($node instanceof Twig_Node_Expression_Filter) {
         // filter expression is safe when the filter is safe
         $name = $node->getNode('filter')->getAttribute('value');
         $args = $node->getNode('arguments');
         if (false !== ($filter = $env->getFilter($name))) {
             $this->setSafe($node, $filter->getSafe($args));
         } else {
             $this->setSafe($node, array());
         }
     } elseif ($node instanceof Twig_Node_Expression_Function) {
         // function expression is safe when the function is safe
         $name = $node->getNode('name')->getAttribute('name');
         $args = $node->getNode('arguments');
         $function = $env->getFunction($name);
         if (false !== $function) {
             $this->setSafe($node, $function->getSafe($args));
         } else {
             $this->setSafe($node, array());
         }
     } else {
         $this->setSafe($node, array());
     }
     return $node;
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:33,代码来源:SafeAnalysis.php

示例3: leaveNode

 public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_Expression_Constant) {
         // constants are marked safe for all
         $this->setSafe($node, array('all'));
     } elseif ($node instanceof Twig_Node_Expression_BlockReference) {
         // blocks are safe by definition
         $this->setSafe($node, array('all'));
     } elseif ($node instanceof Twig_Node_Expression_Parent) {
         // parent block is safe by definition
         $this->setSafe($node, array('all'));
     } elseif ($node instanceof Twig_Node_Expression_Conditional) {
         // intersect safeness of both operands
         $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3')));
         $this->setSafe($node, $safe);
     } elseif ($node instanceof Twig_Node_Expression_Filter) {
         // filter expression is safe when the filter is safe
         $name = $node->getNode('filter')->getAttribute('value');
         $args = $node->getNode('arguments');
         if (false !== ($filter = $env->getFilter($name))) {
             $safe = $filter->getSafe($args);
             if (null === $safe) {
                 $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety());
             }
             $this->setSafe($node, $safe);
         } else {
             $this->setSafe($node, array());
         }
     } elseif ($node instanceof Twig_Node_Expression_Function) {
         // function expression is safe when the function is safe
         $name = $node->getAttribute('name');
         $args = $node->getNode('arguments');
         $function = $env->getFunction($name);
         if (false !== $function) {
             $this->setSafe($node, $function->getSafe($args));
         } else {
             $this->setSafe($node, array());
         }
     } elseif ($node instanceof Twig_Node_Expression_MethodCall) {
         if ($node->getAttribute('safe')) {
             $this->setSafe($node, array('all'));
         } else {
             $this->setSafe($node, array());
         }
     } elseif ($node instanceof Twig_Node_Expression_MacroCall) {
         $this->setSafe($node, array('all'));
     } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) {
         $name = $node->getNode('node')->getAttribute('name');
         // attributes on template instances are safe
         if ('_self' == $name || in_array($name, $this->safeVars)) {
             $this->setSafe($node, array('all'));
         } else {
             $this->setSafe($node, array());
         }
     } else {
         $this->setSafe($node, array());
     }
     return $node;
 }
开发者ID:0151n,项目名称:vichan,代码行数:59,代码来源:SafeAnalysis.php

示例4: preEscapeFilterNode

 private function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env)
 {
     $name = $filter->getNode('filter')->getAttribute('value');
     $type = $env->getFilter($name)->getPreEscape();
     if (null === $type) {
         return $filter;
     }
     $node = $filter->getNode('node');
     if ($this->isSafeFor($type, $node, $env)) {
         return $filter;
     }
     $filter->setNode('node', $this->getEscaperFilter($type, $node));
     return $filter;
 }
开发者ID:vgrish,项目名称:twiggy,代码行数:14,代码来源:Escaper.php

示例5: genderFilter

 public function genderFilter(\Twig_Environment $env, $genderType)
 {
     // @todo is this the right way to do translation ?
     // Is it better to do it in the twig itself with "|gender|trans()" ?
     $trans = $env->getFilter('trans')->getCallable();
     switch ($genderType) {
         case 'xx':
             return call_user_func($trans, 'Female');
         case 'xy':
             return call_user_func($trans, 'Male');
         default:
             return '?';
     }
 }
开发者ID:xtrasmal,项目名称:iinano,代码行数:14,代码来源:RendererExtension.php


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