From 269b942a2bf7b022795e591d9b0ad04526ee7e09 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 28 Jan 2008 21:00:20 +0000 Subject: added ability to "extend" helpers * modified Loader to check for prefixed helpers in application/helpers folder * surrounded provided helper functions with if (! function_exists('foo')) conditionals so the user's helper functions take precedent. --- system/helpers/inflector_helper.php | 133 ++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 60 deletions(-) (limited to 'system/helpers/inflector_helper.php') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index b1864cb0b..bf70a6799 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -36,34 +36,36 @@ * @access public * @param string * @return str - */ -function singular($str) -{ - $str = strtolower(trim($str)); - $end = substr($str, -3); + */ +if (! function_exists('singular')) +{ + function singular($str) + { + $str = strtolower(trim($str)); + $end = substr($str, -3); - if ($end == 'ies') - { - $str = substr($str, 0, strlen($str)-3).'y'; - } - elseif ($end == 'ses') - { - $str = substr($str, 0, strlen($str)-2); - } - else - { - $end = substr($str, -1); + if ($end == 'ies') + { + $str = substr($str, 0, strlen($str)-3).'y'; + } + elseif ($end == 'ses') + { + $str = substr($str, 0, strlen($str)-2); + } + else + { + $end = substr($str, -1); - if ($end == 's') - { - $str = substr($str, 0, strlen($str)-1); - } - } + if ($end == 's') + { + $str = substr($str, 0, strlen($str)-1); + } + } - return $str; + return $str; + } } - // -------------------------------------------------------------------- /** @@ -75,32 +77,34 @@ function singular($str) * @param string * @param bool * @return str - */ -function plural($str, $force = FALSE) -{ - $str = strtolower(trim($str)); - $end = substr($str, -1); - - if ($end == 'y') - { - $str = substr($str, 0, strlen($str)-1).'ies'; - } - elseif ($end == 's') - { - if ($force == TRUE) - { - $str .= 'es'; - } - } - else - { - $str .= 's'; - } - - return $str; + */ +if (! function_exists('plural')) +{ + function plural($str, $force = FALSE) + { + $str = strtolower(trim($str)); + $end = substr($str, -1); + + if ($end == 'y') + { + $str = substr($str, 0, strlen($str)-1).'ies'; + } + elseif ($end == 's') + { + if ($force == TRUE) + { + $str .= 'es'; + } + } + else + { + $str .= 's'; + } + + return $str; + } } - // -------------------------------------------------------------------- /** @@ -111,12 +115,15 @@ function plural($str, $force = FALSE) * @access public * @param string * @return str - */ -function camelize($str) -{ - $str = 'x'.strtolower(trim($str)); - $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); - return substr(str_replace(' ', '', $str), 1); + */ +if (! function_exists('camelize')) +{ + function camelize($str) + { + $str = 'x'.strtolower(trim($str)); + $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); + return substr(str_replace(' ', '', $str), 1); + } } // -------------------------------------------------------------------- @@ -129,10 +136,13 @@ function camelize($str) * @access public * @param string * @return str - */ -function underscore($str) + */ +if (! function_exists('underscore')) { - return preg_replace('/[\s]+/', '_', strtolower(trim($str))); + function underscore($str) + { + return preg_replace('/[\s]+/', '_', strtolower(trim($str))); + } } // -------------------------------------------------------------------- @@ -145,10 +155,13 @@ function underscore($str) * @access public * @param string * @return str - */ -function humanize($str) -{ - return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); + */ +if (! function_exists('humanize')) +{ + function humanize($str) + { + return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); + } } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b