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


PHP Twig_Environment::setLexer方法代码示例

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


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

示例1: spawn

 /**
  * Spawns a new instance of Twig.
  *
  * @return object
  **/
 protected function spawn()
 {
     // register the Twig autoloader.
     Twig_Autoloader::register();
     // Init the Twig loader.
     $loader = new Twig_Loader_String();
     // check if the cache dir is set.
     if ($this->compile_dir) {
         if (is_null($this->debug)) {
             $this->debug = is_dev_mode();
         }
         $twig = new Twig_Environment($loader, array('autoescape' => FALSE, 'cache' => $this->compile_dir, 'debug' => $this->debug, 'charset' => $this->charset, 'base_template_class' => $this->base_template_class, 'strict_variables' => $this->strict_variables, 'autoescape' => $this->autoescape, 'optimizations' => $this->optimizations));
     } else {
         $twig = new Twig_Environment($loader, array('autoescape' => FALSE));
     }
     // init all functions as Twig functions.
     foreach ($this->allowed_functions as $function) {
         $twig->addFunction($function, new Twig_Function_Function($function));
     }
     // setup debugger
     $twig->addExtension(new Twig_Extension_Debug());
     // setup the Lexer
     $lexer = new Twig_Lexer($twig, $this->delimiters);
     $twig->setLexer($lexer);
     // finally, return the object.
     return $twig;
 }
开发者ID:huayuxian,项目名称:FUEL-CMS,代码行数:32,代码来源:Fuel_twig_parser.php

示例2: __construct

 public function __construct($data = array())
 {
     parent::__construct($data);
     $dirs = Zend_Registry::get('dirs');
     $template = Zend_Registry::get('theme');
     $config = Zend_Registry::get('config');
     $qool_module = Zend_Registry::get('Qool_Module');
     // Class Constructor.
     // These automatically get set with each new instance.
     $loader = new Twig_Loader_Filesystem(APPL_PATH . $dirs['structure']['templates'] . DIR_SEP . $qool_module . DIR_SEP . $template . DIR_SEP);
     $twig = new Twig_Environment($loader, array('cache' => APPL_PATH . $dirs['structure']['cache'] . DIR_SEP . 'twig' . DIR_SEP));
     $lexer = new Twig_Lexer($twig, array('tag_comment' => array('<#', '#>}'), 'tag_block' => array('<%', '%>'), 'tag_variable' => array('<<', '>>')));
     $twig->setLexer($lexer);
     include_once APPL_PATH . $dirs['structure']['lib'] . DIR_SEP . 'Qool' . DIR_SEP . 'Template' . DIR_SEP . 'template.php';
     if (file_exists(APPL_PATH . $dirs['structure']['templates'] . DIR_SEP . $qool_module . DIR_SEP . $template . DIR_SEP . 'functions.php')) {
         include_once APPL_PATH . $dirs['structure']['templates'] . DIR_SEP . $qool_module . DIR_SEP . $template . DIR_SEP . 'functions.php';
     }
     $funcs = get_defined_functions();
     foreach ($funcs['user'] as $k => $v) {
         $twig->addFunction($v, new Twig_Function_Function($v));
     }
     $this->_twig = $twig;
     $this->assign('config', $config);
     Zend_Registry::set('tplExt', 'html');
 }
开发者ID:basdog22,项目名称:Qool,代码行数:25,代码来源:Twig.php

示例3: testExpressions

 /**
  * @dataProvider getData
  */
 public function testExpressions($expression, $expectedViolation)
 {
     $twig = new \Twig_Environment();
     $twig->setLexer(new Lexer($twig));
     $validator = new Validator();
     $violations = $validator->validate(new Official(), $twig->tokenize($expression));
     if ($expectedViolation) {
         $this->assertSame(1, count($violations));
         $this->assertSame($expectedViolation, $violations[0]->getReason());
     } else {
         $this->assertSame(0, count($violations));
     }
 }
开发者ID:allocine,项目名称:twigcs,代码行数:16,代码来源:FunctionalTest.php

示例4: __construct

 /**
  * Constructor
  *
  * @param array $config An array of default values.
  */
 public function __construct($config)
 {
     $this->config = $config;
     ShortcodesTrait::setShortcodesClass($this);
     // Set up Twig environment
     $this->loader = new \Twig_Loader_Array([]);
     $this->twig = new Twig\Environment($this->loader, ['use_strict_variables' => false]);
     // Set up sandbox for parsing shortcodes
     $this->policy = new \Twig_Sandbox_SecurityPolicy();
     $this->twig->addExtension(new \Twig_Extension_Sandbox($this->policy, true));
     $this->policy->setAllowedTags($this->loadShortcodes());
     // Modify lexer to match special shortcode syntax
     $lexer = new \Twig_Lexer($this->twig, array('tag_comment' => ['{#', '#}'], 'tag_block' => ['{{%', '%}}'], 'tag_variable' => ['{#', '#}'], 'interpolation' => ['#{', '}']));
     $this->twig->setLexer($lexer);
 }
