本文整理汇总了PHP中Twig_Compiler::repr方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Compiler::repr方法的具体用法?PHP Twig_Compiler::repr怎么用?PHP Twig_Compiler::repr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Compiler
的用法示例。
在下文中一共展示了Twig_Compiler::repr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Compiles the node to PHP.
*
* @param \Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$vars = $this->getNode('vars');
$defaults = new \Twig_Node_Expression_Array(array(), -1);
if ($vars instanceof \Twig_Node_Expression_Array) {
$defaults = $this->getNode('vars');
$vars = null;
}
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
$method = null === $this->getNode('count') ? 'trans' : 'transChoice';
$compiler->write('echo $this->env->getExtension(\'translator\')->getTranslator()->' . $method . '(')->subcompile($msg);
$compiler->raw(', ');
if (null !== $this->getNode('count')) {
$compiler->subcompile($this->getNode('count'))->raw(', ');
}
if (null !== $vars) {
$compiler->raw('array_merge(')->subcompile($defaults)->raw(', ')->subcompile($this->getNode('vars'))->raw(')');
} else {
$compiler->subcompile($defaults);
}
$compiler->raw(', ');
if (null === $this->getNode('domain')) {
$compiler->repr('messages');
} else {
$compiler->subcompile($this->getNode('domain'));
}
if (null !== $this->getNode('locale')) {
$compiler->raw(', ')->subcompile($this->getNode('locale'));
}
$compiler->raw(");\n");
}
示例2: compile
public function compile(Twig_Compiler $compiler)
{
$name = $this->getAttribute('name');
$compiler->addDebugInfo($this);
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
}
} elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]);
} elseif ($this->getAttribute('always_defined')) {
$compiler->raw('$context[')->string($name)->raw(']');
} else {
if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
$compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : null)');
} else {
// When Twig will require PHP 7.0, the Template::notFound() method
// will be removed and the code inlined like this:
// (function () { throw new Exception(...); })();
$compiler->raw('(isset($context[')->string($name)->raw(']) || array_key_exists(')->string($name)->raw(', $context) ? $context[')->string($name)->raw('] : $this->notFound(')->string($name)->raw(', ')->repr($this->lineno)->raw('))');
}
}
}
示例3: compileDefaults
protected function compileDefaults(\Twig_Compiler $compiler, \Twig_Node_Expression_Array $defaults)
{
$compiler->raw('array(');
foreach ($defaults as $name => $default) {
$compiler->repr($name)->raw(' => ')->subcompile($default)->raw(', ');
}
$compiler->raw(')');
}
示例4: compileAssetUrl
private function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset)
{
$compiler->repr($asset->getTargetPath());
if (file_exists(PUB_DIR . DS . $asset->getTargetPath())) {
return;
}
$writer = new \Assetic\AssetWriter(PUB_DIR . DS);
$writer->writeAsset($asset);
}
示例5: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('array(');
$first = true;
foreach ($this->nodes as $name => $node) {
if (!$first) {
$compiler->raw(', ');
}
$first = false;
$compiler->repr($name)->raw(' => ')->subcompile($node);
}
$compiler->raw(')');
}
示例6: testReprNumericValueWithLocale
public function testReprNumericValueWithLocale()
{
$compiler = new Twig_Compiler(new Twig_Environment());
$locale = setlocale(LC_NUMERIC, 0);
if (false === $locale) {
$this->markTestSkipped('Your platform does not support locales.');
}
$required_locales = ['fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'];
if (false === setlocale(LC_NUMERIC, $required_locales)) {
$this->markTestSkipped('Could not set any of required locales: ' . implode(", ", $required_locales));
}
$this->assertEquals('1.2', $compiler->repr(1.2)->getSource());
$this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
setlocale(LC_NUMERIC, $locale);
}
示例7: compile
public function compile(Twig_Compiler $compiler)
{
$name = $this->getAttribute('name');
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
}
} elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]);
} else {
$compiler->raw('$this->getContext($context, ')->string($name)->raw(')');
}
}
示例8: compile
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('$this->env->view->getHelper(');
$compiler->repr($this->getAttribute('helper'));
$compiler->raw(')->' . $this->getAttribute('helper') . '(');
$first = true;
foreach ($this->getNode('args') as $arg) {
if (!$first) {
$compiler->raw(', ');
}
$first = false;
$compiler->subcompile($arg);
}
$compiler->raw(")");
}
示例9: compile
public function compile(Twig_Compiler $compiler)
{
static $specialVars = array('_self' => '$this', '_context' => '$context', '_charset' => '$this->env->getCharset()');
$name = $this->getAttribute('name');
if ($this->hasAttribute('is_defined_test')) {
if (isset($specialVars[$name])) {
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
}
} elseif (isset($specialVars[$name])) {
$compiler->raw($specialVars[$name]);
} else {
$compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
}
}
示例10: compileAssetUrl
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
if (!($vars = $asset->getVars())) {
$compiler->repr($asset->getTargetPath());
return;
}
$compiler->raw("strtr(")->string($asset->getTargetPath())->raw(", array(");
$first = true;
foreach ($vars as $var) {
if (!$first) {
$compiler->raw(", ");
}
$first = false;
$compiler->string("{" . $var . "}")->raw(" => \$context['assetic']['vars']['{$var}']");
}
$compiler->raw("))");
}
示例11: compile
public function compile(Twig_Compiler $compiler)
{
$name = $this->getAttribute('name');
$compiler->addDebugInfo($this);
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
if ('_self' === $name) {
@trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED);
}
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
}
} elseif ($this->isSpecial()) {
if ('_self' === $name) {
@trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED);
}
$compiler->raw($this->specialVars[$name]);
} elseif ($this->getAttribute('always_defined')) {
$compiler->raw('$context[')->string($name)->raw(']');
} else {
// remove the non-PHP 5.4 version when PHP 5.3 support is dropped
// as the non-optimized version is just a workaround for slow ternary operator
// when the context has a lot of variables
if (PHP_VERSION_ID >= 50400) {
// PHP 5.4 ternary operator performance was optimized
$compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : ');
if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
$compiler->raw('null)');
} else {
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
}
} else {
$compiler->raw('$this->getContext($context, ')->string($name);
if ($this->getAttribute('ignore_strict_check')) {
$compiler->raw(', true');
}
$compiler->raw(')');
}
}
}
示例12: compile
public function compile(Twig_Compiler $compiler)
{
$name = $this->getAttribute('name');
$compiler->addDebugInfo($this);
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
}
} elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]);
} elseif ($this->getAttribute('always_defined')) {
$compiler->raw('$context[')->string($name)->raw(']');
} else {
if (PHP_VERSION_ID >= 70000) {
// use PHP 7 null coalescing operator
$compiler->raw('($context[')->string($name)->raw('] ?? ');
if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
$compiler->raw('null)');
} else {
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
}
} elseif (PHP_VERSION_ID >= 50400) {
// PHP 5.4 ternary operator performance was optimized
$compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : ');
if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
$compiler->raw('null)');
} else {
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
}
} else {
$compiler->raw('$this->getContext($context, ')->string($name);
if ($this->getAttribute('ignore_strict_check')) {
$compiler->raw(', true');
}
$compiler->raw(')');
}
}
}
示例13: compile
public function compile(Twig_Compiler $compiler)
{
$name = $this->getAttribute('name');
$compiler->addDebugInfo($this);
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
}
} elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]);
} elseif ($this->getAttribute('always_defined')) {
$compiler->raw('$context[')->string($name)->raw(']');
} else {
$compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : ');
if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
$compiler->raw('null)');
} else {
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
}
}
}
示例14: compile
public function compile(Twig_Compiler $compiler)
{
$name = $this->getAttribute('name');
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
} else {
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
}
} elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]);
} else {
if (version_compare(phpversion(), '5.4.0RC1', '>=') && ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables())) {
// PHP 5.4 ternary operator performance was optimized
$compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : null)');
} else {
$compiler->raw('$this->getContext($context, ')->string($name);
if ($this->getAttribute('ignore_strict_check')) {
$compiler->raw(', true');
}
$compiler->raw(')');
}
}
}
示例15: compileAssetUrl
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
$compiler->repr($asset->getTargetPath());
}