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


PHP Twig_ExtensionInterface類代碼示例

本文整理匯總了PHP中Twig_ExtensionInterface的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_ExtensionInterface類的具體用法?PHP Twig_ExtensionInterface怎麽用?PHP Twig_ExtensionInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: initExtension

 protected function initExtension(Twig_ExtensionInterface $extension)
 {
     // filters
     foreach ($extension->getFilters() as $name => $filter) {
         if ($name instanceof Twig_SimpleFilter) {
             $filter = $name;
             $name = $filter->getName();
         } elseif ($filter instanceof Twig_SimpleFilter) {
             $name = $filter->getName();
         }
         $this->filters[$name] = $filter;
     }
     // functions
     foreach ($extension->getFunctions() as $name => $function) {
         if ($name instanceof Twig_SimpleFunction) {
             $function = $name;
             $name = $function->getName();
         } elseif ($function instanceof Twig_SimpleFunction) {
             $name = $function->getName();
         }
         $this->functions[$name] = $function;
     }
     // tests
     foreach ($extension->getTests() as $name => $test) {
         if ($name instanceof Twig_SimpleTest) {
             $test = $name;
             $name = $test->getName();
         } elseif ($test instanceof Twig_SimpleTest) {
             $name = $test->getName();
         }
         $this->tests[$name] = $test;
     }
     // token parsers
     foreach ($extension->getTokenParsers() as $parser) {
         if ($parser instanceof Twig_TokenParserInterface) {
             $this->parsers->addTokenParser($parser);
         } elseif ($parser instanceof Twig_TokenParserBrokerInterface) {
             $this->parsers->addTokenParserBroker($parser);
         } else {
             throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances');
         }
     }
     // node visitors
     foreach ($extension->getNodeVisitors() as $visitor) {
         $this->visitors[] = $visitor;
     }
     // operators
     if ($operators = $extension->getOperators()) {
         if (2 !== count($operators)) {
             throw new InvalidArgumentException(sprintf('"%s::getOperators()" does not return a valid operators array.', get_class($extension)));
         }
         $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
         $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
     }
 }
開發者ID:tschifftner,項目名稱:Magento-MEP,代碼行數:55,代碼來源:Environment.php

示例2: addExtension

 /**
  * Registers an extension.
  *
  * @param Twig_ExtensionInterface $extension A Twig_ExtensionInterface instance
  */
 public function addExtension(Twig_ExtensionInterface $extension)
 {
     $this->extensions[$extension->getName()] = $extension;
     $this->parsers = null;
     $this->visitors = null;
     $this->filters = null;
     $this->tests = null;
     $this->functions = null;
     $this->globals = null;
 }
開發者ID:basdog22,項目名稱:Qool,代碼行數:15,代碼來源:Environment.php

示例3: addExtension

 public function addExtension(Twig_ExtensionInterface $extension)
 {
     $this->extensions[$extension->getName()] = $extension;
 }
開發者ID:hungnv0789,項目名稱:vhtm,代碼行數:4,代碼來源:Environment.php

示例4: initExtension

 protected function initExtension(Twig_ExtensionInterface $extension)
 {
     // filters
     foreach ($extension->getFilters() as $name => $filter) {
         if ($filter instanceof Twig_SimpleFilter) {
             $name = $filter->getName();
         } else {
             @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use Twig_SimpleFilter instead.', get_class($filter), $name), E_USER_DEPRECATED);
         }
         $this->filters[$name] = $filter;
     }
     // functions
     foreach ($extension->getFunctions() as $name => $function) {
         if ($function instanceof Twig_SimpleFunction) {
             $name = $function->getName();
         } else {
             @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use Twig_SimpleFunction instead.', get_class($function), $name), E_USER_DEPRECATED);
         }
         $this->functions[$name] = $function;
     }
     // tests
     foreach ($extension->getTests() as $name => $test) {
         if ($test instanceof Twig_SimpleTest) {
             $name = $test->getName();
         } else {
             @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use Twig_SimpleTest instead.', get_class($test), $name), E_USER_DEPRECATED);
         }
         $this->tests[$name] = $test;
     }
     // token parsers
     foreach ($extension->getTokenParsers() as $parser) {
         if ($parser instanceof Twig_TokenParserInterface) {
             $this->parsers->addTokenParser($parser);
         } elseif ($parser instanceof Twig_TokenParserBrokerInterface) {
             @trigger_error('Registering a Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED);
             $this->parsers->addTokenParserBroker($parser);
         } else {
             throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances');
         }
     }
     // node visitors
     foreach ($extension->getNodeVisitors() as $visitor) {
         $this->visitors[] = $visitor;
     }
     // operators
     if ($operators = $extension->getOperators()) {
         if (2 !== count($operators)) {
             throw new InvalidArgumentException(sprintf('"%s::getOperators()" does not return a valid operators array.', get_class($extension)));
         }
         $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
         $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
     }
 }
開發者ID:rogerioleal1,項目名稱:ci_base,代碼行數:53,代碼來源:Environment.php

示例5: initExtension

 private function initExtension(Twig_ExtensionInterface $extension)
 {
     // filters
     foreach ($extension->getFilters() as $filter) {
         $this->filters[$filter->getName()] = $filter;
     }
     // functions
     foreach ($extension->getFunctions() as $function) {
         $this->functions[$function->getName()] = $function;
     }
     // tests
     foreach ($extension->getTests() as $test) {
         $this->tests[$test->getName()] = $test;
     }
     // token parsers
     foreach ($extension->getTokenParsers() as $parser) {
         if (!$parser instanceof Twig_TokenParserInterface) {
             throw new LogicException('getTokenParsers() must return an array of Twig_TokenParserInterface');
         }
         $this->parsers[] = $parser;
     }
     // node visitors
     foreach ($extension->getNodeVisitors() as $visitor) {
         $this->visitors[] = $visitor;
     }
     // operators
     if ($operators = $extension->getOperators()) {
         if (2 !== count($operators)) {
             throw new InvalidArgumentException(sprintf('"%s::getOperators()" does not return a valid operators array.', get_class($extension)));
         }
         $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
         $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
     }
 }
開發者ID:PieterSwitten,項目名稱:webandmobile,代碼行數:34,代碼來源:Environment.php

示例6: addExtension

 /**
  * Add twig extension
  * 
  * @param \Twig_ExtensionInterface $extension
  * 
  * @return \Bridge\Bundle\TwigBundle\TwigTemplating
  */
 public function addExtension(\Twig_ExtensionInterface $extension)
 {
     if ($extension instanceof ContainerAwareInterface) {
         $extension->setContainer($this->container);
     }
     if ($extension instanceof AbstractExtension) {
         $extension->setEngine($this->twigEngine);
     }
     $this->environment->addExtension($extension);
     return $this;
 }
開發者ID:kernelstudio,項目名稱:bridge-twig-bundle,代碼行數:18,代碼來源:TwigTemplating.php

示例7: getFunctions

 /**
  * {@see \Twig_Extension::getFunctions}.
  */
 public function getFunctions()
 {
     $result = [];
     foreach ($this->extension->getFunctions() as $function) {
         $callable = $function->getCallable();
         $result[] = new \Twig_SimpleFunction($function->getName(), function () use($callable) {
             return $this->memoizeCache->memoize($callable, $this->lifeTime);
         });
     }
     return $result;
 }
開發者ID:sulu,項目名稱:sulu,代碼行數:14,代碼來源:MemoizeTwigExtensionTrait.php


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