mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-20 14:36:57 +00:00
add some more DocComments / type hints
This commit is contained in:
@@ -22,7 +22,7 @@ interface Twig_CompilerInterface
|
||||
*
|
||||
* @param Twig_NodeInterface $node The node to compile
|
||||
*
|
||||
* @return Twig_Compiler The current compiler instance
|
||||
* @return Twig_CompilerInterface The current compiler instance
|
||||
*/
|
||||
function compile(Twig_NodeInterface $node);
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ class Twig_ExpressionParser
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function getFunctionNode($node)
|
||||
public function getFunctionNode(Twig_Node_Expression_Name $node)
|
||||
{
|
||||
$args = $this->parseArguments();
|
||||
|
||||
|
||||
@@ -171,18 +171,18 @@ class Twig_Extension_Core extends Twig_Extension
|
||||
);
|
||||
}
|
||||
|
||||
public function parseNotTestExpression($parser, $node)
|
||||
public function parseNotTestExpression(Twig_Parser $parser, $node)
|
||||
{
|
||||
return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($parser, $node), $parser->getCurrentToken()->getLine());
|
||||
}
|
||||
|
||||
public function parseTestExpression($parser, $node)
|
||||
public function parseTestExpression(Twig_Parser $parser, $node)
|
||||
{
|
||||
$stream = $parser->getStream();
|
||||
$name = $stream->expect(Twig_Token::NAME_TYPE);
|
||||
$arguments = null;
|
||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
||||
$arguments = $parser->getExpressionParser()->parseArguments($node);
|
||||
$arguments = $parser->getExpressionParser()->parseArguments();
|
||||
}
|
||||
|
||||
return new Twig_Node_Expression_Test($node, $name->getValue(), $arguments, $parser->getCurrentToken()->getLine());
|
||||
|
||||
@@ -26,6 +26,8 @@ interface Twig_FilterInterface
|
||||
|
||||
function needsEnvironment();
|
||||
|
||||
function needsContext();
|
||||
|
||||
function getSafe(Twig_Node $filterArgs);
|
||||
|
||||
function getPreEscape();
|
||||
|
||||
@@ -27,5 +27,7 @@ interface Twig_FunctionInterface
|
||||
|
||||
function needsEnvironment();
|
||||
|
||||
function needsContext();
|
||||
|
||||
function getSafe(Twig_Node $filterArgs);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class Twig_NodeTraverser
|
||||
return $node;
|
||||
}
|
||||
|
||||
protected function traverseForVisitor($visitor, Twig_NodeInterface $node = null)
|
||||
protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null)
|
||||
{
|
||||
if (null === $node) {
|
||||
return null;
|
||||
|
||||
@@ -245,6 +245,11 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
array_shift($this->importedFunctions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the expression parser.
|
||||
*
|
||||
* @return Twig_ExpressionParser The expression parser
|
||||
*/
|
||||
public function getExpressionParser()
|
||||
{
|
||||
return $this->expressionParser;
|
||||
@@ -260,11 +265,21 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the token stream.
|
||||
*
|
||||
* @return Twig_TokenStream The token stream
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current token.
|
||||
*
|
||||
* @return Twig_Token The current token
|
||||
*/
|
||||
public function getCurrentToken()
|
||||
{
|
||||
return $this->stream->getCurrent();
|
||||
|
||||
+6
-8
@@ -59,16 +59,14 @@ class Twig_Token
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the current token for a type.
|
||||
* Tests the current token for a type and/or a value.
|
||||
*
|
||||
* The first argument is the type
|
||||
* of the token (if not given Twig_Token::NAME_TYPE), the second the
|
||||
* value of the token (if not given value is not checked).
|
||||
* Parameters may be:
|
||||
* * just type
|
||||
* * type and value (or array of possible values)
|
||||
* * just value (or array of possible values) (NAME_TYPE is used as type)
|
||||
*
|
||||
* The token value can be an array if multiple checks should be
|
||||
* performed.
|
||||
*
|
||||
* @param integer $type The type to test
|
||||
* @param array|integer $type The type to test
|
||||
* @param array|string|null $values The token value
|
||||
*
|
||||
* @return Boolean
|
||||
|
||||
@@ -41,7 +41,7 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser
|
||||
return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd($token)
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endautoescape');
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser
|
||||
return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd($token)
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endblock');
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class Twig_TokenParser_Filter extends Twig_TokenParser
|
||||
return new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd($token)
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endfilter');
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ class Twig_TokenParser_For extends Twig_TokenParser
|
||||
return new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideForFork($token)
|
||||
public function decideForFork(Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('else', 'endfor'));
|
||||
}
|
||||
|
||||
public function decideForEnd($token)
|
||||
public function decideForEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endfor');
|
||||
}
|
||||
|
||||
@@ -57,12 +57,12 @@ class Twig_TokenParser_If extends Twig_TokenParser
|
||||
return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideIfFork($token)
|
||||
public function decideIfFork(Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('elseif', 'else', 'endif'));
|
||||
}
|
||||
|
||||
public function decideIfEnd($token)
|
||||
public function decideIfEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('endif'));
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class Twig_TokenParser_Macro extends Twig_TokenParser
|
||||
return null;
|
||||
}
|
||||
|
||||
public function decideBlockEnd($token)
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endmacro');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class Twig_TokenParser_Sandbox extends Twig_TokenParser
|
||||
return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd($token)
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endsandbox');
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class Twig_TokenParser_Set extends Twig_TokenParser
|
||||
return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd($token)
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endset');
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Twig_TokenParser_Spaceless extends Twig_TokenParser
|
||||
return new Twig_Node_Spaceless($body, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideSpacelessEnd($token)
|
||||
public function decideSpacelessEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endspaceless');
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array|Iterable $parsers An Iterable of Twig_TokenParserInterface instances
|
||||
* @param array|Iterable $brokers An Iterable of Twig_TokenParserBrokerInterface instances
|
||||
* @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances
|
||||
* @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances
|
||||
*/
|
||||
public function __construct($parsers = array(), $brokers = array())
|
||||
{
|
||||
@@ -97,10 +97,10 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
|
||||
public function setParser(Twig_ParserInterface $parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
foreach($this->parsers as $tokenParser) {
|
||||
foreach ($this->parsers as $tokenParser) {
|
||||
$tokenParser->setParser($parser);
|
||||
}
|
||||
foreach($this->brokers as $broker) {
|
||||
foreach ($this->brokers as $broker) {
|
||||
$broker->setParser($parser);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user