tags, cleans up newlines and indents, and runs * htmlentities() before output. * * @param mixed $var The variable to dump. * @param string $label An optional label. * @return string */ static public function dump($var, $label=null, $echo=true) { // format the label $label = ($label===null) ? '' : rtrim($label) . ' '; // var_dump the variable into a buffer and keep the output ob_start(); var_dump($var); $output = ob_get_clean(); // neaten the newlines and indents $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output); $output = '
'
                . $label
                . htmlentities($output, ENT_QUOTES)
                . '
'; if ($echo) { echo($output); } return $output; } /** * Registers a shared object. * * @param string $name The name for the object. * @param object $obj The object to register. * @throws Zend_Exception * @return void */ static public function register($name, $obj) { if (!is_string($name)) { throw new Zend_Exception('First argument $name must be a string.'); } // don't register the same name twice if (array_key_exists($name, self::$_registry)) { throw new Zend_Exception("Object named '$name' already registered."); } // only objects may be stored in the registry if (!is_object($obj)) { throw new Zend_Exception("Only objects may be stored in the registry."); } $e = ''; // an object can only be stored in the registry once foreach (self::$_registry as $dup=>$registeredObject) { if ($obj === $registeredObject) { $e = "Duplicate object handle already exists in the registry as \"$dup\"."; break; } } /** * @todo throwing exceptions inside foreach could cause leaks, use a workaround * like this until a fix is available * * @link http://bugs.php.net/bug.php?id=34065 */ if ($e) { throw new Zend_Exception($e); } self::$_registry[$name] = $obj; } /** * Retrieves a registered shared object, where $name is the * registered name of the object to retrieve. * * If $name is null, an associative array will be returned listing * the contents of the registry. * * @see register() * @param string $name The name for the object. * @throws Zend_Exception * @return object The registered object. */ static public function registry($name=null) { if ($name === null) { $registry = array(); foreach (self::$_registry as $name=>$obj) { $registry[$name] = get_class($obj); } return $registry; } if (!is_string($name)) { throw new Zend_Exception('First argument $name must be a string, or null to list registry.'); } if (!array_key_exists($name, self::$_registry)) { throw new Zend_Exception("No object named \"$name\" is registered."); } return self::$_registry[$name]; } }