本文整理汇总了PHP中Twig_Environment::setParser方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::setParser方法的具体用法?PHP Twig_Environment::setParser怎么用?PHP Twig_Environment::setParser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Environment
的用法示例。
在下文中一共展示了Twig_Environment::setParser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createTwigEnvironment
/**
* Create twig environment with the options specified in the curry cms configuration.
*
* @param Twig_LoaderInterface $loader
* @return Twig_Environment
*/
private static function createTwigEnvironment(Twig_LoaderInterface $loader)
{
$options = Curry_Core::$config->curry->template->options->toArray();
$twig = new Twig_Environment($loader, $options);
$twig->setParser(new Curry_Twig_Parser($twig));
$twig->addTokenParser(new Curry_Twig_TokenParser_Placeholder());
$twig->addTokenParser(new Curry_Twig_TokenParser_Ia());
$twig->addFunction('url', new Twig_Function_Function('url'));
$twig->addFunction('L', new Twig_Function_Function('L'));
$twig->addFunction('round', new Twig_Function_Function('round'));
$twig->addFilter('ldate', new Twig_Filter_Function('Curry_Twig_Template::ldate'));
$twig->addFilter('dump', new Twig_Filter_Function('var_dump'));
return $twig;
}
示例2: boot
public function boot()
{
// Create services
$this->singleton('logger', array($this, 'getLogger'));
$this->singleton('cache', array($this, 'getCache'));
$this->singleton('index', array($this, 'getIndex'));
$this->singleton('autoloader', array($this, 'getAutoloader'));
// some more
$app = $this;
$this->singleton('dispatcher', function () use($app) {
return new EventDispatcher();
});
$this->singleton('resolver', function () use($app) {
return new ControllerResolver($app->logger);
});
$this->singleton('kernel', function () use($app) {
return new HttpKernel($app->dispatcher, $app->resolver, $app->requestStack);
});
$this->singleton('requestStack', function () use($app) {
return new RequestStack();
});
$this->singleton('backend', function () use($app) {
return new Backend($app);
});
$this->singleton('whoopsHandler', function () use($app) {
if (PHP_SAPI === 'cli') {
return new PlainTextHandler();
} else {
if ($this['developmentMode']) {
return new PrettyPageHandler();
} else {
return new CallbackHandler(array($app, 'showException'));
}
}
});
$this->singleton('whoops', function () use($app) {
$whoops = new \Whoops\Run();
$whoops->pushHandler($app->whoopsHandler);
// Send error mail
if ($app['errorNotification']) {
$whoops->pushHandler(array($app, 'sendErrorNotification'));
}
// Add error to log
$whoops->pushHandler(function (\Exception $e) use($app) {
$app->logger->error($e->getMessage(), array('exception' => $e));
return Handler::DONE;
});
return $whoops;
});
$this->singleton('twig', function () use($app) {
$loader = new \Twig_Loader_Filesystem($app['template.root']);
$options = $app['template.options'];
$twig = new \Twig_Environment($loader, $options);
$twig->setParser(new \Curry_Twig_Parser($twig));
$twig->addTokenParser(new \Curry_Twig_TokenParser_Placeholder());
$twig->addTokenParser(new \Curry_Twig_TokenParser_Ia());
$twig->addFunction('url', new \Twig_Function_Function('url'));
$twig->addFunction('L', new \Twig_Function_Function('L'));
$twig->addFunction('round', new \Twig_Function_Function('round'));
$twig->addFilter('ldate', new \Twig_Filter_Function('\\Curry\\App::ldate'));
$twig->addFilter('dump', new \Twig_Filter_Function('var_dump'));
return $twig;
});
$this->whoops->register();
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$this->logger->warning('Magic quotes gpc is enabled, please disable!');
}
// TODO: remove this!
$this->globals = (object) array('ProjectName' => $this['name'], 'BaseUrl' => $this['baseUrl'], 'DevelopmentMode' => $this['developmentMode']);
// Try to set utf-8 locale
$arguments = (array) $this['locale'];
array_unshift($arguments, LC_ALL);
$locale = call_user_func_array('setlocale', $arguments);
$this->logger->debug($locale ? 'Set default locale to ' . $locale : 'Unable to set default locale');
// Set default umask
if ($this['umask'] !== false) {
umask($this['umask']);
}
self::initErrorHandling();
self::initPropel();
URL::setDefaultBaseUrl($this['baseUrl']);
URL::setDefaultSecret($this['secret']);
if ($this['autoPublish']) {
$this->autoPublish();
}
if ($this['sharedController']) {
$this->logger->notice('Using php routing for curry shared folder');
$this->dispatcher->addSubscriber(new StaticContent('/shared/', $app['basePath'] . '/shared'));
}
if ($app['backend.basePath']) {
$this->dispatcher->addSubscriber($app->backend);
}
if (class_exists('Page')) {
$this->dispatcher->addSubscriber(new Frontend($this));
}
$this->dispatcher->addSubscriber(new FileNotFound($this));
$this->dispatcher->addSubscriber(new Generator\ModuleProfiler($app->logger));
$this->dispatcher->addSubscriber(new Generator\ModuleCacher($app->cache));
$this->dispatcher->addSubscriber(new Generator\ModuleHtmlHead());
$this->dispatcher->addSubscriber(new Generator\LiveEdit($this));
//.........这里部分代码省略.........