/**
* Registers Twig_Autoloader as an SPL autoloader.
*/
- static public function register()
+ public static function register()
{
ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(new self, 'autoload'));
*
* @param string $class A class name.
*/
- static public function autoload($class)
+ public static function autoload($class)
{
if (0 !== strpos($class, 'Twig')) {
return;
*
* @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();
}
*/
interface Twig_ExistsLoaderInterface
{
-
/**
* Check if we have the source code of a template, given its name.
*
if (0 === strlen($hex)) {
$hex = '0';
}
+
return '\\'.$hex.' ';
}
* Per OWASP recommendations, we'll use hex entities for any other
* characters where a named entity does not exist.
*/
+
return sprintf('&#x%s;', $hex);
}
}
}
// and byte fallback
-else
-{
+else {
/**
* Returns the length of a variable.
*
*
* @param Twig_Environment $environment The current Twig_Environment instance
*/
- function initRuntime(Twig_Environment $environment);
+ public function initRuntime(Twig_Environment $environment);
/**
* Returns the token parser instances to add to the existing list.
*
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
*/
- function getTokenParsers();
+ public function getTokenParsers();
/**
* Returns the node visitor instances to add to the existing list.
*
* @return array An array of Twig_NodeVisitorInterface instances
*/
- function getNodeVisitors();
+ public function getNodeVisitors();
/**
* Returns a list of filters to add to the existing list.
*
* @return array An array of filters
*/
- function getFilters();
+ public function getFilters();
/**
* Returns a list of tests to add to the existing list.
*
* @return array An array of tests
*/
- function getTests();
+ public function getTests();
/**
* Returns a list of functions to add to the existing list.
*
* @return array An array of functions
*/
- function getFunctions();
+ public function getFunctions();
/**
* Returns a list of operators to add to the existing list.
*
* @return array An array of operators
*/
- function getOperators();
+ public function getOperators();
/**
* Returns a list of global variables to add to the existing list.
*
* @return array An array of global variables
*/
- function getGlobals();
+ public function getGlobals();
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
- function getName();
+ public function getName();
}
*
* @return string The PHP code for the filter
*/
- function compile();
+ public function compile();
- function needsEnvironment();
+ public function needsEnvironment();
- function needsContext();
+ public function needsContext();
- function getSafe(Twig_Node $filterArgs);
+ public function getSafe(Twig_Node $filterArgs);
- function getPreservesSafety();
+ public function getPreservesSafety();
- function getPreEscape();
+ public function getPreEscape();
- function setArguments($arguments);
+ public function setArguments($arguments);
- function getArguments();
+ public function getArguments();
}
*
* @return string The PHP code for the function
*/
- function compile();
+ public function compile();
- function needsEnvironment();
+ public function needsEnvironment();
- function needsContext();
+ public function needsContext();
- function getSafe(Twig_Node $filterArgs);
+ public function getSafe(Twig_Node $filterArgs);
- function setArguments($arguments);
+ public function setArguments($arguments);
- function getArguments();
+ public function getArguments();
}
*
* @return Twig_TokenStream A token stream instance
*/
- function tokenize($code, $filename = null);
+ public function tokenize($code, $filename = null);
}
*
* @throws Twig_Error_Loader When $name is not found
*/
- function getSource($name);
+ public function getSource($name);
/**
* Gets the cache key to use for the cache for a given template name.
*
* @throws Twig_Error_Loader When $name is not found
*/
- function getCacheKey($name);
+ public function getCacheKey($name);
/**
* Returns true if the template is still fresh.
*
* @throws Twig_Error_Loader When $name is not found
*/
- function isFresh($name, $time);
+ public function isFresh($name, $time);
}
*
* @param string The attribute name
*
- * @return mixed The attribute value
+ * @return mixed The attribute value
*/
public function getAttribute($name)
{
->indent()
->subcompile($this->getNode('body'))
->outdent()
- ->write("} catch(Exception \$e) {\n")
+ ->write("} catch (Exception \$e) {\n")
->indent()
->write("ob_end_clean();\n\n")
->write("throw \$e;\n")
parent::compileDisplayFooter($compiler);
$compiler
- ->write("protected function checkSecurity() {\n")
+ ->write("protected function checkSecurity()\n", "{\n")
->indent()
->write("\$this->env->getExtension('sandbox')->checkSecurity(\n")
->indent()
*
* @param Twig_Compiler A Twig_Compiler instance
*/
- function compile(Twig_Compiler $compiler);
+ public function compile(Twig_Compiler $compiler);
- function getLine();
+ public function getLine();
- function getNodeTag();
+ public function getNodeTag();
}
*
* @return Twig_NodeInterface The modified node
*/
- function enterNode(Twig_NodeInterface $node, Twig_Environment $env);
+ public function enterNode(Twig_NodeInterface $node, Twig_Environment $env);
/**
* Called after child nodes are visited.
*
* @return Twig_NodeInterface The modified node
*/
- function leaveNode(Twig_NodeInterface $node, Twig_Environment $env);
+ public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env);
/**
* Returns the priority for this visitor.
*
* @return integer The priority level
*/
- function getPriority();
+ public function getPriority();
}
*
* @return Twig_Node_Module A node tree
*/
- function parse(Twig_TokenStream $stream);
+ public function parse(Twig_TokenStream $stream);
}
*/
interface Twig_Sandbox_SecurityPolicyInterface
{
- function checkSecurity($tags, $filters, $functions);
+ public function checkSecurity($tags, $filters, $functions);
- function checkMethodAllowed($obj, $method);
+ public function checkMethodAllowed($obj, $method);
- function checkPropertyAllowed($obj, $method);
+ public function checkPropertyAllowed($obj, $method);
}
*/
abstract class Twig_Template implements Twig_TemplateInterface
{
- static protected $cache = array();
+ protected static $cache = array();
protected $parent;
protected $parents;
/**
* This method is only useful when testing Twig. Do not use it.
*/
- static public function clearCache()
+ public static function clearCache()
{
self::$cache = array();
}
*
* @return string The rendered template
*/
- function render(array $context);
+ public function render(array $context);
/**
* Displays the template with the given context.
* @param array $context An array of parameters to pass to the template
* @param array $blocks An array of blocks to pass to the template
*/
- function display(array $context, array $blocks = array());
+ public function display(array $context, array $blocks = array());
/**
* Returns the bound environment for this template.
*
* @return Twig_Environment The current environment
*/
- function getEnvironment();
+ public function getEnvironment();
}
$expected = trim($match[3], "\n ");
- if ($expected != $output) {
+ if ($expected != $output) {
echo 'Compiled template that failed:';
- foreach (array_keys($templates) as $name) {
+ foreach (array_keys($templates) as $name) {
echo "Template: $name\n";
$source = $loader->getSource($name);
echo $twig->compile($twig->parse($twig->tokenize($source, $name)));
*
* @return string The PHP code for the test
*/
- function compile();
+ public function compile();
}
*
* @return string The string representation
*/
- static public function typeToString($type, $short = false, $line = -1)
+ public static function typeToString($type, $short = false, $line = -1)
{
switch ($type) {
case self::EOF_TYPE:
*
* @return string The string representation
*/
- static public function typeToEnglish($type, $line = -1)
+ public static function typeToEnglish($type, $line = -1)
{
switch ($type) {
case self::EOF_TYPE:
*
* @return null|Twig_TokenParserInterface A Twig_TokenParserInterface or null if no suitable TokenParser was found
*/
- function getTokenParser($tag);
+ public function getTokenParser($tag);
/**
* Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows of.
*
* @param Twig_ParserInterface $parser A Twig_ParserInterface interface
*/
- function setParser(Twig_ParserInterface $parser);
+ public function setParser(Twig_ParserInterface $parser);
/**
* Gets the Twig_ParserInterface.
*
* @return null|Twig_ParserInterface A Twig_ParserInterface instance or null
*/
- function getParser();
+ public function getParser();
}
*
* @param $parser A Twig_Parser instance
*/
- function setParser(Twig_Parser $parser);
+ public function setParser(Twig_Parser $parser);
/**
* Parses a token and returns a node.
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
- function parse(Twig_Token $token);
+ public function parse(Twig_Token $token);
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
- function getTag();
+ public function getTag();
}
class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase
{
- static protected $params, $templates;
+ protected static $params, $templates;
public function setUp()
{
class FooObject
{
- static public $called = array('__toString' => 0, 'foo' => 0, 'getFooBar' => 0);
+ public static $called = array('__toString' => 0, 'foo' => 0, 'getFooBar' => 0);
public $bar = 'bar';
- static public function reset()
+ public static function reset()
{
self::$called = array('__toString' => 0, 'foo' => 0, 'getFooBar' => 0);
}
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_AutoEscapeTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_BlockReferenceTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_BlockTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_DoTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_ForTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_IfTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_ImportTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_IncludeTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
{
/**
ob_start();
try {
echo "foo";
- } catch(Exception \$e) {
+ } catch (Exception \$e) {
ob_end_clean();
throw \$e;
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_ModuleTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_PrintTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_SandboxTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_SandboxedModuleTest extends Twig_Test_NodeTestCase
{
/**
echo "foo";
}
- protected function checkSecurity() {
+ protected function checkSecurity()
+ {
\$this->env->getExtension('sandbox')->checkSecurity(
array('upper'),
array('for'),
\$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks));
}
- protected function checkSecurity() {
+ protected function checkSecurity()
+ {
\$this->env->getExtension('sandbox')->checkSecurity(
array('upper'),
array('for'),
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_SandboxedPrintTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_SetTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_SpacelessTest extends Twig_Test_NodeTestCase
{
/**
* file that was distributed with this source code.
*/
-
class Twig_Tests_Node_TextTest extends Twig_Test_NodeTestCase
{
/**
// add twig_template_get_attributes tests
if (function_exists('twig_template_get_attributes')) {
- foreach(array_slice($tests, 0) as $test) {
+ foreach (array_slice($tests, 0) as $test) {
$test = array_pad($test, 7, null);
$test[6] = true;
$tests[] = $test;
return 'protected';
}
- static public function getStatic()
+ public static function getStatic()
{
return 'static';
}
class Twig_TemplateMethodAndPropObject
{
private $a = 'a_prop';
- public function getA() {
+ public function getA()
+ {
return 'a';
}
public $b = 'b_prop';
- public function getB() {
+ public function getB()
+ {
return 'b';
}
private $c = 'c_prop';
- private function getC() {
+ private function getC()
+ {
return 'c';
}
}
class Twig_TemplateMagicMethodObject
{
- public function __call($method, $arguments) {
+ public function __call($method, $arguments)
+ {
return '__call_'.$method;
}
}
class Twig_Tests_TokenStreamTest extends PHPUnit_Framework_TestCase
{
- static protected $tokens;
+ protected static $tokens;
public function setUp()
{