开发者ID:Sommerregen,项目名称:grav-plugin-shortcodes,代码行数:20,代码来源:Shortcodes.php

示例5: __construct

 /**
  * Constructor.
  *
  * @param \src\path_helper $path_helper
  * @param \src\config\config $config
  * @param \src\user $user
  * @param \src\template\context $context template context
  * @param \src\extension\manager $extension_manager extension manager, if null then template events will not be invoked
  */
 public function __construct(\src\path_helper $path_helper, $config, $user, \src\template\context $context, \src\extension\manager $extension_manager = null)
 {
     $this->path_helper = $path_helper;
     $this->src_root_path = $path_helper->get_src_root_path();
     $this->php_ext = $path_helper->get_php_ext();
     $this->config = $config;
     $this->user = $user;
     $this->context = $context;
     $this->extension_manager = $extension_manager;
     $this->cachepath = $this->src_root_path . 'cache/twig/';
     // Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
     $loader = new \src\template\twig\loader('');
     $this->twig = new \src\template\twig\environment($this->config, $this->path_helper, $this->extension_manager, $loader, array('cache' => defined('IN_INSTALL') ? false : $this->cachepath, 'debug' => defined('DEBUG'), 'auto_reload' => (bool) $this->config['load_tplcompile'], 'autoescape' => false));
     $this->twig->addExtension(new \src\template\twig\extension($this->context, $this->user));
     if (defined('DEBUG')) {
         $this->twig->addExtension(new \Twig_Extension_Debug());
     }
     $lexer = new \src\template\twig\lexer($this->twig);
     $this->twig->setLexer($lexer);
     // Add admin namespace
     if ($this->path_helper->get_adm_relative_path() !== null && is_dir($this->src_root_path . $this->path_helper->get_adm_relative_path() . 'style/')) {
         $this->twig->getLoader()->setPaths($this->src_root_path . $this->path_helper->get_adm_relative_path() . 'style/', 'admin');
     }
 }
开发者ID:,项目名称:,代码行数:33,代码来源:

示例6: __construct

 public function __construct()
 {
     $this['reporter.console'] = function () {
         return new ConsoleReporter();
     };
     $this['reporter.checkstyle'] = function () {
         return new CheckstyleReporter();
     };
     $this['twig'] = function ($container) {
         $twig = new \Twig_Environment();
         $twig->setLexer(new Lexer($twig));
         return $twig;
     };
     $this['validator'] = function () {
         return new Validator();
     };
 }
开发者ID:allocine,项目名称:twigcs,代码行数:17,代码来源:Container.php

示例7: array

/**
 * Avisota newsletter and mailing system
 * Copyright © 2016 Sven Baumann
 *
 * PHP version 5
 *
 * @copyright  way.vision 2016
 * @author     Sven Baumann <baumann.sv@gmail.com>
 * @package    avisota/contao-message
 * @license    LGPL-3.0+
 * @filesource
 */
/** @var \Pimple $container */
/**
 * Define message renderer
 */
$container['avisota.message.renderer'] = $container->share(function () {
    return new \Avisota\Contao\Message\Core\Renderer\MessageRenderer();
});
$container['avisota.message.tagReplacementEngine'] = $container->share(function () {
    $debug = $GLOBALS['TL_CONFIG']['debugMode'] || $GLOBALS['TL_CONFIG']['twigDebugMode'];
    $loader = new \Twig_Loader_Array(array());
    $twig = new \Twig_Environment($loader, array('autoescape' => false, 'debug' => $debug));
    // Add debug extension
    if ($debug || $GLOBALS['TL_CONFIG']['twigDebugExtension']) {
        $twig->addExtension(new Twig_Extension_Debug());
    }
    $lexer = new Twig_Lexer($twig, array('tag_comment' => array('{#', '#}'), 'tag_block' => array('{%', '%}'), 'tag_variable' => array('##', '##'), 'interpolation' => array('#{', '}')));
    $twig->setLexer($lexer);
    return new \Avisota\Contao\Message\Core\Renderer\TagReplacementService($twig);
});
开发者ID:avisota,项目名称:contao-message,代码行数:31,代码来源:services.php

