From f6bce94d5297a95e88d7f32282f1bbd45fd30c13 Mon Sep 17 00:00:00 2001 From: Matthieu Auger Date: Mon, 30 Mar 2015 00:37:37 +0200 Subject: [PATCH 01/13] Use stubs for profiles. Fixes #1660 --- .../Tests/Profiler/Dumper/AbstractTest.php | 108 +++++++++++++----- 1 file changed, 82 insertions(+), 26 deletions(-) diff --git a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php index 555a5e7445..d855664ac4 100644 --- a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php +++ b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php @@ -13,32 +13,88 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends PHPUnit_Framework { protected function getProfile() { - $profile = new Twig_Profiler_Profile(); - $index = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::TEMPLATE); - $profile->addProfile($index); - $body = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::BLOCK, 'body'); - $body->leave(); - $index->addProfile($body); - $embedded = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::TEMPLATE); - $included = new Twig_Profiler_Profile('included.twig', Twig_Profiler_Profile::TEMPLATE); - $embedded->addProfile($included); - $index->addProfile($embedded); - $included->leave(); - $embedded->leave(); - - $macro = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::MACRO, 'foo'); - $macro->leave(); - $index->addProfile($macro); - - $embedded = clone $embedded; - $index->addProfile($embedded); - usleep(500); - $embedded->leave(); - - usleep(4500); - $index->leave(); - - $profile->leave(); + $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock(); + + $profile->expects($this->any())->method('isRoot')->will($this->returnValue(true)); + $profile->expects($this->any())->method('getName')->will($this->returnValue('main')); + $profile->expects($this->any())->method('getDuration')->will($this->returnValue(1)); + $profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0)); + $profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0)); + + $subProfiles = array( + $this->getIndexProfile( + array( + $this->getEmbeddedBlockProfile(), + $this->getEmbeddedTemplateProfile( + array( + $this->getIncludedTemplateProfile(), + ) + ), + $this->getMacroProfile(), + $this->getEmbeddedTemplateProfile( + array( + $this->getIncludedTemplateProfile(), + ) + ), + ) + ), + ); + + $profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles)); + $profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles))); + + return $profile; + } + + private function getIndexProfile(array $subProfiles = array()) + { + return $this->generateProfile('main', 1, true, 'template', 'index.twig', $subProfiles); + } + + private function getEmbeddedBlockProfile(array $subProfiles = array()) + { + return $this->generateProfile('body', 0.0001, false, 'block', 'embedded.twig', $subProfiles); + } + + private function getEmbeddedTemplateProfile(array $subProfiles = array()) + { + return $this->generateProfile('main', 0.0001, true, 'template', 'embedded.twig', $subProfiles); + } + + private function getIncludedTemplateProfile(array $subProfiles = array()) + { + return $this->generateProfile('main', 0.0001, true, 'template', 'included.twig', $subProfiles); + } + + private function getMacroProfile(array $subProfiles = array()) + { + return $this->generateProfile('foo', 0.0001, false, 'macro', 'index.twig', $subProfiles); + } + + /** + * @param string $name + * @param float $duration + * @param bool $isTemplate + * @param string $type + * @param string $templateName + * @param array $subProfiles + * + * @return Twig_Profiler_Profile + */ + private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = array()) + { + $profile = $this->getMockBuilder('Twig_Profiler_Profile')->disableOriginalConstructor()->getMock(); + + $profile->expects($this->any())->method('isRoot')->will($this->returnValue(false)); + $profile->expects($this->any())->method('getName')->will($this->returnValue($name)); + $profile->expects($this->any())->method('getDuration')->will($this->returnValue($duration)); + $profile->expects($this->any())->method('getMemoryUsage')->will($this->returnValue(0)); + $profile->expects($this->any())->method('getPeakMemoryUsage')->will($this->returnValue(0)); + $profile->expects($this->any())->method('isTemplate')->will($this->returnValue($isTemplate)); + $profile->expects($this->any())->method('getType')->will($this->returnValue($type)); + $profile->expects($this->any())->method('getTemplate')->will($this->returnValue($templateName)); + $profile->expects($this->any())->method('getProfiles')->will($this->returnValue($subProfiles)); + $profile->expects($this->any())->method('getIterator')->will($this->returnValue(new ArrayIterator($subProfiles))); return $profile; } From ddf011d360dab7569547170114b33810b010ddc8 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Wed, 1 Apr 2015 14:49:29 -0300 Subject: [PATCH 02/13] Updated exception messages for null vars in Twig_Template::getAttribute(). --- ext/twig/twig.c | 52 ++++++++++++++++++++++++-------- lib/Twig/Template.php | 16 ++++++++-- test/Twig/Tests/TemplateTest.php | 4 +++ 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/ext/twig/twig.c b/ext/twig/twig.c index ae5b1470ec..40c03fdef0 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -779,12 +779,18 @@ PHP_FUNCTION(twig_template_get_attributes) $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface', $item, get_class($object)); } elseif (is_array($object)) { if (empty($object)) { - $message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem); + $message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem); } else { - $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); } } elseif (Twig_Template::ARRAY_CALL === $type) { - $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + if (null === $object) { + $message = sprintf('Impossible to access a key ("%s") on a null variable', $item); + } else { + $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + } + } elseif (null === $object) { + $message = sprintf('Impossible to access an attribute ("%s") on a null variable', $item); } else { $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object); } @@ -807,12 +813,21 @@ PHP_FUNCTION(twig_template_get_attributes) } else { char *type_name = zend_zval_type_name(object); Z_ADDREF_P(object); - convert_to_string(object); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, - (strcmp("array", type) == 0) - ? "Impossible to access a key (\"%s\") on a %s variable (\"%s\")" - : "Impossible to access an attribute (\"%s\") on a %s variable (\"%s\")", - item, type_name, Z_STRVAL_P(object)); + if (Z_TYPE_P(object) == IS_NULL) { + convert_to_string(object); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, + (strcmp("array", type) == 0) + ? "Impossible to access a key (\"%s\") on a %s variable" + : "Impossible to access an attribute (\"%s\") on a %s variable", + item, type_name); + } else { + convert_to_string(object); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, + (strcmp("array", type) == 0) + ? "Impossible to access a key (\"%s\") on a %s variable (\"%s\")" + : "Impossible to access an attribute (\"%s\") on a %s variable (\"%s\")", + item, type_name, Z_STRVAL_P(object)); + } zval_ptr_dtor(&object); } efree(item); @@ -836,7 +851,14 @@ PHP_FUNCTION(twig_template_get_attributes) if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { return null; } - throw new Twig_Error_Runtime(sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName()); + + if (null === $object) { + $message = sprintf('Impossible to invoke a method ("%s") on a null variable', $item); + } else { + $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + } + + throw new Twig_Error_Runtime($message, -1, $this->getTemplateName()); } */ if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "isStrictVariables" TSRMLS_CC)) { @@ -846,9 +868,15 @@ PHP_FUNCTION(twig_template_get_attributes) type_name = zend_zval_type_name(object); Z_ADDREF_P(object); - convert_to_string_ex(&object); + if (Z_TYPE_P(object) == IS_NULL) { + convert_to_string_ex(&object); - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable (\"%s\")", item, type_name, Z_STRVAL_P(object)); + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable", item, type_name); + } else { + convert_to_string_ex(&object); + + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to invoke a method (\"%s\") on a %s variable (\"%s\")", item, type_name, Z_STRVAL_P(object)); + } zval_ptr_dtor(&object); efree(item); diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index caf96428b2..20c26647fe 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -419,7 +419,13 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); } } elseif (Twig_Template::ARRAY_CALL === $type) { - $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + if (null === $object) { + $message = sprintf('Impossible to access a key ("%s") on a null variable', $item); + } else { + $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + } + } elseif (null === $object) { + $message = sprintf('Impossible to access an attribute ("%s") on a null variable', $item); } else { $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object); } @@ -437,7 +443,13 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ return; } - throw new Twig_Error_Runtime(sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName()); + if (null === $object) { + $message = sprintf('Impossible to invoke a method ("%s") on a null variable', $item); + } else { + $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object); + } + + throw new Twig_Error_Runtime($message, -1, $this->getTemplateName()); } // object property diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 9010f28e10..35e41884a0 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -28,6 +28,7 @@ public function testGetAttributeExceptions($template, $message, $useExt) $context = array( 'string' => 'foo', + 'null' => null, 'empty_array' => array(), 'array' => array('foo' => 'foo'), 'array_access' => new Twig_TemplateArrayAccessObject(), @@ -47,11 +48,14 @@ public function getAttributeExceptions() { $tests = array( array('{{ string["a"] }}', 'Impossible to access a key ("a") on a string variable ("foo") in "%s" at line 1', false), + array('{{ null["a"] }}', 'Impossible to access a key ("a") on a null variable in "%s" at line 1', false), array('{{ empty_array["a"] }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), array('{{ array["a"] }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), array('{{ array_access["a"] }}', 'Key "a" in object with ArrayAccess of class "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), array('{{ string.a }}', 'Impossible to access an attribute ("a") on a string variable ("foo") in "%s" at line 1', false), array('{{ string.a() }}', 'Impossible to invoke a method ("a") on a string variable ("foo") in "%s" at line 1', false), + array('{{ null.a }}', 'Impossible to access an attribute ("a") on a null variable in "%s" at line 1', false), + array('{{ null.a() }}', 'Impossible to invoke a method ("a") on a null variable in "%s" at line 1', false), array('{{ empty_array.a }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), array('{{ array.a }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), array('{{ attribute(array, -10) }}', 'Key "-10" for array with keys "foo" does not exist in "%s" at line 1', false), From 2698a4228462a7f5cf50258ba37d7d6f018b13f4 Mon Sep 17 00:00:00 2001 From: Evaldo Junior Date: Wed, 8 Apr 2015 16:01:18 +0200 Subject: [PATCH 03/13] Added an example for "and" on if statment --- doc/tags/if.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/tags/if.rst b/doc/tags/if.rst index b10dcb4b3a..860bd3d147 100644 --- a/doc/tags/if.rst +++ b/doc/tags/if.rst @@ -37,6 +37,14 @@ You can also use ``not`` to check for values that evaluate to ``false``:

