Created
August 19, 2010 22:59
-
-
Save balupton/539149 to your computer and use it in GitHub Desktop.
Navigation Menu View Helper does not support templates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This is the populate function mentioned in the patch. | |
// Included here as was unsure where the best place to put it in Zend Framework would be. | |
/** | |
* Populates some text with a set of params | |
* @version 1, January 30, 2010 | |
* @param array $array | |
* @return mixed | |
* @author Benjamin "balupton" Lupton <[email protected]> - {@link http://www.balupton.com/} | |
*/ | |
function populate ( $text, $params = null, $sprintf = null ) { | |
# Prepare | |
$result = ''; | |
# Ensure params is an array | |
if ( !$params ) $params = array(); elseif ( !is_array($params) ) $params = array($params); | |
# Use sprintf? | |
if ( $sprintf === null ) { | |
# Detect | |
$sprintf = is_simple_array($params); | |
} | |
# Apply sprintf? | |
if ( $sprintf ) { | |
# Populate simple | |
$result = vsprintf($text, $params); | |
} | |
else { | |
# Populate advanced | |
$result = ' '.$text; | |
$result = preg_replace('/([^\\\\])?\\$([a-zA-Z0-9_\\.]+)/ie', 'preg_unescape("${1}") . delve(\\$params, preg_unescape("${2}"))', $result); | |
$result = substr($result,1); | |
$result = str_replace(array('\\$','\\.'), array('$','.'), $result); | |
} | |
# Return result | |
return $result; | |
} | |
/** | |
* Unescape a string a pregex replace function | |
* @version 1, February 01, 2010 | |
* @param string $value | |
* @return string | |
* @author Benjamin "balupton" Lupton <[email protected]> - {@link http://www.balupton.com/} | |
*/ | |
function preg_unescape ( $value ) { | |
/* | |
* When using the e modifier, this function escapes some characters (namely ', ", \ and null) in the strings that replace the backreferences. | |
* This is done to ensure that no syntax errors arise from backreference usage with either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")'). | |
* Make sure you are aware of PHP's string syntax to know exactly how the interpreted string will look like. | |
*/ | |
$result = str_replace(array("\\'", '\\"', '\\\\', '\\0'), array("'", '"', '\\', '\0'), $value); | |
return $result; | |
} | |
/** | |
* Checks if the array is a simple array | |
* @version 1, January 30, 2010 | |
* @param array $array | |
* @return mixed | |
* @author Benjamin "balupton" Lupton <[email protected]> - {@link http://www.balupton.com/} | |
*/ | |
function is_simple_array ( array $array ) { | |
return is_numeric(implode('',array_keys($array))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?=$this->menu('front.actions') | |
->setTemplate('<span class="title">$label</span>') | |
->render()?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related Zend Framework Issue:
http://framework.zend.com/issues/browse/ZF-10346