1 <?php
  2 
  3 /*
  4  * This file is part of the ICanBoogie package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace ICanBoogie;
 13 
 14 if (!function_exists(__NAMESPACE__ . '\downcase'))
 15 {
 16     /**
 17      * Returns an lowercase string.
 18      *
 19      * @param string $str
 20      *
 21      * @return string
 22      */
 23     function downcase($str)
 24     {
 25         return mb_strtolower($str);
 26     }
 27 }
 28 
 29 if (!function_exists(__NAMESPACE__ . '\upcase'))
 30 {
 31     /**
 32      * Returns an uppercase string.
 33      *
 34      * @param string $str
 35      *
 36      * @return string
 37      */
 38     function upcase($str)
 39     {
 40         return mb_strtoupper($str);
 41     }
 42 }
 43 
 44 if (!function_exists(__NAMESPACE__ . '\capitalize'))
 45 {
 46     /**
 47      * Returns a copy of str with the first character converted to uppercase and the
 48      * remainder to lowercase.
 49      *
 50      * @param string $str
 51      */
 52     function capitalize($str)
 53     {
 54         return upcase(mb_substr($str, 0, 1)) . downcase(mb_substr($str, 1));
 55     }
 56 }
 57 
 58 /**
 59  * Forwards calls to `Inflector::get()->pluralize()`.
 60  *
 61  * @param string $word
 62  * @param string $locale Locale identifier.
 63  *
 64  * @return string
 65  */
 66 function pluralize($word, $locale='en')
 67 {
 68     return Inflector::get($locale)->pluralize($word);
 69 }
 70 
 71 /**
 72  * Forwards calls to `Inflector::get()->singularize()`.
 73  *
 74  * @param string $word
 75  * @param string $locale Locale identifier.
 76  *
 77  * @return string
 78  */
 79 function singularize($word, $locale='en')
 80 {
 81     return Inflector::get($locale)->singularize($word);
 82 }
 83 
 84 /**
 85  * Forwards calls to `Inflector::get()->camelize()`.
 86  *
 87  * @param string $str
 88  * @param bool $uppercase_first_letter
 89  * @param string $locale Locale identifier.
 90  *
 91  * @return string
 92  */
 93 function camelize($str, $uppercase_first_letter=false, $locale='en')
 94 {
 95     return Inflector::get($locale)->camelize($str, $uppercase_first_letter);
 96 }
 97 
 98 /**
 99  * Forwards calls to `Inflector::get()->underscore()`.
100  *
101  * @param string $camel_cased_word
102  * @param string $locale Locale identifier.
103  *
104  * @return string
105  */
106 function underscore($camel_cased_word, $locale='en')
107 {
108     return Inflector::get($locale)->underscore($camel_cased_word);
109 }
110 
111 /**
112  * Forwards calls to `Inflector::get()->hyphenate()`.
113  *
114  * @param string $str
115  * @param string $locale Locale identifier.
116  *
117  * @return string
118  */
119 function hyphenate($str, $locale='en')
120 {
121     return Inflector::get($locale)->hyphenate($str);
122 }
123 
124 /**
125  * Forwards calls to `Inflector::get()->humanize()`.
126  *
127  * @param string $lower_case_and_underscored_word
128  * @param string $locale Locale identifier.
129  *
130  * @return string
131  */
132 function humanize($lower_case_and_underscored_word, $locale='en')
133 {
134     return Inflector::get($locale)->humanize($lower_case_and_underscored_word);
135 }
136 
137 /**
138  * Forwards calls to `Inflector::get()->titleize()`.
139  *
140  * @param string $str
141  * @param string $locale Locale identifier.
142  *
143  * @return string
144  */
145 function titleize($str, $locale='en')
146 {
147     return Inflector::get($locale)->titleize($str);
148 }