示例8: render

 /**
  * Render view
  *
  * @param $view string The name of the view
  * @param $data array  The data to use in rendering in the view
  */
 public function render($view, $data = array())
 {
     // Retrieve data necessary for properly rendering header and footer, and
     //   add that data to the template data
     $areaAcc = new \TMT\accessor\AreaAccessor();
     $employeeAcc = new \TMT\accessor\Employee();
     $linkAcc = new \TMT\accessor\Links();
     // Determine if user is admin or superuser
     $admin = $this->isAdmin();
     $su = $this->isSuperuser();
     // Get user and area information
     $user = $employeeAcc->get($this->user['netId']);
     $areaArray = $areaAcc->getAll($this->user['netId']);
     $areas = array();
     if (isset($this->user['area'])) {
         foreach ($areaArray as $area) {
             $areas[] = array('id' => $area->ID, 'name' => $area->longName);
         }
         // Retrieve link tree
         $links = $linkAcc->getTree($this->user['area']);
         $this->cleanLinkTree($links, $admin, $su);
     }
     // Check environment
     $environment = $this->getEnvironment();
     // Get quicklinks
     $quicklinks = $this->getAccessor("Quicklinks")->getByUser($this->user['netId']);
     $notificationsUrl = getenv("NOTIFICATIONSURL");
     // Add data necessary for the main header and footer to load properly
     $data['templateData'] = array("area" => isset($this->user['area']) ? $this->user['area'] : null, "areaName" => isset($this->user['area']) ? $areaAcc->get($this->user['area'])->longName : null, "areaGuid" => isset($this->user['areaGuid']) ? $this->user['areaGuid'] : null, "areas" => $areas, "authenticated" => $this->authenticated, "canSU" => $this->canBeSuperuser(), "environment" => $environment, "firstName" => $user->firstName, "isSU" => $su, "jwt" => $this->createJWT(), "lastName" => $user->lastName, "links" => isset($links) ? $links : null, "netId" => $this->user['netId'], "notificationsUrl" => $notificationsUrl, "quicklinks" => $quicklinks, "server" => $_SERVER['SERVER_NAME']);
     // load twig
     $twigLoader = new \Twig_Loader_Filesystem(self::VIEWS_PATH);
     $twig = new \Twig_Environment($twigLoader);
     // to avoid conflicts with angularjs use of {{ }}
     $lexer = new \Twig_Lexer($twig, array('tag_comment' => array('[#', '#]'), 'tag_block' => array('[%', '%]'), 'tag_variable' => array('[[', ']]'), 'interpolation' => array('#[', ']')));
     $twig->setLexer($lexer);
     // render a view
     echo $twig->render($view . self::VIEW_FILE_TYPE, $data);
 }
开发者ID:byu-oit-ssengineering,项目名称:team-managment-tool,代码行数:44,代码来源:App.php

示例9: renderTwig

 /**
  * Render a twig file with custom twig tags.
  *
  * @param string $template
  * @param array  $parameters
  * @param string $sourceDir
  *
  * @return string
  */
 public function renderTwig($template, array $parameters, $sourceDir)
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array($sourceDir)), array('debug' => true, 'cache' => false, 'strict_variables' => true, 'autoescape' => false));
     // Ruby erb template syntax
     $lexer = new \Twig_Lexer($twig, array('tag_comment' => array('<%#', '%>'), 'tag_block' => array('<%', '%>'), 'tag_variable' => array('<%=', '%>')));
     $twig->setLexer($lexer);
     return $twig->render($template, $parameters);
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:17,代码来源:KunstmaanGenerator.php

示例10: getSonata_Formatter_Twig_Env_TextService

 /**
  * Gets the 'sonata.formatter.twig.env.text' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * This service is private.
  * If you want to be able to request this service from the container directly,
  * make it public, otherwise you might end up with broken code.
  *
  * @return \Twig_Environment A Twig_Environment instance.
  */
 protected function getSonata_Formatter_Twig_Env_TextService()
 {
     $this->services['sonata.formatter.twig.env.text'] = $instance = new \Twig_Environment(new \Sonata\FormatterBundle\Twig\Loader\LoaderSelector(new \Twig_Loader_String(), $this->get('twig.loader')), array('debug' => false, 'strict_variables' => false, 'charset' => 'UTF-8'));
     $instance->addExtension(new \Twig_Extension_Sandbox(new \Sonata\FormatterBundle\Twig\SecurityPolicyContainerAware($this, array(0 => 'sonata.formatter.twig.control_flow', 1 => 'sonata.formatter.twig.gist', 2 => 'sonata.media.formatter.twig')), true));
     $instance->addExtension($this->get('sonata.formatter.twig.control_flow'));
     $instance->addExtension($this->get('sonata.formatter.twig.gist'));
     $instance->addExtension($this->get('sonata.media.formatter.twig'));
     $instance->setLexer(new \Twig_Lexer($instance, array('tag_comment' => array(0 => '<#', 1 => '#>'), 'tag_block' => array(0 => '<%', 1 => '%>'), 'tag_variable' => array(0 => '<%=', 1 => '%>'))));
     return $instance;
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:22,代码来源:appDevDebugProjectContainer.php


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