Bladeren bron

[Templating] added an Engine::load() method

Fabien Potencier 14 jaren geleden
bovenliggende
commit
cbb22b4ec4
1 gewijzigde bestanden met toevoegingen van 24 en 7 verwijderingen
  1. 24 7
      src/Symfony/Component/Templating/Engine.php

+ 24 - 7
src/Symfony/Component/Templating/Engine.php

@@ -140,17 +140,34 @@ class Engine implements \ArrayAccess
      */
     public function exists($name)
     {
-        list($tpl, $options) = $this->splitTemplateName($name);
+        return false !== $this->load($name);
+    }
 
-        $template = $this->loader->load($tpl, $options);
+    /**
+     * Returns true if the template exists.
+     *
+     * @param string $name A template name
+     *
+     * @return Boolean true if the template exists, false otherwise
+     */
+    public function load($name)
+    {
+        if (isset($this->cache[$name])) {
+            list($tpl, $options, $template) = $this->cache[$name];
+        } else {
+            list($tpl, $options) = $this->splitTemplateName($name);
 
-        if (false === $template) {
-            return false;
-        }
+            // load
+            $template = $this->loader->load($tpl, $options);
 
-        $this->cache[$name] = array($tpl, $options, $template);
+            if (false === $template) {
+                return false;
+            }
+
+            $this->cache[$name] = array($tpl, $options, $template);
+        }
 
-        return true;
+        return $template;
     }
 
     /**