PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_Menu » Bug #2935

combine duplicate code into _prefixUrl method

Details

Request #2935combine duplicate code into _prefixUrl method
Submitted2004-12-09 16:02 UTC
Fromaaron dot hawley at uvm dot edu
Assignedavb
StatusClosed
PackageHTML_Menu
PHP Version4.3.4
OSGNU/Linux
Roadmaps(Not assigned)

Comments

[2004-12-09 16:02 UTC] aaron dot hawley at uvm dot edu

Description:
------------
The code that prefixes URLs at each node in the _buildUrlMap and _findNodeType methods, should be consolidated. The patch below contains a method _prefixUrl. This makes it easier to create a sub-class which can modify the URL prefixing behavior.

Reproduce code:
---------------
===================================================================
RCS file: RCS/Menu.php,v
retrieving revision 1.1
diff -u -r1.1 Menu.php
--- Menu.php 2004/12/08 19:29:28 1.1
+++ Menu.php 2004/12/09 15:40:53
@@ -101,7 +101,7 @@
/**
* Prefix for menu URLs
* @var string
- * @see setUrlPrefix()
+ * @see setUrlPrefix(), _prefixUrl()
*/
var $_urlPrefix = '';

@@ -279,7 +279,7 @@
*/
function _findNodeType($nodeId, &$nodeUrl, $level)
{
- $nodeUrl = $this->_urlPrefix . ((empty($this->_urlPrefix) || '/' != $nodeUrl{0})? $nodeUrl: substr($nodeUrl, 1));
+ $nodeUrl = $this->_prefixUrl($nodeUrl);
if ($this->_currentUrl == $nodeUrl) {
// menu item that fits to this url - 'active' menu item
return HTML_MENU_ENTRY_ACTIVE;
@@ -292,6 +292,11 @@
}
}

+ function _prefixUrl($nodeUrl)
+ {
+ return $this->_urlPrefix . ((empty($this->_urlPrefix) || '/' != $nodeUrl{0}) ? $nodeUrl : substr($nodeUrl, 1));
+ }
+
/**
* Renders the tree menu ('tree' and 'sitemap')
*
@@ -474,7 +479,7 @@
function _buildUrlMap($menu, $path)
{
foreach ($menu as $nodeId => $node) {
- $url = $this->_urlPrefix . ((empty($this->_urlPrefix) || '/' != $node['url']{0})? $node['url']: substr($node['url'], 1));
+ $url = $this->_prefixUrl($node['url']);
$this->_urlMap[$url] = $path;

if ($url == $this->_currentUrl) {

http://www.uvm.edu/~ashawley/php/HTML_Menu.php-prefixUrl.diff-u