add addBuiltinHelpers() method for adding all built-in helpers to a view
authorChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:28:50 +0000 (11:28 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:28:50 +0000 (11:28 -0400)
framework/View/lib/Horde/View/Base.php
framework/View/test/Horde/View/BaseTest.php

index b5a28b2..994d1d1 100644 (file)
@@ -159,6 +159,24 @@ abstract class Horde_View_Base
     }
 
     /**
+     * Adds all of the built-in Horde_View_Helpers to this instance
+     *
+     * @todo We'll come up with a lazy-load strategy in the future.
+     */
+    public function addBuiltinHelpers()
+    {
+        $dir = dirname(__FILE__) . '/Helper';
+        foreach (new DirectoryIterator($dir) as $f) {
+            if ($f->isFile()) {
+                $helper = str_replace('.php', '', $f->getFilename());
+                if ($helper != 'Base') {
+                    $this->addHelper($helper);
+                }
+            }
+        }
+    }
+
+    /**
      * Adds to the stack of helpers in LIFO order.
      *
      * @param Horde_View_Helper $helper The helper instance to add. If this is a
index 2afe1aa..95b6b99 100644 (file)
@@ -244,4 +244,16 @@ class Horde_View_BaseTest extends Horde_Test_Case
         $this->_view->addHelper(new Horde_View_Helper_Text($this->_view));
     }
 
+    public function testAddBuiltinHelpers()
+    {
+        $view = new Horde_View();
+        $view->addBuiltinHelpers();
+
+        try {
+            $this->assertEquals('&amp;', $view->h('&'));
+        } catch (Exception $e) {
+            $this->fail('h helper not callable');
+        }
+    }
+
 }