Remove addBuiltinHelpers; add Tag and Text helpers in the default factory
authorChuck Hagenbuch <chuck@horde.org>
Sun, 19 Sep 2010 03:33:13 +0000 (23:33 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 19 Sep 2010 03:33:13 +0000 (23:33 -0400)
framework/Core/lib/Horde/Core/Factory/View.php
framework/View/lib/Horde/View/Base.php
framework/View/lib/Horde/View/Helper/Debug.php
framework/View/test/Horde/View/BaseTest.php
jonah/lib/View/StoryView.php
koward/lib/Koward/View/Object/listall.html.php
koward/lib/Koward/View/Object/search.html.php
luxor/source.php
luxor/symbol.php

index 9c85d47..85565e1 100644 (file)
@@ -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;
     }
 }
index 7850484..39beac6 100644 (file)
@@ -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
index 946dfb6..f909a39 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Copyright 2007-2008 Maintainable Software, LLC
- * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
  *
  * @author     Mike Naberezny <mike@maintainable.com>
  * @author     Derek DeVries <derek@maintainable.com>
@@ -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 = "<strong>$loc</strong>";
+        }
+        return $loc;
+    }
+
+    protected function _clean($line)
+    {
+        $l = trim(strip_tags($line));
+        return $l ? $l : '&nbsp;';
+    }
+
+    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('<br />', $src);
+    }
 }
index ed7ae4e..f1bc36a 100644 (file)
@@ -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('&amp;', $view->h('&'));
-        } catch (Exception $e) {
-            $this->fail('h helper not callable');
-        }
-    }
-
 }
index 08e88e8..c6f0744 100644 (file)
@@ -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;
 
index 6a0dfe4..c64fe49 100644 (file)
@@ -1,8 +1,6 @@
 <?php echo $this->renderPartial('header'); ?>
 <?php echo $this->renderPartial('menu'); ?>
 
-<?php echo $this->addBuiltinHelpers(); ?>
-
 <?php echo $this->tabs->render($this->object_type); ?>
 
 <?php if (isset($this->objectlist)): ?>
index d910b54..a2d80ed 100644 (file)
@@ -1,8 +1,6 @@
 <?php echo $this->renderPartial('header'); ?>
 <?php echo $this->renderPartial('menu'); ?>
 
-<?php echo $this->addBuiltinHelpers(); ?>
-
 <?php if (empty($this->objectlist)): ?>
   <?php echo $this->form->renderActive(new Horde_Form_Renderer(), $this->vars,
                                 $this->post, 'post'); ?>
index 8185610..59844ab 100644 (file)
@@ -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');
index 72bcee5..5008b9c 100644 (file)
@@ -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;