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


PHP Twig_Environment::registerUndefinedFilterCallback方法代码示例

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


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

示例1: init

 /**
  * Twig initialization that sets the twig loader chain, then the environment, then extensions
  * and also the base set of twig vars
  */
 public function init()
 {
     if (!isset($this->twig)) {
         /** @var Config $config */
         $config = $this->grav['config'];
         /** @var UniformResourceLocator $locator */
         $locator = $this->grav['locator'];
         $debugger = $this->grav['debugger'];
         $this->twig_paths = $locator->findResources('theme://templates');
         $this->grav->fireEvent('onTwigTemplatePaths');
         $this->loader = new \Twig_Loader_Filesystem($this->twig_paths);
         $this->loaderArray = new \Twig_Loader_Array(array());
         $loader_chain = new \Twig_Loader_Chain(array($this->loaderArray, $this->loader));
         $params = $config->get('system.twig');
         if (!empty($params['cache'])) {
             $params['cache'] = $locator->findResource('cache://twig', true, true);
         }
         $this->twig = new \Twig_Environment($loader_chain, $params);
         if ($debugger->enabled() && $config->get('system.debugger.twig')) {
             $this->twig = new \DebugBar\Bridge\Twig\TraceableTwigEnvironment($this->twig);
             $collector = new \DebugBar\Bridge\Twig\TwigCollector($this->twig);
             $debugger->addCollector($collector);
         }
         if ($config->get('system.twig.undefined_functions')) {
             $this->twig->registerUndefinedFunctionCallback(function ($name) {
                 if (function_exists($name)) {
                     return new \Twig_Function_Function($name);
                 }
                 return new \Twig_Function_Function(function () {
                 });
             });
         }
         if ($config->get('system.twig.undefined_filters')) {
             $this->twig->registerUndefinedFilterCallback(function ($name) {
                 if (function_exists($name)) {
                     return new \Twig_Filter_Function($name);
                 }
                 return new \Twig_Filter_Function(function () {
                 });
             });
         }
         $this->grav->fireEvent('onTwigInitialized');
         // set default date format if set in config
         if ($config->get('system.pages.dateformat.long')) {
             $this->twig->getExtension('core')->setDateFormat($config->get('system.pages.dateformat.long'));
         }
         // enable the debug extension if required
         if ($config->get('system.twig.debug')) {
             $this->twig->addExtension(new \Twig_Extension_Debug());
         }
         $this->twig->addExtension(new TwigExtension());
         $this->grav->fireEvent('onTwigExtensions');
         // Set some standard variables for twig
         $this->twig_vars = array('grav' => $this->grav, 'config' => $config, 'uri' => $this->grav['uri'], 'base_dir' => rtrim(ROOT_DIR, '/'), 'base_url' => $this->grav['base_url'], 'base_url_absolute' => $this->grav['base_url_absolute'], 'base_url_relative' => $this->grav['base_url_relative'], 'theme_dir' => $locator->findResource('theme://'), 'theme_url' => $this->grav['base_url'] . '/' . $locator->findResource('theme://', false), 'site' => $config->get('site'), 'assets' => $this->grav['assets'], 'taxonomy' => $this->grav['taxonomy'], 'browser' => $this->grav['browser']);
     }
 }
开发者ID:re-pe,项目名称:grav,代码行数:60,代码来源:Twig.php

示例2: __construct

 /**
  * @param array $values
  */
 public function __construct($values = array())
 {
     $defaults['twig.options'] = array();
     $defaults['twig.directories'] = array();
     $defaults['twig.loader'] = function ($meadow) {
         // this needs to be lazy or theme switchers and alike explode it
         $stylesheet_dir = get_stylesheet_directory();
         $template_dir = get_template_directory();
         $calculated_dirs = array($stylesheet_dir, $template_dir, plugin_dir_path(__DIR__) . 'twig');
         // enables explicit inheritance from parent theme in child
         if ($stylesheet_dir !== $template_dir) {
             $calculated_dirs[] = dirname($template_dir);
         }
         $directories = array_unique(array_merge($calculated_dirs, $meadow['twig.directories']));
         return new \Twig_Loader_Filesystem($directories);
     };
     $defaults['twig.undefined_function'] = array(__CLASS__, 'undefined_function');
     $defaults['twig.undefined_filter'] = array(__CLASS__, 'undefined_filter');
     $defaults['twig.environment'] = function ($meadow) {
         $environment = new \Twig_Environment($meadow['twig.loader'], $meadow['twig.options']);
         $meadow_extension = new Extension();
         $environment->addExtension($meadow_extension);
         $environment->registerUndefinedFunctionCallback($meadow['twig.undefined_function']);
         $environment->registerUndefinedFilterCallback($meadow['twig.undefined_filter']);
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $debug_extension = new \Twig_Extension_Debug();
             $environment->addExtension($debug_extension);
             $environment->enableDebug();
         }
         return $environment;
     };
     $defaults['hierarchy'] = function () {
         return new Template_Hierarchy();
     };
     parent::__construct(array_merge($defaults, $values));
 }
