diff --git a/CHANGELOG b/CHANGELOG index 8feae8baf..c541bd705 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,8 +13,17 @@ * improved the performance of the filesystem loader * removed features that were deprecated in 1.x -* 1.22.3 (2015-XX-XX) +* 1.22.4 (2015-XX-XX) + * n/a + +* 1.22.3 (2015-10-13) + + * fixed regression when using null as a cache strategy + * improved performance when checking template freshness + * fixed warnings when loaded templates do not exist + * fixed template class name generation to prevent possible collisions + * fixed logic for custom escapers to call them even on integers and null values * changed template cache names to take into account the Twig C extension * 1.22.2 (2015-09-22) diff --git a/doc/templates.rst b/doc/templates.rst index d90749cfa..0542c573a 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -758,15 +758,27 @@ tests. Other Operators ~~~~~~~~~~~~~~~ -The following operators are very useful but don't fit into any of the other -categories: - -* ``..``: Creates a sequence based on the operand before and after the - operator (this is just syntactic sugar for the :doc:`range` - function). +The following operators don't fit into any of the other categories: * ``|``: Applies a filter. +* ``..``: Creates a sequence based on the operand before and after the operator + (this is just syntactic sugar for the :doc:`range` function): + + .. code-block:: jinja + + {{ 1..5 }} + + {# equivalent to #} + {{ range(1, 5) }} + + Note that you must use parentheses when combining it with the filter operator + due to the :ref:`operator precedence rules `: + + .. code-block:: jinja + + (1..5)|join(', ') + * ``~``: Converts all operands into strings and concatenates them. ``{{ "Hello " ~ name ~ "!" }}`` would return (assuming ``name`` is ``'John'``) ``Hello John!``. diff --git a/lib/Twig/Cache/Filesystem.php b/lib/Twig/Cache/Filesystem.php index 463104463..2c2182a82 100644 --- a/lib/Twig/Cache/Filesystem.php +++ b/lib/Twig/Cache/Filesystem.php @@ -87,6 +87,10 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface */ public function getTimestamp($key) { + if (!file_exists($key)) { + return 0; + } + return (int) @filemtime($key); } } diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index fd026f217..e5b556282 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -45,6 +45,7 @@ class Twig_Environment private $filterCallbacks = array(); private $staging; private $originalCache; + private $lastModifiedExtension = 0; /** * Constructor. @@ -238,6 +239,10 @@ class Twig_Environment } elseif (false === $cache) { $this->originalCache = $cache; $this->cache = new Twig_Cache_Null(); + } elseif (null === $cache) { + @trigger_error('Using "null" as the cache strategy is deprecated and will be removed in Twig 2.0.', E_USER_DEPRECATED); + $this->originalCache = false; + $this->cache = new Twig_Cache_Null(); } elseif ($cache instanceof Twig_CacheInterface) { $this->originalCache = $this->cache = $cache; } else { @@ -386,14 +391,7 @@ class Twig_Environment */ public function isTemplateFresh($name, $time) { - foreach ($this->extensions as $extension) { - $r = new ReflectionObject($extension); - if (filemtime($r->getFileName()) > $time) { - return false; - } - } - - return $this->getLoader()->isFresh($name, $time); + return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time); } /** @@ -665,6 +663,11 @@ class Twig_Environment throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName())); } + $r = new ReflectionObject($extension); + if (($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) { + $this->lastModifiedExtension = $extensionTime; + } + $this->extensions[$extension->getName()] = $extension; }