本文整理汇总了PHP中Twig_NodeInterface::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_NodeInterface::getAttribute方法的具体用法?PHP Twig_NodeInterface::getAttribute怎么用?PHP Twig_NodeInterface::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_NodeInterface
的用法示例。
在下文中一共展示了Twig_NodeInterface::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compileString
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
{
if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value');
} elseif ($body instanceof \Twig_Node_Text) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
}
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
if (version_compare(\Twig_Environment::VERSION, '1.5', '>=')) {
foreach ($matches[1] as $var) {
$key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
if (!$vars->hasElement($key)) {
$vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
}
}
} else {
$current = array();
foreach ($vars as $name => $var) {
$current[$name] = true;
}
foreach ($matches[1] as $var) {
if (!isset($current['%' . $var . '%'])) {
$vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
}
}
}
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
}
示例2: enterNode
/**
* Called before child nodes are visited.
*
* @param Twig_NodeInterface $node The node to visit
* @param Twig_Environment $env The Twig environment instance
*
* @return Twig_NodeInterface The modified node
*/
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
$this->inAModule = true;
$this->tags = array();
$this->filters = array();
$this->functions = array();
return $node;
} elseif ($this->inAModule) {
// look for tags
if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) {
$this->tags[$node->getNodeTag()] = $node;
}
// look for filters
if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) {
$this->filters[$node->getNode('filter')->getAttribute('value')] = $node;
}
// look for functions
if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) {
$this->functions[$node->getAttribute('name')] = $node;
}
// wrap print to check __toString() calls
if ($node instanceof Twig_Node_Print) {
return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getLine(), $node->getNodeTag());
}
}
return $node;
}
示例3: enterNode
/**
* Called before child nodes are visited.
*
* @param Twig_NodeInterface $node The node to visit
* @param Twig_Environment $env The Twig environment instance
*
* @param Twig_NodeInterface The modified node
*/
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_AutoEscape) {
$this->statusStack[] = $node->getAttribute('value');
} elseif ($node instanceof Twig_Node_Block) {
$this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
}
return $node;
}
示例4: enterNode
/**
* Called before child nodes are visited.
*
* @param Twig_NodeInterface $node The node to visit
* @param Twig_Environment $env The Twig environment instance
*
* @return Twig_NodeInterface The modified node
*/
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
if ($env->hasExtension('escaper') && ($defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename')))) {
$this->defaultStrategy = $defaultStrategy;
}
} elseif ($node instanceof Twig_Node_AutoEscape) {
$this->statusStack[] = $node->getAttribute('value');
} elseif ($node instanceof Twig_Node_Block) {
$this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
}
return $node;
}
示例5: leaveNode
/**
* {@inheritdoc}
*/
public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
$varName = $this->getVarName();
$node->setNode('display_start', new Twig_Node(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getAttribute('filename'), $varName), $node->getNode('display_start'))));
$node->setNode('display_end', new Twig_Node(array(new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end'))));
} elseif ($node instanceof Twig_Node_Block) {
$varName = $this->getVarName();
$node->setNode('body', new Twig_Node_Body(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), $node->getNode('body'), new Twig_Profiler_Node_LeaveProfile($varName))));
} elseif ($node instanceof Twig_Node_Macro) {
$varName = $this->getVarName();
$node->setNode('body', new Twig_Node_Body(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName), $node->getNode('body'), new Twig_Profiler_Node_LeaveProfile($varName))));
}
return $node;
}
示例6: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
{
if ($node instanceof \Twig_Node_Expression_Function && 'constant' === $node->getAttribute('name') && 1 === $node->count() && null !== ($resolved = $this->resolve($node))) {
return $this->resolve($node);
}
return $node;
}
示例7: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Expression_Name) {
print $node->getAttribute('name') . "\n";
}
return $node;
}
示例8: compile
/**
* Compiles a node.
*
* @param Twig_NodeInterface $node The node to compile
* @param int $indentation The current indentation
*
* @return Twig_Compiler The current compiler instance
*/
public function compile(Twig_NodeInterface $node, $indentation = 0)
{
$this->lastLine = null;
$this->source = '';
$this->debugInfo = array();
$this->sourceOffset = 0;
// source code starts at 1 (as we then increment it when we encounter new lines)
$this->sourceLine = 1;
$this->indentation = $indentation;
if ($node instanceof Twig_Node_Module) {
$node->setFilename($node->getAttribute('filename'));
// to be removed in 2.0
$this->filename = $node->getAttribute('filename');
}
$node->compile($this);
return $this;
}
示例9: leaveNode
/**
* Called after child nodes are visited.
*
* @param Twig_NodeInterface $node The node to visit
* @param Twig_Environment $env The Twig environment instance
*
* @param Twig_NodeInterface The modified node
*/
public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) {
array_pop($this->statusStack);
} elseif ($node instanceof Twig_Node_BlockReference) {
$this->blocks[$node->getAttribute('name')] = $this->needEscaping($env);
}
return $node;
}
示例10: compileString
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
{
if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value');
} elseif ($body instanceof \Twig_Node_Text) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
}
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
foreach ($matches[1] as $var) {
$key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
if (!$vars->hasElement($key)) {
$vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
}
}
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
}
示例11: leaveNode
public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env)
{
if ($node instanceof TwigJsNode) {
if ($node->hasAttribute('name')) {
$this->moduleNode->setAttribute('twig_js_name', $node->getAttribute('name'));
}
return false;
}
return $node;
}
示例12: compileString
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
{
if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value');
} elseif ($body instanceof \Twig_Node_Text) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
}
$current = array();
foreach ($vars as $name => $var) {
$current[$name] = true;
}
preg_match_all('/\\%([^\\%]+)\\%/', $msg, $matches);
foreach ($matches[1] as $var) {
if (!isset($current['%' . $var . '%'])) {
$vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
}
}
return array(new \Twig_Node_Expression_Constant(trim($msg), $body->getLine()), $vars);
}
示例13: leaveNode
public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env)
{
if ($node instanceof \Twig_Node_Module) {
$this->currentModule = null;
} elseif ($node instanceof \Twig_Node_Expression_Function) {
$name = $node->getAttribute('name');
if ('render_documents' == $name) {
$this->currentRenderDocuments = null;
}
}
return $node;
}
示例14: compileString
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
{
if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value');
} elseif ($body instanceof \Twig_Node_Text) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
}
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
foreach ($matches[1] as $var) {
$key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
if (!$vars->hasElement($key)) {
if ('count' === $var && null !== $this->getNode('count')) {
$vars->addElement($this->getNode('count'), $key);
} else {
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
$vars->addElement($varExpr, $key);
}
}
}
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
}
示例15: enterNode
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
{
$this->stack[] = $node;
if ($node instanceof \Twig_Node_Expression_Function) {
$name = $node->getAttribute('name');
if (in_array($name, $this->methodNames)) {
$args = $node->getNode('arguments');
switch ($name) {
case '_n':
case '_fn':
$id = $args->getNode(0)->getAttribute('value') . '|' . $args->getNode(1)->getAttribute('value');
break;
default:
case '__f':
case '__':
$id = $args->getNode(0)->getAttribute('value');
break;
}
// obtain translation domain from composer file
$composerPath = str_replace($this->file->getRelativePathname(), '', $this->file->getPathname());
if (isset(self::$domainCache[$composerPath])) {
$domain = self::$domainCache[$composerPath];
} else {
$scanner = new Scanner();
$scanner->scan(array($composerPath), 1);
$metaData = $scanner->getModulesMetaData(true);
$domains = array_keys($metaData);
if (isset($domains[0])) {
$domain = strtolower($domains[0]);
// cache result of file lookup
self::$domainCache[$composerPath] = $domain;
} else {
$domain = 'messages';
}
}
$domainNode = array_search($name, $this->methodNames);
$domain = $args->hasNode($domainNode) ? $args->getNode($domainNode)->getAttribute('value') : $domain;
$message = new Message($id, $domain);
$message->addSource(new FileSource((string) $this->file, $node->getLine()));
$this->catalogue->add($message);
}
}
return $node;
}