开发者ID:rarst,项目名称:meadow,代码行数:39,代码来源:class-core.php

示例3: init

 /**
  * Twig initialization that sets the twig loader chain, then the environment, then extensions
  * and also the base set of twig vars
  */
 public function init()
 {
     if (!isset($this->twig)) {
         /** @var Config $config */
         $config = $this->grav['config'];
         /** @var UniformResourceLocator $locator */
         $locator = $this->grav['locator'];
         /** @var Language $language */
         $language = $this->grav['language'];
         $active_language = $language->getActive();
         $language_append = '';
         if ($language->getDefault() != $active_language || $config->get('system.languages.include_default_lang') === true) {
             $language_append = $active_language ? '/' . $active_language : '';
         }
         // handle language templates if available
         if ($language->enabled()) {
             $lang_templates = $locator->findResource('theme://templates/' . ($active_language ? $active_language : $language->getDefault()));
             if ($lang_templates) {
                 $this->twig_paths[] = $lang_templates;
             }
         }
         $this->twig_paths = array_merge($this->twig_paths, $locator->findResources('theme://templates'));
         $this->grav->fireEvent('onTwigTemplatePaths');
         $this->loader = new \Twig_Loader_Filesystem($this->twig_paths);
         $this->loaderArray = new \Twig_Loader_Array([]);
         $loader_chain = new \Twig_Loader_Chain([$this->loaderArray, $this->loader]);
         $params = $config->get('system.twig');
         if (!empty($params['cache'])) {
             $cachePath = $locator->findResource('cache://twig', true, true);
             $params['cache'] = new \Twig_Cache_Filesystem($cachePath, \Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION);
         }
         if (!empty($this->autoescape)) {
             $params['autoescape'] = $this->autoescape;
         }
         $this->twig = new TwigEnvironment($loader_chain, $params);
         if ($config->get('system.twig.undefined_functions')) {
             $this->twig->registerUndefinedFunctionCallback(function ($name) {
                 if (function_exists($name)) {
                     return new \Twig_Function_Function($name);
                 }
                 return new \Twig_Function_Function(function () {
                 });
             });
         }
         if ($config->get('system.twig.undefined_filters')) {
             $this->twig->registerUndefinedFilterCallback(function ($name) {
                 if (function_exists($name)) {
                     return new \Twig_Filter_Function($name);
                 }
                 return new \Twig_Filter_Function(function () {
                 });
             });
         }
         $this->grav->fireEvent('onTwigInitialized');
         // set default date format if set in config
         if ($config->get('system.pages.dateformat.long')) {
             $this->twig->getExtension('core')->setDateFormat($config->get('system.pages.dateformat.long'));
         }
         // enable the debug extension if required
         if ($config->get('system.twig.debug')) {
             $this->twig->addExtension(new \Twig_Extension_Debug());
         }
         $this->twig->addExtension(new TwigExtension());
         $this->grav->fireEvent('onTwigExtensions');
         // Set some standard variables for twig
         $this->twig_vars = $this->twig_vars + ['config' => $config, 'uri' => $this->grav['uri'], 'base_dir' => rtrim(ROOT_DIR, '/'), 'base_url' => $this->grav['base_url'] . $language_append, 'base_url_simple' => $this->grav['base_url'], 'base_url_absolute' => $this->grav['base_url_absolute'] . $language_append, 'base_url_relative' => $this->grav['base_url_relative'] . $language_append, 'theme_dir' => $locator->findResource('theme://'), 'theme_url' => $this->grav['base_url'] . '/' . $locator->findResource('theme://', false), 'site' => $config->get('site'), 'assets' => $this->grav['assets'], 'taxonomy' => $this->grav['taxonomy'], 'browser' => $this->grav['browser']];
     }
 }
开发者ID:dweelie,项目名称:grav,代码行数:72,代码来源:Twig.php


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