diff options
author | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
---|---|---|
committer | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
commit | 269b942a2bf7b022795e591d9b0ad04526ee7e09 (patch) | |
tree | f465bb5a700d4cc5d72ca6e55e251640a46b869b /system/helpers/inflector_helper.php | |
parent | a25530f6594c7ba45b3faa9537fda9f807069759 (diff) |
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.
Diffstat (limited to 'system/helpers/inflector_helper.php')
-rw-r--r-- | system/helpers/inflector_helper.php | 133 |
1 files changed, 73 insertions, 60 deletions
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 |