moved more methods/properties to private

This commit is contained in:
Fabien Potencier
2015-08-18 17:15:53 +02:00
parent 7de9a57b92
commit 905a2a8102
5 changed files with 67 additions and 67 deletions
+29 -29
View File
@@ -18,32 +18,32 @@ class Twig_Environment
{ {
const VERSION = '2.0.0-DEV'; const VERSION = '2.0.0-DEV';
protected $charset; private $charset;
protected $loader; private $loader;
protected $debug; private $debug;
protected $autoReload; private $autoReload;
protected $cache; private $cache;
protected $lexer; private $lexer;
protected $parser; private $parser;
protected $compiler; private $compiler;
protected $baseTemplateClass; private $baseTemplateClass;
protected $extensions; private $extensions;
protected $parsers; private $parsers;
protected $visitors; private $visitors;
protected $filters; private $filters;
protected $tests; private $tests;
protected $functions; private $functions;
protected $globals; private $globals;
protected $runtimeInitialized; private $runtimeInitialized;
protected $extensionInitialized; private $extensionInitialized;
protected $loadedTemplates; private $loadedTemplates;
protected $strictVariables; private $strictVariables;
protected $unaryOperators; private $unaryOperators;
protected $binaryOperators; private $binaryOperators;
protected $templateClassPrefix = '__TwigTemplate_'; private $templateClassPrefix = '__TwigTemplate_';
protected $functionCallbacks; private $functionCallbacks;
protected $filterCallbacks; private $filterCallbacks;
protected $staging; private $staging;
/** /**
* Constructor. * Constructor.
@@ -1088,7 +1088,7 @@ class Twig_Environment
return array_keys($alternatives); return array_keys($alternatives);
} }
protected function initGlobals() private function initGlobals()
{ {
$globals = array(); $globals = array();
foreach ($this->extensions as $extension) { foreach ($this->extensions as $extension) {
@@ -1105,7 +1105,7 @@ class Twig_Environment
return call_user_func_array('array_merge', $globals); return call_user_func_array('array_merge', $globals);
} }
protected function initExtensions() private function initExtensions()
{ {
if ($this->extensionInitialized) { if ($this->extensionInitialized) {
return; return;
@@ -1126,7 +1126,7 @@ class Twig_Environment
$this->initExtension($this->staging); $this->initExtension($this->staging);
} }
protected function initExtension(Twig_ExtensionInterface $extension) private function initExtension(Twig_ExtensionInterface $extension)
{ {
// filters // filters
foreach ($extension->getFilters() as $filter) { foreach ($extension->getFilters() as $filter) {
+6 -6
View File
@@ -62,7 +62,7 @@ class Twig_ExpressionParser
return $expr; return $expr;
} }
protected function getPrimary() private function getPrimary()
{ {
$token = $this->parser->getCurrentToken(); $token = $this->parser->getCurrentToken();
@@ -84,7 +84,7 @@ class Twig_ExpressionParser
return $this->parsePrimaryExpression(); return $this->parsePrimaryExpression();
} }
protected function parseConditionalExpression($expr) private function parseConditionalExpression($expr)
{ {
while ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, '?')) { while ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, '?')) {
if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) { if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) {
@@ -105,12 +105,12 @@ class Twig_ExpressionParser
return $expr; return $expr;
} }
protected function isUnary(Twig_Token $token) private function isUnary(Twig_Token $token)
{ {
return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]);
} }
protected function isBinary(Twig_Token $token) private function isBinary(Twig_Token $token)
{ {
return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]);
} }
@@ -561,7 +561,7 @@ class Twig_ExpressionParser
return new Twig_Node($targets); return new Twig_Node($targets);
} }
protected function getFunctionNodeClass($name, $line) private function getFunctionNodeClass($name, $line)
{ {
$env = $this->parser->getEnvironment(); $env = $this->parser->getEnvironment();
@@ -577,7 +577,7 @@ class Twig_ExpressionParser
return $function->getNodeClass(); return $function->getNodeClass();
} }
protected function getFilterNodeClass($name, $line) private function getFilterNodeClass($name, $line)
{ {
$env = $this->parser->getEnvironment(); $env = $this->parser->getEnvironment();
+28 -28
View File
@@ -17,21 +17,21 @@
*/ */
class Twig_Lexer class Twig_Lexer
{ {
protected $tokens; private $tokens;
protected $code; private $code;
protected $cursor; private $cursor;
protected $lineno; private $lineno;
protected $end; private $end;
protected $state; private $state;
protected $states; private $states;
protected $brackets; private $brackets;
protected $env; private $env;
protected $filename; private $filename;
protected $options; private $options;
protected $regexes; private $regexes;
protected $position; private $position;
protected $positions; private $positions;
protected $currentVarBlockLine; private $currentVarBlockLine;
const STATE_DATA = 0; const STATE_DATA = 0;
const STATE_BLOCK = 1; const STATE_BLOCK = 1;
@@ -139,7 +139,7 @@ class Twig_Lexer
return new Twig_TokenStream($this->tokens, $this->filename); return new Twig_TokenStream($this->tokens, $this->filename);
} }
protected function lexData() private function lexData()
{ {
// if no matches are left we return the rest of the template as simple text token // if no matches are left we return the rest of the template as simple text token
if ($this->position == count($this->positions[0]) - 1) { if ($this->position == count($this->positions[0]) - 1) {
@@ -195,7 +195,7 @@ class Twig_Lexer
} }
} }
protected function lexBlock() private function lexBlock()
{ {
if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) { if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) {
$this->pushToken(Twig_Token::BLOCK_END_TYPE); $this->pushToken(Twig_Token::BLOCK_END_TYPE);
@@ -206,7 +206,7 @@ class Twig_Lexer
} }
} }
protected function lexVar() private function lexVar()
{ {
if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) { if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) {
$this->pushToken(Twig_Token::VAR_END_TYPE); $this->pushToken(Twig_Token::VAR_END_TYPE);
@@ -217,7 +217,7 @@ class Twig_Lexer
} }
} }
protected function lexExpression() private function lexExpression()
{ {
// whitespace // whitespace
if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) { if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) {
@@ -285,7 +285,7 @@ class Twig_Lexer
} }
} }
protected function lexRawData() private function lexRawData()
{ {
if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
throw new Twig_Error_Syntax('Unexpected end of file: Unclosed "verbatim" block', $this->lineno, $this->filename); throw new Twig_Error_Syntax('Unexpected end of file: Unclosed "verbatim" block', $this->lineno, $this->filename);
@@ -301,7 +301,7 @@ class Twig_Lexer
$this->pushToken(Twig_Token::TEXT_TYPE, $text); $this->pushToken(Twig_Token::TEXT_TYPE, $text);
} }
protected function lexComment() private function lexComment()
{ {
if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
throw new Twig_Error_Syntax('Unclosed comment', $this->lineno, $this->filename); throw new Twig_Error_Syntax('Unclosed comment', $this->lineno, $this->filename);
@@ -310,7 +310,7 @@ class Twig_Lexer
$this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
} }
protected function lexString() private function lexString()
{ {
if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) { if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) {
$this->brackets[] = array($this->options['interpolation'][0], $this->lineno); $this->brackets[] = array($this->options['interpolation'][0], $this->lineno);
@@ -331,7 +331,7 @@ class Twig_Lexer
} }
} }
protected function lexInterpolation() private function lexInterpolation()
{ {
$bracket = end($this->brackets); $bracket = end($this->brackets);
if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) { if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) {
@@ -344,7 +344,7 @@ class Twig_Lexer
} }
} }
protected function pushToken($type, $value = '') private function pushToken($type, $value = '')
{ {
// do not push empty text tokens // do not push empty text tokens
if (Twig_Token::TEXT_TYPE === $type && '' === $value) { if (Twig_Token::TEXT_TYPE === $type && '' === $value) {
@@ -354,13 +354,13 @@ class Twig_Lexer
$this->tokens[] = new Twig_Token($type, $value, $this->lineno); $this->tokens[] = new Twig_Token($type, $value, $this->lineno);
} }
protected function moveCursor($text) private function moveCursor($text)
{ {
$this->cursor += strlen($text); $this->cursor += strlen($text);
$this->lineno += substr_count($text, "\n"); $this->lineno += substr_count($text, "\n");
} }
protected function getOperatorRegex() private function getOperatorRegex()
{ {
$operators = array_merge( $operators = array_merge(
array('='), array('='),
@@ -390,13 +390,13 @@ class Twig_Lexer
return '/'.implode('|', $regex).'/A'; return '/'.implode('|', $regex).'/A';
} }
protected function pushState($state) private function pushState($state)
{ {
$this->states[] = $this->state; $this->states[] = $this->state;
$this->state = $state; $this->state = $state;
} }
protected function popState() private function popState()
{ {
if (0 === count($this->states)) { if (0 === count($this->states)) {
throw new Exception('Cannot pop state without a previous state'); throw new Exception('Cannot pop state without a previous state');
+1 -1
View File
@@ -17,7 +17,7 @@
class Twig_Loader_Chain implements Twig_LoaderInterface class Twig_Loader_Chain implements Twig_LoaderInterface
{ {
private $hasSourceCache = array(); private $hasSourceCache = array();
protected $loaders = array(); private $loaders = array();
/** /**
* Constructor. * Constructor.
+3 -3
View File
@@ -202,12 +202,12 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
throw new Twig_Error_Loader($this->errorCache[$name]); throw new Twig_Error_Loader($this->errorCache[$name]);
} }
protected function normalizeName($name) private function normalizeName($name)
{ {
return preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); return preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
} }
protected function parseName($name, $default = self::MAIN_NAMESPACE) private function parseName($name, $default = self::MAIN_NAMESPACE)
{ {
if (isset($name[0]) && '@' == $name[0]) { if (isset($name[0]) && '@' == $name[0]) {
if (false === $pos = strpos($name, '/')) { if (false === $pos = strpos($name, '/')) {
@@ -223,7 +223,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface
return array($default, $name); return array($default, $name);
} }
protected function validateName($name) private function validateName($name)
{ {
if (false !== strpos($name, "\0")) { if (false !== strpos($name, "\0")) {
throw new Twig_Error_Loader('A template name cannot contain NUL bytes.'); throw new Twig_Error_Loader('A template name cannot contain NUL bytes.');