From: Chuck Hagenbuch Date: Sat, 30 May 2009 15:28:50 +0000 (-0400) Subject: add addBuiltinHelpers() method for adding all built-in helpers to a view X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1302739e6a0f8a3bc6d276955970d8311bd40a5a;p=horde.git add addBuiltinHelpers() method for adding all built-in helpers to a view --- diff --git a/framework/View/lib/Horde/View/Base.php b/framework/View/lib/Horde/View/Base.php index b5a28b2b2..994d1d187 100644 --- a/framework/View/lib/Horde/View/Base.php +++ b/framework/View/lib/Horde/View/Base.php @@ -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 diff --git a/framework/View/test/Horde/View/BaseTest.php b/framework/View/test/Horde/View/BaseTest.php index 2afe1aa02..95b6b9965 100644 --- a/framework/View/test/Horde/View/BaseTest.php +++ b/framework/View/test/Horde/View/BaseTest.php @@ -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('&', $view->h('&')); + } catch (Exception $e) { + $this->fail('h helper not callable'); + } + } + }