forked from kolber/stacey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgraded to newer Twig to use |filters etc
- From this pull kolber#91 + Specified variables for search in app/cache.inc.php on line 71/72
- Loading branch information
Ole Sletten
committed
Feb 19, 2015
1 parent
e292bed
commit 6065c06
Showing
181 changed files
with
9,319 additions
and
6,234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,28 +12,30 @@ | |
/** | ||
* Autoloads Twig classes. | ||
* | ||
* @package twig | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class Twig_Autoloader | ||
{ | ||
/** | ||
* Registers Twig_Autoloader as an SPL autoloader. | ||
* | ||
* @param Boolean $prepend Whether to prepend the autoloader or not. | ||
*/ | ||
static public function register() | ||
public static function register($prepend = false) | ||
{ | ||
ini_set('unserialize_callback_func', 'spl_autoload_call'); | ||
spl_autoload_register(array(new self, 'autoload')); | ||
if (version_compare(phpversion(), '5.3.0', '>=')) { | ||
spl_autoload_register(array(new self, 'autoload'), true, $prepend); | ||
} else { | ||
spl_autoload_register(array(new self, 'autoload')); | ||
} | ||
} | ||
|
||
/** | ||
* Handles autoloading of classes. | ||
* | ||
* @param string $class A class name. | ||
* | ||
* @return boolean Returns true if the class has been loaded | ||
* @param string $class A class name. | ||
*/ | ||
static public function autoload($class) | ||
public static function autoload($class) | ||
{ | ||
if (0 !== strpos($class, 'Twig')) { | ||
return; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,18 @@ | |
/** | ||
* Compiles a node to PHP code. | ||
* | ||
* @package twig | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class Twig_Compiler implements Twig_CompilerInterface | ||
{ | ||
protected $lastLine; | ||
protected $source; | ||
protected $indentation; | ||
protected $env; | ||
protected $debugInfo; | ||
protected $sourceOffset; | ||
protected $sourceLine; | ||
protected $filename; | ||
|
||
/** | ||
* Constructor. | ||
|
@@ -31,6 +34,12 @@ class Twig_Compiler implements Twig_CompilerInterface | |
public function __construct(Twig_Environment $env) | ||
{ | ||
$this->env = $env; | ||
$this->debugInfo = array(); | ||
} | ||
|
||
public function getFilename() | ||
{ | ||
return $this->filename; | ||
} | ||
|
||
/** | ||
|
@@ -56,17 +65,24 @@ public function getSource() | |
/** | ||
* Compiles a node. | ||
* | ||
* @param Twig_NodeInterface $node The node to compile | ||
* @param integer $indent The current indentation | ||
* @param Twig_NodeInterface $node The node to compile | ||
* @param integer $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->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) { | ||
$this->filename = $node->getAttribute('filename'); | ||
} | ||
|
||
$node->compile($this); | ||
|
||
return $this; | ||
|
@@ -86,7 +102,7 @@ public function subcompile(Twig_NodeInterface $node, $raw = true) | |
/** | ||
* Adds a raw string to the compiled code. | ||
* | ||
* @param string $string The string | ||
* @param string $string The string | ||
* | ||
* @return Twig_Compiler The current compiler instance | ||
*/ | ||
|
@@ -113,6 +129,11 @@ public function write() | |
return $this; | ||
} | ||
|
||
/** | ||
* Appends an indentation to the current PHP code after compilation. | ||
* | ||
* @return Twig_Compiler The current compiler instance | ||
*/ | ||
public function addIndentation() | ||
{ | ||
$this->source .= str_repeat(' ', $this->indentation * 4); | ||
|
@@ -123,7 +144,7 @@ public function addIndentation() | |
/** | ||
* Adds a quoted string to the compiled code. | ||
* | ||
* @param string $string The string | ||
* @param string $value The string | ||
* | ||
* @return Twig_Compiler The current compiler instance | ||
*/ | ||
|
@@ -137,19 +158,27 @@ public function string($value) | |
/** | ||
* Returns a PHP representation of a given value. | ||
* | ||
* @param mixed $value The value to convert | ||
* @param mixed $value The value to convert | ||
* | ||
* @return Twig_Compiler The current compiler instance | ||
*/ | ||
public function repr($value) | ||
{ | ||
if (is_int($value) || is_float($value)) { | ||
if (false !== $locale = setlocale(LC_NUMERIC, 0)) { | ||
setlocale(LC_NUMERIC, 'C'); | ||
} | ||
|
||
$this->raw($value); | ||
} else if (null === $value) { | ||
|
||
if (false !== $locale) { | ||
setlocale(LC_NUMERIC, $locale); | ||
} | ||
} elseif (null === $value) { | ||
$this->raw('null'); | ||
} else if (is_bool($value)) { | ||
} elseif (is_bool($value)) { | ||
$this->raw($value ? 'true' : 'false'); | ||
} else if (is_array($value)) { | ||
} elseif (is_array($value)) { | ||
$this->raw('array('); | ||
$i = 0; | ||
foreach ($value as $key => $value) { | ||
|
@@ -178,17 +207,35 @@ public function repr($value) | |
public function addDebugInfo(Twig_NodeInterface $node) | ||
{ | ||
if ($node->getLine() != $this->lastLine) { | ||
$this->lastLine = $node->getLine(); | ||
$this->write("// line {$node->getLine()}\n"); | ||
|
||
// when mbstring.func_overload is set to 2 | ||
// mb_substr_count() replaces substr_count() | ||
// but they have different signatures! | ||
if (((int) ini_get('mbstring.func_overload')) & 2) { | ||
// this is much slower than the "right" version | ||
$this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n"); | ||
} else { | ||
$this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); | ||
} | ||
$this->sourceOffset = strlen($this->source); | ||
$this->debugInfo[$this->sourceLine] = $node->getLine(); | ||
|
||
$this->lastLine = $node->getLine(); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function getDebugInfo() | ||
{ | ||
return $this->debugInfo; | ||
} | ||
|
||
/** | ||
* Indents the generated code. | ||
* | ||
* @param integer $indent The number of indentation to add | ||
* @param integer $step The number of indentation to add | ||
* | ||
* @return Twig_Compiler The current compiler instance | ||
*/ | ||
|
@@ -202,18 +249,19 @@ public function indent($step = 1) | |
/** | ||
* Outdents the generated code. | ||
* | ||
* @param integer $indent The number of indentation to remove | ||
* @param integer $step The number of indentation to remove | ||
* | ||
* @return Twig_Compiler The current compiler instance | ||
*/ | ||
public function outdent($step = 1) | ||
{ | ||
$this->indentation -= $step; | ||
|
||
if ($this->indentation < 0) { | ||
throw new Twig_Error('Unable to call outdent() as the indentation would become negative'); | ||
// can't outdent by more steps than the current indentation level | ||
if ($this->indentation < $step) { | ||
throw new LogicException('Unable to call outdent() as the indentation would become negative'); | ||
} | ||
|
||
$this->indentation -= $step; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,24 +12,24 @@ | |
/** | ||
* Interface implemented by compiler classes. | ||
* | ||
* @package twig | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Fabien Potencier <[email protected]> | ||
* @deprecated since 1.12 (to be removed in 2.0) | ||
*/ | ||
interface Twig_CompilerInterface | ||
{ | ||
/** | ||
* Compiles a node. | ||
* | ||
* @param Twig_NodeInterface $node The node to compile | ||
* @param Twig_NodeInterface $node The node to compile | ||
* | ||
* @return Twig_CompilerInterface The current compiler instance | ||
*/ | ||
function compile(Twig_NodeInterface $node); | ||
public function compile(Twig_NodeInterface $node); | ||
|
||
/** | ||
* Gets the current PHP code after compilation. | ||
* | ||
* @return string The PHP code | ||
*/ | ||
function getSource(); | ||
public function getSource(); | ||
} |
Oops, something went wrong.