Skip to content

Commit

Permalink
feature #1729 moved protected to private (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.0-dev branch.

Discussion
----------

moved protected to private

Moved some protected properties/methods from protected to private.

I've changed protected properties/methods mostly on internal classes but not where it could potentially break BC too badly with existing code.

Classes where we could change protected to private but where it could be a problem for existing code:

* Twig_ExpressionParser
* Twig_Environment
* Twig_Lexer
* Twig_Node
* Twig_Parser (done in second commit)
* Twig_Template

closes #1645

Commits
-------

56a3791 moved protected to private (more)
dbd0c91 moved protected to private
  • Loading branch information
fabpot committed Jul 15, 2015
2 parents 4e58c48 + 56a3791 commit a3b7fcb
Show file tree
Hide file tree
Showing 29 changed files with 115 additions and 115 deletions.
16 changes: 8 additions & 8 deletions lib/Twig/Compiler.php
Expand Up @@ -17,14 +17,14 @@
*/
class Twig_Compiler
{
protected $lastLine;
protected $source;
protected $indentation;
protected $env;
protected $debugInfo;
protected $sourceOffset;
protected $sourceLine;
protected $filename;
private $lastLine;
private $source;
private $indentation;
private $env;
private $debugInfo;
private $sourceOffset;
private $sourceLine;
private $filename;

/**
* Constructor.
Expand Down
10 changes: 5 additions & 5 deletions lib/Twig/Error.php
Expand Up @@ -33,9 +33,9 @@
*/
class Twig_Error extends Exception
{
protected $lineno;
protected $filename;
protected $rawMessage;
private $lineno;
private $filename;
private $rawMessage;

/**
* Constructor.
Expand Down Expand Up @@ -130,7 +130,7 @@ public function guess()
$this->updateRepr();
}

protected function updateRepr()
private function updateRepr()
{
$this->message = $this->rawMessage;

Expand Down Expand Up @@ -158,7 +158,7 @@ protected function updateRepr()
}
}

protected function guessTemplateInfo()
private function guessTemplateInfo()
{
$template = null;
$templateClass = null;
Expand Down
8 changes: 4 additions & 4 deletions lib/Twig/ExpressionParser.php
Expand Up @@ -25,9 +25,9 @@ class Twig_ExpressionParser
const OPERATOR_LEFT = 1;
const OPERATOR_RIGHT = 2;

protected $parser;
protected $unaryOperators;
protected $binaryOperators;
private $parser;
private $unaryOperators;
private $binaryOperators;

public function __construct(Twig_Parser $parser, array $unaryOperators, array $binaryOperators)
{
Expand Down Expand Up @@ -592,7 +592,7 @@ protected function getFilterNodeClass($name, $line)
}

// checks that the node only contains "constant" elements
protected function checkConstantExpression(Twig_Node $node)
private function checkConstantExpression(Twig_Node $node)
{
if (!($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array
|| $node instanceof Twig_Node_Expression_Unary_Neg || $node instanceof Twig_Node_Expression_Unary_Pos
Expand Down
10 changes: 5 additions & 5 deletions lib/Twig/Extension/Core.php
Expand Up @@ -15,10 +15,10 @@
*/
class Twig_Extension_Core extends Twig_Extension
{
protected $dateFormats = array('F j, Y H:i', '%d days');
protected $numberFormat = array(0, '.', ',');
protected $timezone = null;
protected $escapers = array();
private $dateFormats = array('F j, Y H:i', '%d days');
private $numberFormat = array(0, '.', ',');
private $timezone = null;
private $escapers = array();

/**
* Defines a new escaper to be used via the escape filter.
Expand Down Expand Up @@ -307,7 +307,7 @@ public function parseTestExpression(Twig_Parser $parser, Twig_Node $node)
return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine());
}

protected function getTestName(Twig_Parser $parser, $line)
private function getTestName(Twig_Parser $parser, $line)
{
$stream = $parser->getStream();
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Extension/Escaper.php
Expand Up @@ -10,7 +10,7 @@
*/
class Twig_Extension_Escaper extends Twig_Extension
{
protected $defaultStrategy;
private $defaultStrategy;

public function __construct($defaultStrategy = 'html')
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Extension/Optimizer.php
Expand Up @@ -10,7 +10,7 @@
*/
class Twig_Extension_Optimizer extends Twig_Extension
{
protected $optimizers;
private $optimizers;

public function __construct($optimizers = -1)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Twig/Extension/Sandbox.php
Expand Up @@ -10,9 +10,9 @@
*/
class Twig_Extension_Sandbox extends Twig_Extension
{
protected $sandboxedGlobally;
protected $sandboxed;
protected $policy;
private $sandboxedGlobally;
private $sandboxed;
private $policy;

public function __construct(Twig_Sandbox_SecurityPolicyInterface $policy, $sandboxed = false)
{
Expand Down
12 changes: 6 additions & 6 deletions lib/Twig/Extension/Staging.php
Expand Up @@ -18,12 +18,12 @@
*/
class Twig_Extension_Staging extends Twig_Extension
{
protected $functions = array();
protected $filters = array();
protected $visitors = array();
protected $tokenParsers = array();
protected $globals = array();
protected $tests = array();
private $functions = array();
private $filters = array();
private $visitors = array();
private $tokenParsers = array();
private $globals = array();
private $tests = array();

public function addFunction(Twig_Function $function)
{
Expand Down
8 changes: 4 additions & 4 deletions lib/Twig/Filter.php
Expand Up @@ -16,10 +16,10 @@
*/
class Twig_Filter
{
protected $name;
protected $callable;
protected $options;
protected $arguments = array();
private $name;
private $callable;
private $options;
private $arguments = array();

public function __construct($name, $callable, array $options = array())
{
Expand Down
8 changes: 4 additions & 4 deletions lib/Twig/Function.php
Expand Up @@ -18,10 +18,10 @@
*/
class Twig_Function
{
protected $name;
protected $callable;
protected $options;
protected $arguments = array();
private $name;
private $callable;
private $options;
private $arguments = array();

public function __construct($name, $callable, array $options = array())
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Loader/Array.php
Expand Up @@ -23,7 +23,7 @@
*/
class Twig_Loader_Array implements Twig_LoaderInterface
{
protected $templates = array();
private $templates = array();

/**
* Constructor.
Expand Down
4 changes: 2 additions & 2 deletions lib/Twig/Markup.php
Expand Up @@ -16,8 +16,8 @@
*/
class Twig_Markup implements Countable
{
protected $content;
protected $charset;
private $content;
private $charset;

public function __construct($content, $charset)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Twig/Node/CheckSecurity.php
Expand Up @@ -14,9 +14,9 @@
*/
class Twig_Node_CheckSecurity extends Twig_Node
{
protected $usedFilters;
protected $usedTags;
protected $usedFunctions;
private $usedFilters;
private $usedTags;
private $usedFunctions;

public function __construct(array $usedFilters, array $usedTags, array $usedFunctions)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Node/Expression/Array.php
Expand Up @@ -10,7 +10,7 @@
*/
class Twig_Node_Expression_Array extends Twig_Node_Expression
{
protected $index;
private $index;

public function __construct(array $elements, $lineno)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Node/Expression/Name.php
Expand Up @@ -11,7 +11,7 @@
*/
class Twig_Node_Expression_Name extends Twig_Node_Expression
{
protected $specialVars = array(
private $specialVars = array(
'_self' => '$this',
'_context' => '$context',
'_charset' => '$this->env->getCharset()',
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Node/Expression/Test/Defined.php
Expand Up @@ -38,7 +38,7 @@ public function __construct(Twig_Node $node, $name, Twig_Node $arguments = null,
}
}

protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
private function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
{
$node->setAttribute('ignore_strict_check', true);

Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Node/For.php
Expand Up @@ -17,7 +17,7 @@
*/
class Twig_Node_For extends Twig_Node
{
protected $loop;
private $loop;

public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_Node $body, Twig_Node $else = null, $lineno, $tag = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Node/SandboxedPrint.php
Expand Up @@ -50,7 +50,7 @@ public function compile(Twig_Compiler $compiler)
*
* @return Twig_Node
*/
protected function removeNodeFilter($node)
private function removeNodeFilter($node)
{
if ($node instanceof Twig_Node_Expression_Filter) {
return $this->removeNodeFilter($node->getNode('node'));
Expand Down
6 changes: 3 additions & 3 deletions lib/Twig/NodeTraverser.php
Expand Up @@ -18,8 +18,8 @@
*/
class Twig_NodeTraverser
{
protected $env;
protected $visitors;
private $env;
private $visitors;

/**
* Constructor.
Expand Down Expand Up @@ -69,7 +69,7 @@ public function traverse(Twig_Node $node)
return $node;
}

protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_Node $node = null)
private function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_Node $node = null)
{
if (null === $node) {
return;
Expand Down
22 changes: 11 additions & 11 deletions lib/Twig/NodeVisitor/Escaper.php
Expand Up @@ -16,12 +16,12 @@
*/
class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface
{
protected $statusStack = array();
protected $blocks = array();
protected $safeAnalysis;
protected $traverser;
protected $defaultStrategy = false;
protected $safeVars = array();
private $statusStack = array();
private $blocks = array();
private $safeAnalysis;
private $traverser;
private $defaultStrategy = false;
private $safeVars = array();

public function __construct()
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public function leaveNode(Twig_Node $node, Twig_Environment $env)
return $node;
}

protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type)
private function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env, $type)
{
if (false === $type) {
return $node;
Expand All @@ -102,7 +102,7 @@ protected function escapePrintNode(Twig_Node_Print $node, Twig_Environment $env,
);
}

protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env)
private function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig_Environment $env)
{
$name = $filter->getNode('filter')->getAttribute('value');

Expand All @@ -121,7 +121,7 @@ protected function preEscapeFilterNode(Twig_Node_Expression_Filter $filter, Twig
return $filter;
}

protected function isSafeFor($type, Twig_Node $expression, $env)
private function isSafeFor($type, Twig_Node $expression, $env)
{
$safe = $this->safeAnalysis->getSafe($expression);

Expand All @@ -139,7 +139,7 @@ protected function isSafeFor($type, Twig_Node $expression, $env)
return in_array($type, $safe) || in_array('all', $safe);
}

protected function needEscaping(Twig_Environment $env)
private function needEscaping(Twig_Environment $env)
{
if (count($this->statusStack)) {
return $this->statusStack[count($this->statusStack) - 1];
Expand All @@ -148,7 +148,7 @@ protected function needEscaping(Twig_Environment $env)
return $this->defaultStrategy ? $this->defaultStrategy : false;
}

protected function getEscaperFilter($type, Twig_Node $node)
private function getEscaperFilter($type, Twig_Node $node)
{
$line = $node->getLine();
$name = new Twig_Node_Expression_Constant('escape', $line);
Expand Down

0 comments on commit a3b7fcb

Please sign in to comment.