本文整理汇总了PHP中Twig_Environment::isDebug方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::isDebug方法的具体用法?PHP Twig_Environment::isDebug怎么用?PHP Twig_Environment::isDebug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Environment
的用法示例。
在下文中一共展示了Twig_Environment::isDebug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compress
public function compress($html)
{
if (!$this->twig->isDebug() || $this->forceCompression) {
return $this->parser->compress($html);
}
return $html;
}
示例2: configure
/**
* Loads the Twig instance and registers the autoloader.
*/
public function configure()
{
parent::configure();
$this->configuration = $this->context->getConfiguration();
// template name
$template = sfConfig::get('sf_template');
$templateDir = sfConfig::get('sf_template_dir') . '/' . $template;
if (!file_exists($templateDir)) {
throw new sfException(__METHOD__ . ": Couldn't find template " . $template);
}
// decorator template path
$layoutTemplateDir = $templateDir . '/global';
if (is_readable($layoutTemplateDir . '/' . $this->getDecoratorTemplate())) {
$this->setDecoratorDirectory($layoutTemplateDir);
}
// module template path
$moduleTemplateDir = $templateDir . '/modules/' . $this->moduleName;
if (is_readable($moduleTemplateDir . '/' . $this->getTemplate())) {
$this->setDirectory($moduleTemplateDir);
}
// init twig engine
// empty array becuase it changes based on the rendering context
$this->loader = new Twig_Loader_Filesystem(array());
$this->twig = new sfTwigEnvironment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir') . '/' . $template, 'debug' => sfConfig::get('sf_debug', false), 'sf_context' => $this->context));
if ($this->twig->isDebug()) {
$this->twig->setAutoReload(true);
}
$this->loadExtensions();
}
示例3: output
public function output(FieldDescriptionInterface $fieldDescription, $content)
{
if ($this->environment->isDebug()) {
return sprintf("\n<!-- START - fieldName: %s, template: %s -->\n%s\n<!-- END - fieldName: %s -->", $fieldDescription->getFieldName(), $fieldDescription->getTemplate(), $content, $fieldDescription->getFieldName());
}
return $content;
}
示例4: initExtensions
/**
* Инициализируется расширения, необходимые для работы
*/
private function initExtensions()
{
if ($this->engine->isDebug()) {
$this->engine->addExtension(new \Twig_Extension_Debug());
}
$this->engine->addExtension(new BitrixExtension());
$this->engine->addExtension(new CustomFunctionsExtension());
}
示例5: configure
/**
* Loads the Twig instance and registers the autoloader.
*
* @return void
*/
public function configure()
{
parent::configure();
$this->configuration = $this->context->getConfiguration();
//Empty array becuase it changes based on the rendering context
$this->loader = new Twig_Loader_Filesystem(array());
$this->twig = new Twig_Environment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir'), 'debug' => sfConfig::get('sf_debug', false)));
if ($this->twig->isDebug()) {
$this->twig->setCache(null);
$this->twig->setAutoReload(true);
}
$this->loadExtensions();
}
示例6: configure
/**
* Loads the Twig instance and registers the autoloader.
*/
public function configure()
{
parent::configure();
$this->configuration = $this->context->getConfiguration();
require_once sfConfig::get('sf_twig_lib_dir', dirname(__FILE__) . '/../lib/vendor/Twig/lib') . '/Twig/Autoloader.php';
Twig_Autoloader::register();
// empty array becuase it changes based on the rendering context
$this->loader = new Twig_Loader_Filesystem(array());
$this->twig = new sfTwigEnvironment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir'), 'debug' => sfConfig::get('sf_debug', false), 'sf_context' => $this->context));
if ($this->twig->isDebug()) {
$this->twig->enableAutoReload();
$this->twig->setCache(null);
}
$this->loadExtensions();
}
示例7: dump
/**
* {@inheritdoc}
*/
public function dump(\Twig_Environment $env, $context)
{
if (!$env->isDebug()) {
return null;
}
if (func_num_args() === 2) {
$vars = [];
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
$vars[$key] = $value;
}
}
$vars = [$vars];
} else {
$vars = func_get_args();
unset($vars[0], $vars[1]);
}
$output = fopen('php://memory', 'r+b');
$prevOutput = $this->dumper->setOutput($output);
foreach ($vars as $value) {
$this->dumper->dump($this->cloner->cloneVar($value));
}
$this->dumper->setOutput($prevOutput);
rewind($output);
return stream_get_contents($output);
}
示例8: dump
/**
* {@inheritdoc}
*/
public function dump(\Twig_Environment $env, $context)
{
// Return if 'debug' is `false` in Twig, or there's no logged on user _and_ `debug_show_loggedoff` in
// config.yml is `false`.
if (!$env->isDebug() || $this->users->getCurrentUser() === null && !$this->debugShowLoggedoff) {
return null;
}
if (func_num_args() === 2) {
$vars = [];
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
$vars[$key] = $value;
}
}
$vars = [$vars];
} else {
$vars = func_get_args();
unset($vars[0], $vars[1]);
}
$output = fopen('php://memory', 'r+b');
$prevOutput = $this->dumper->setOutput($output);
foreach ($vars as $value) {
$this->dumper->dump($this->cloner->cloneVar($value));
}
$this->dumper->setOutput($prevOutput);
rewind($output);
return stream_get_contents($output);
}
示例9: content
public function content($key, $type, array $arguments = array(), $default='') {
$debugmessage = '';
if ($this->env->isDebug()) {
$debugmessage .= "<!--debug IbrowsSimpleCMS\n";
$debugmessage .= "type=$type \n";
$debugmessage .= "key=$key \n";
$debugmessage .= "default=$default \n";
$debugmessage .= "arguments=" . print_r($arguments, true) . " \n";
$debugmessage .= '-->';
if ($default == '') {
$default = "$key-$type";
}
}
$obj = $this->manager->find($type, $key);
if ($obj) {
$out = $debugmessage . $obj->toHTML($this, $arguments);
} else {
$out = $default;
}
$grant = $this->handler->isGranted('ibrows_simple_cms_content_edit_key', array('key'=> $key,'type'=>$type ));
//$grant = $this->handler->isGranted('ibrows_simple_cms_content');
if(!$grant){
return $out;
}
return $this->wrapOutputForEdit($out, $key, $type, $arguments, $default);
}
示例10: dump
public function dump(\Twig_Environment $env, $context)
{
if (!$env->isDebug() || !$this->cloner) {
return;
}
if (2 === func_num_args()) {
$vars = array();
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
$vars[$key] = $value;
}
}
$vars = array($vars);
} else {
$vars = func_get_args();
unset($vars[0], $vars[1]);
}
$html = '';
$dumper = new HtmlDumper(function ($line, $depth) use(&$html) {
if (-1 !== $depth) {
$html .= str_repeat(' ', $depth) . $line . "\n";
}
});
foreach ($vars as $value) {
$dumper->dump($this->cloner->cloneVar($value));
}
return $html;
}
示例11: dump
public function dump(\Twig_Environment $env, $context)
{
if (!$env->isDebug()) {
return;
}
if (2 === func_num_args()) {
$vars = array();
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
$vars[$key] = $value;
}
}
$vars = array($vars);
} else {
$vars = func_get_args();
unset($vars[0], $vars[1]);
}
$dump = fopen('php://memory', 'r+b');
$dumper = new HtmlDumper($dump);
foreach ($vars as $value) {
$dumper->dump($this->cloner->cloneVar($value));
}
rewind($dump);
return stream_get_contents($dump);
}
示例12: getInstance
private static function getInstance()
{
if (self::$instance) {
return self::$instance;
}
$loader = new BitrixLoader($_SERVER['DOCUMENT_ROOT']);
$c = Configuration::getInstance();
$config = $c->get('maximaster');
$twigConfig = (array) $config['tools']['twig'];
$defaultConfig = array('debug' => false, 'charset' => SITE_CHARSET, 'cache' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/maximaster/tools.twig', 'auto_reload' => isset($_GET['clear_cache']) && strtoupper($_GET['clear_cache']) == 'Y', 'autoescape' => false);
$twigOptions = array_merge($defaultConfig, $twigConfig);
$twig = new \Twig_Environment($loader, $twigOptions);
if ($twig->isDebug()) {
$twig->addExtension(new \Twig_Extension_Debug());
}
$twig->addExtension(new BitrixExtension());
$twig->addExtension(new CustomFunctionsExtension());
$event = new Event('', 'onAfterTwigTemplateEngineInited', array($twig));
$event->send();
if ($event->getResults()) {
foreach ($event->getResults() as $evenResult) {
if ($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS) {
$twig = current($evenResult->getParameters());
}
}
}
return self::$instance = $twig;
}
示例13: output
/**
* @param FieldDescriptionInterface $fieldDescription
* @param \Twig_Template $template
* @param array $parameters
*
* @return string
*/
public function output(FieldDescriptionInterface $fieldDescription, \Twig_Template $template, array $parameters = array())
{
$content = $template->render($parameters);
if ($this->environment->isDebug()) {
return sprintf("\n<!-- START \n fieldName: %s\n template: %s\n compiled template: %s\n -->\n%s\n<!-- END - fieldName: %s -->", $fieldDescription->getFieldName(), $fieldDescription->getTemplate(), $template->getTemplateName(), $content, $fieldDescription->getFieldName());
}
return $content;
}
示例14: refFunction
/**
* @param Twig_Environment $env
* @param array $context
* @return string
*/
function refFunction(Twig_Environment $env, array $context)
{
if (!$env->isDebug()) {
return '';
}
ob_start();
r(2 === func_num_args() ? $context : array_slice(func_get_args(), 2));
return ob_get_clean();
}
示例15: compile
/**
* Compiles the node to PHP.
*
* @param \Twig_Compiler A Twig_Compiler instance
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$location = $this->listener_directory . $this->getNode('expr')->getAttribute('name');
foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path) {
$ext_namespace = str_replace('/', '_', $ext_namespace);
if ($this->environment->isDebug()) {
// If debug mode is enabled, lets check for new/removed EVENT
// templates on page load rather than at compile. This is
// slower, but makes developing extensions easier (no need to
// purge the cache when a new event template file is added)
$compiler->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n")->indent();
}
if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) {
$compiler->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n")->write("\$this->env->loadTemplate('@{$ext_namespace}/{$location}.html')->display(\$context);\n")->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n");
}
if ($this->environment->isDebug()) {
$compiler->outdent()->write("}\n\n");
}
}
}