You are not subscribed to our mailing list.

{% endif %} +For multiple conditions ``and`` and ``or`` can be used: + +.. code-block:: jinja + + {% if temperature > 18 and temperature < 27 %} +

It's a nice day for a walk in the park.

+ {% endif %} + For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can use more complex ``expressions`` there too: From c55e60394c461b7b298dddf56e83deca6b0ab8e3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 16 May 2015 16:14:08 +0200 Subject: [PATCH 04/13] fixed CS --- doc/tags/if.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/tags/if.rst b/doc/tags/if.rst index 860bd3d147..12edf980df 100644 --- a/doc/tags/if.rst +++ b/doc/tags/if.rst @@ -37,7 +37,7 @@ You can also use ``not`` to check for values that evaluate to ``false``:

You are not subscribed to our mailing list.

{% endif %} -For multiple conditions ``and`` and ``or`` can be used: +For multiple conditions, ``and`` and ``or`` can be used: .. code-block:: jinja @@ -45,8 +45,8 @@ For multiple conditions ``and`` and ``or`` can be used:

It's a nice day for a walk in the park.

{% endif %} -For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can use -more complex ``expressions`` there too: +For multiple branches ``elseif`` and ``else`` can be used like in PHP. You can +use more complex ``expressions`` there too: .. code-block:: jinja From 329d67c4bb3568de07c9ca0da6754aef2162a0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Tue, 2 Jun 2015 10:05:33 +0200 Subject: [PATCH 05/13] Travis no longer supports hhvm-nightly --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a6274ff6bd..223a3be1ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,9 @@ php: - 5.6 - hhvm - nightly - - hhvm-nightly allow_failures: - php: nightly - - php: hhvm-nightly env: - TWIG_EXT=no @@ -26,7 +24,5 @@ matrix: exclude: - php: hhvm env: TWIG_EXT=yes - - php: hhvm-nightly - env: TWIG_EXT=yes - php: nightly env: TWIG_EXT=yes From dd1b1016a7ff01bdd80509cc0be1229d8bdb9574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Tue, 2 Jun 2015 11:19:07 +0200 Subject: [PATCH 06/13] Fixed error guessing for nested templates --- lib/Twig/Template.php | 9 ++++++++- .../exceptions/syntax_error_in_reused_template.test | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 1d54bb13ac..86094e2da3 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -255,7 +255,14 @@ protected function loadTemplate($template, $templateName = null, $line = null, $ return $this->env->loadTemplate($template, $index); } catch (Twig_Error $e) { - $e->setTemplateFile($templateName ? $templateName : $this->getTemplateName()); + if (!$e->getTemplateFile()) { + $e->setTemplateFile($templateName ? $templateName : $this->getTemplateName()); + } + + if ($e->getTemplateLine()) { + throw $e; + } + if (!$line) { $e->guess(); } else { diff --git a/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test b/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test new file mode 100644 index 0000000000..5dd9f3838e --- /dev/null +++ b/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test @@ -0,0 +1,10 @@ +--TEST-- +Exception for syntax error in reused template +--TEMPLATE-- +{% use 'foo.twig' %} +--TEMPLATE(foo.twig)-- +{% block bar %} + {% do node.data = 5 %} +{% endblock %} +--EXCEPTION-- +Twig_Error_Syntax: Unexpected token "operator" of value "=" ("end of statement block" expected) in "foo.twig" at line 3 From 00fe940ebfc39ff89dceecd8f62c199cb17c9fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Tue, 2 Jun 2015 11:21:27 +0200 Subject: [PATCH 07/13] Fixed CS --- lib/Twig/Template.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 86094e2da3..0878d1640c 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -75,7 +75,7 @@ public function getParent(array $context) return false; } - if ($parent instanceof Twig_Template) { + if ($parent instanceof self) { return $this->parents[$parent->getTemplateName()] = $parent; } @@ -249,7 +249,7 @@ protected function loadTemplate($template, $templateName = null, $line = null, $ return $this->env->resolveTemplate($template); } - if ($template instanceof Twig_Template) { + if ($template instanceof self) { return $template; } @@ -392,10 +392,10 @@ final protected function getContext($context, $item, $ignoreStrictCheck = false) * * @throws Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false */ - protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) + protected function getAttribute($object, $item, array $arguments = array(), $type = self::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) { // array - if (Twig_Template::METHOD_CALL !== $type) { + if (self::METHOD_CALL !== $type) { $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; if ((is_array($object) && array_key_exists($arrayItem, $object)) @@ -408,7 +408,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ return $object[$arrayItem]; } - if (Twig_Template::ARRAY_CALL === $type || !is_object($object)) { + if (self::ARRAY_CALL === $type || !is_object($object)) { if ($isDefinedTest) { return false; } @@ -427,7 +427,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ } else { $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); } - } elseif (Twig_Template::ARRAY_CALL === $type) { + } elseif (self::ARRAY_CALL === $type) { if (null === $object) { $message = sprintf('Impossible to access a key ("%s") on a null variable', $item); } else { @@ -462,7 +462,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ } // object property - if (Twig_Template::METHOD_CALL !== $type) { + if (self::METHOD_CALL !== $type) { if (isset($object->$item) || array_key_exists((string) $item, $object)) { if ($isDefinedTest) { return true; From 29986a9c4c9fba7a080c548e49fa752b5005b8d6 Mon Sep 17 00:00:00 2001 From: Artem Lopata Date: Tue, 2 Jun 2015 15:11:17 +0300 Subject: [PATCH 08/13] Added note about case sensitivity of logic operators --- doc/templates.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/templates.rst b/doc/templates.rst index 7ff7862835..4ec4a52d15 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -669,6 +669,10 @@ You can combine multiple expressions with the following operators: Twig also support bitwise operators (``b-and``, ``b-xor``, and ``b-or``). +.. note:: + + Operators are case sensitive. + Comparisons ~~~~~~~~~~~ From df9da8e85855753d19a4d0ff52e1783b56f7ac3e Mon Sep 17 00:00:00 2001 From: Ulf Date: Tue, 2 Jun 2015 11:41:25 +0200 Subject: [PATCH 09/13] Added label for "Whitespace Control" section --- doc/tags/spaceless.rst | 2 +- doc/templates.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/tags/spaceless.rst b/doc/tags/spaceless.rst index 12e77b2575..b39cb27efe 100644 --- a/doc/tags/spaceless.rst +++ b/doc/tags/spaceless.rst @@ -33,5 +33,5 @@ quirks under some circumstances. .. tip:: For more information on whitespace control, read the - :doc:`dedicated<../templates>` section of the documentation and learn how + :ref:`dedicated section ` of the documentation and learn how you can also use the whitespace control modifier on your tags. diff --git a/doc/templates.rst b/doc/templates.rst index 7ff7862835..825ffce9e8 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -801,6 +801,8 @@ inserted into the string: {{ "foo #{bar} baz" }} {{ "foo #{1 + 2} baz" }} +.. _templates-whitespace-control: + Whitespace Control ------------------ From 0a46d060691c903935596cfc445044318c0a6e20 Mon Sep 17 00:00:00 2001 From: Kevin Simper Date: Wed, 4 Feb 2015 15:44:30 +0100 Subject: [PATCH 10/13] Organize and show value types --- doc/api.rst | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index cdeaffdb04..2724bc2876 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -72,29 +72,43 @@ options as the constructor second argument:: The following options are available: -* ``debug``: When set to ``true``, the generated templates have a +* ``debug`` *boolean* + + When set to ``true``, the generated templates have a ``__toString()`` method that you can use to display the generated nodes (default to ``false``). -* ``charset``: The charset used by the templates (default to ``utf-8``). +* ``charset`` *string (default to ``utf-8``)* + + The charset used by the templates. + +* ``base_template_class`` *(default to ``Twig_Template``)* + + The base template class to use for generated + templates. -* ``base_template_class``: The base template class to use for generated - templates (default to ``Twig_Template``). +* ``cache`` *boolean* -* ``cache``: An absolute path where to store the compiled templates, or + An absolute path where to store the compiled templates, or ``false`` to disable caching (which is the default). -* ``auto_reload``: When developing with Twig, it's useful to recompile the +* ``auto_reload`` *boolean* + + When developing with Twig, it's useful to recompile the template whenever the source code changes. If you don't provide a value for the ``auto_reload`` option, it will be determined automatically based on the ``debug`` value. -* ``strict_variables``: If set to ``false``, Twig will silently ignore invalid +* ``strict_variables`` *boolean* + + If set to ``false``, Twig will silently ignore invalid variables (variables and or attributes/methods that do not exist) and replace them with a ``null`` value. When set to ``true``, Twig throws an exception instead (default to ``false``). -* ``autoescape``: If set to ``true``, HTML auto-escaping will be enabled by +* ``autoescape`` *boolean* + + If set to ``true``, HTML auto-escaping will be enabled by default for all templates (default to ``true``). As of Twig 1.8, you can set the escaping strategy to use (``html``, ``js``, @@ -110,7 +124,9 @@ The following options are available: strategy does not incur any overhead at runtime as auto-escaping is done at compilation time.) -* ``optimizations``: A flag that indicates which optimizations to apply +* ``optimizations`` *integer* + + A flag that indicates which optimizations to apply (default to ``-1`` -- all optimizations are enabled; set it to ``0`` to disable). From d0b71307d61c8a796275895e1d47d310b8bd6bfa Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 7 Jun 2015 01:22:13 +0200 Subject: [PATCH 11/13] fixed previous merge --- doc/api.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 2724bc2876..f367db07a5 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -82,12 +82,12 @@ The following options are available: The charset used by the templates. -* ``base_template_class`` *(default to ``Twig_Template``)* +* ``base_template_class`` *string (default to ``Twig_Template``)* The base template class to use for generated templates. -* ``cache`` *boolean* +* ``cache`` *string|false* An absolute path where to store the compiled templates, or ``false`` to disable caching (which is the default). @@ -106,7 +106,7 @@ The following options are available: replace them with a ``null`` value. When set to ``true``, Twig throws an exception instead (default to ``false``). -* ``autoescape`` *boolean* +* ``autoescape`` *string|boolean* If set to ``true``, HTML auto-escaping will be enabled by default for all templates (default to ``true``). From b560a2c14fc96c5116b92b48e03c1226b042a117 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 7 Jun 2015 01:26:25 +0200 Subject: [PATCH 12/13] reverted unexpected change --- lib/Twig/Extension/Core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index fd3b11718c..5ddf21e9e7 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -1412,7 +1412,7 @@ function twig_test_iterable($value) * * @return string The rendered template */ -function twig_include(Twig_Environment $env, array $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false) +function twig_include(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false) { $alreadySandboxed = false; $sandbox = null; From 3e3aa8e26d7fecb76c0a741581a5697a09b06c49 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 7 Jun 2015 01:28:33 +0200 Subject: [PATCH 13/13] updated CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 6e1bbe9b4b..034158da6e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.18.2 (2015-XX-XX) + * fixed template/line guessing in exceptions for nested templates * optimized the number of inodes and the size of realpath cache when using the cache * 1.18.1 (2015-04-19)