Browse code

made it clear that Twig_Loader_String must not be used by end users

Fabien Potencier authored on 11/10/2014 20:30:59
Showing 4 changed files
... ...
@@ -166,21 +166,6 @@ Namespaced templates can be accessed via the special
166 166
 
167 167
     $twig->render('@admin/index.html', array());
168 168
 
169
-``Twig_Loader_String``
170
-......................
171
-
172
-``Twig_Loader_String`` loads templates from strings. It's a dummy loader as
173
-the template reference is the template source code::
174
-
175
-    $loader = new Twig_Loader_String();
176
-    $twig = new Twig_Environment($loader);
177
-
178
-    echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
179
-
180
-This loader should only be used for unit testing as it has severe limitations:
181
-several tags, like ``extends`` or ``include`` do not make sense to use as the
182
-reference to the template is the template source code itself.
183
-
184 169
 ``Twig_Loader_Array``
185 170
 .....................
186 171
 
... ...
@@ -268,26 +253,6 @@ All loaders implement the ``Twig_LoaderInterface``::
268 253
         function isFresh($name, $time);
269 254
     }
270 255
 
271
-As an example, here is how the built-in ``Twig_Loader_String`` reads::
272
-
273
-    class Twig_Loader_String implements Twig_LoaderInterface
274
-    {
275
-        public function getSource($name)
276
-        {
277
-          return $name;
278
-        }
279
-
280
-        public function getCacheKey($name)
281
-        {
282
-          return $name;
283
-        }
284
-
285
-        public function isFresh($name, $time)
286
-        {
287
-          return false;
288
-        }
289
-    }
290
-
291 256
 The ``isFresh()`` method must return ``true`` if the current cached template
292 257
 is still fresh, given the last modification time, or ``false`` otherwise.
293 258
 
... ...
@@ -50,12 +50,14 @@ This section gives you a brief introduction to the PHP API for Twig.
50 50
 
51 51
     require_once '/path/to/vendor/autoload.php';
52 52
 
53
-    $loader = new Twig_Loader_String();
53
+    $loader = new Twig_Loader_Array(
54
+        'index' => 'Hello {{ name }}!',
55
+    );
54 56
     $twig = new Twig_Environment($loader);
55 57
 
56
-    echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));
58
+    echo $twig->render('index', array('name' => 'Fabien'));
57 59
 
58
-Twig uses a loader (``Twig_Loader_String``) to locate templates, and an
60
+Twig uses a loader (``Twig_Loader_Array``) to locate templates, and an
59 61
 environment (``Twig_Environment``) to store the configuration.
60 62
 
61 63
 The ``render()`` method loads the template passed as a first argument and
... ...
@@ -17,6 +17,8 @@
17 17
  * source code of the template). If you don't want to see your cache grows out of
18 18
  * control, you need to take care of clearing the old cache file by yourself.
19 19
  *
20
+ * This loader should only be used for unit testing.
21
+ *
20 22
  * @author Fabien Potencier <fabien@symfony.com>
21 23
  */
22 24
 class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
... ...
@@ -12,9 +12,7 @@
12 12
 /**
13 13
  * Loads a template from a string.
14 14
  *
15
- * This loader should only be used for unit testing as it has many limitations
16
- * (for instance, the include or extends tag does not make any sense for a string
17
- * loader).
15
+ * This loader should NEVER be used. It only exists for Twig internal purposes.
18 16
  *
19 17
  * When using this loader with a cache mechanism, you should know that a new cache
20 18
  * key is generated each time a template content "changes" (the cache key being the