From fc9bb378d4c5e719a632fed09c1eda5546436f25 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sat, 18 Sep 2010 23:33:13 -0400 Subject: [PATCH] Remove addBuiltinHelpers; add Tag and Text helpers in the default factory --- framework/Core/lib/Horde/Core/Factory/View.php | 3 +- framework/View/lib/Horde/View/Base.php | 18 ------ framework/View/lib/Horde/View/Helper/Debug.php | 76 +++++++++++++++++++++++++- framework/View/test/Horde/View/BaseTest.php | 13 ----- jonah/lib/View/StoryView.php | 2 +- koward/lib/Koward/View/Object/listall.html.php | 2 - koward/lib/Koward/View/Object/search.html.php | 2 - luxor/source.php | 2 +- luxor/symbol.php | 2 +- 9 files changed, 79 insertions(+), 41 deletions(-) diff --git a/framework/Core/lib/Horde/Core/Factory/View.php b/framework/Core/lib/Horde/Core/Factory/View.php index 9c85d47d5..85565e180 100644 --- a/framework/Core/lib/Horde/Core/Factory/View.php +++ b/framework/Core/lib/Horde/Core/Factory/View.php @@ -33,7 +33,8 @@ class Horde_Core_Factory_View public function create(Horde_Injector $injector) { $view = new Horde_View(); - $view->addBuiltinHelpers(); + $view->addHelper('Tag'); + $view->addHelper('Text'); return $view; } } diff --git a/framework/View/lib/Horde/View/Base.php b/framework/View/lib/Horde/View/Base.php index 785048418..39beac66e 100644 --- a/framework/View/lib/Horde/View/Base.php +++ b/framework/View/lib/Horde/View/Base.php @@ -147,24 +147,6 @@ 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/lib/Horde/View/Helper/Debug.php b/framework/View/lib/Horde/View/Helper/Debug.php index 946dfb68e..f909a3968 100644 --- a/framework/View/lib/Horde/View/Helper/Debug.php +++ b/framework/View/lib/Horde/View/Helper/Debug.php @@ -1,7 +1,7 @@ * @author Derek DeVries @@ -40,6 +40,36 @@ class Horde_View_Helper_Debug extends Horde_View_Helper_Base } /** + * Pretty exception dumper. + * + * Inspired by: + * http://www.sitepoint.com/blogs/2006/04/04/pretty-blue-screen/ and + * http://www.sitepoint.com/blogs/2006/08/12/pimpin-harrys-pretty-bluescreen/. + * + * Also see for future ideas: + * http://mikenaberezny.com/archives/55 + * + * @param Exception $e + */ + public function dump(Exception $e) + { + $input = array( + 'type' => get_class($e), + 'code' => $e->getCode(), + 'message' => $e->getMessage(), + 'line' => $e->getLine(), + 'file' => $e->getFile(), + 'trace' => $e->getTrace(), + ); + + // Store previous output. + $previous_output = ob_get_contents(); + + $desc = $input['type'] . ' making ' . $_SERVER['REQUEST_METHOD'] . ' request to ' . $_SERVER['REQUEST_URI']; + return $this->render('_dump.html.php'); + } + + /** * Returns formatted output from var_dump(). * * Buffers the var_dump output for a variable and applies some @@ -48,7 +78,7 @@ class Horde_View_Helper_Debug extends Horde_View_Helper_Base * @param mixed $var variable to dump * @return string formatted results of var_dump() */ - private function _fetch($var) + protected function _fetch($var) { ob_start(); var_dump($var); @@ -57,4 +87,46 @@ class Horde_View_Helper_Debug extends Horde_View_Helper_Base return $output; } + protected function _sub($f) + { + $loc = ''; + if (isset($f['class'])) { + $loc .= $f['class'] . $f['type']; + } + if (isset($f['function'])) { + $loc .= $f['function']; + } + if (!empty($loc)) { + $loc = htmlspecialchars($loc); + $loc = "$loc"; + } + return $loc; + } + + protected function _clean($line) + { + $l = trim(strip_tags($line)); + return $l ? $l : ' '; + } + + protected function _parms($f) + { + if (isset($f['function'])) { + try { + if (isset($f['class'])) { + $r = new ReflectionMethod($f['class'] . '::' . $f['function']); + } else { + $r = new ReflectionFunction($f['function']); + } + return $r->getParameters(); + } catch(Exception $e) {} + } + return array(); + } + + protected function _src2lines($file) + { + $src = nl2br(highlight_file($file, true)); + return explode('
', $src); + } } diff --git a/framework/View/test/Horde/View/BaseTest.php b/framework/View/test/Horde/View/BaseTest.php index ed7ae4e6c..f1bc36ac6 100644 --- a/framework/View/test/Horde/View/BaseTest.php +++ b/framework/View/test/Horde/View/BaseTest.php @@ -243,17 +243,4 @@ class Horde_View_BaseTest extends Horde_Test_Case // successful when trying to add it again $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'); - } - } - } diff --git a/jonah/lib/View/StoryView.php b/jonah/lib/View/StoryView.php index 08e88e8cb..c6f0744de 100644 --- a/jonah/lib/View/StoryView.php +++ b/jonah/lib/View/StoryView.php @@ -71,7 +71,7 @@ class Jonah_View_StoryView extends Jonah_View_Base JONAH_TEMPLATES . '/stories/partial', JONAH_TEMPLATES . '/stories/layout'))); $view->addHelper('Tag'); - $view->addBuiltinHelpers(); + $view->addHelper('Text'); $view->tagcloud = $cloud->buildHTML(); $view->story = $story; diff --git a/koward/lib/Koward/View/Object/listall.html.php b/koward/lib/Koward/View/Object/listall.html.php index 6a0dfe4bc..c64fe4985 100644 --- a/koward/lib/Koward/View/Object/listall.html.php +++ b/koward/lib/Koward/View/Object/listall.html.php @@ -1,8 +1,6 @@ renderPartial('header'); ?> renderPartial('menu'); ?> -addBuiltinHelpers(); ?> - tabs->render($this->object_type); ?> objectlist)): ?> diff --git a/koward/lib/Koward/View/Object/search.html.php b/koward/lib/Koward/View/Object/search.html.php index d910b54d6..a2d80edb4 100644 --- a/koward/lib/Koward/View/Object/search.html.php +++ b/koward/lib/Koward/View/Object/search.html.php @@ -1,8 +1,6 @@ renderPartial('header'); ?> renderPartial('menu'); ?> -addBuiltinHelpers(); ?> - objectlist)): ?> form->renderActive(new Horde_Form_Renderer(), $this->vars, $this->post, 'post'); ?> diff --git a/luxor/source.php b/luxor/source.php index 8185610cc..59844ab2c 100644 --- a/luxor/source.php +++ b/luxor/source.php @@ -14,7 +14,7 @@ Horde_Registry::appInit('luxor'); function printdir($dir) { $view = new Horde_View(array('templatePath' => LUXOR_TEMPLATES)); - $view->addBuiltinHelpers(); + $view->addHelper('Text'); $dirlist = Luxor::dirExpand($dir); if (is_a($dirlist, 'PEAR_Error')) { $GLOBALS['notification']->push($dirlist, 'horde.error'); diff --git a/luxor/symbol.php b/luxor/symbol.php index 72bcee501..5008b9c9e 100644 --- a/luxor/symbol.php +++ b/luxor/symbol.php @@ -77,7 +77,7 @@ require LUXOR_TEMPLATES . '/common-header.inc'; require LUXOR_TEMPLATES . '/menu.inc'; $view = new Horde_View(array('templatePath' => LUXOR_TEMPLATES)); -$view->addBuiltinHelpers(); +$view->addHelper('Text'); $view->title = $title; $view->declarations = $ds; $view->references = $rs; -- 2.11.0