3 * $Id: Inflector.php 3189 2007-11-18 20:37:44Z meus $
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the MIT license. For more information, see
19 * <http://www.doctrine-project.org>.
22 namespace Doctrine\Common\Util;
25 * Doctrine inflector has static methods for inflecting text
27 * The methods in these classes are from several different sources collected
28 * across several different php projects and several different authors. The
29 * original author names and emails are not known
31 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
32 * @link www.doctrine-project.org
34 * @version $Revision: 3189 $
35 * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
36 * @author Jonathan H. Wage <jonwage@gmail.com>
41 * Convert word in to the format for a Doctrine table name. Converts 'ModelName' to 'model_name'
43 * @param string $word Word to tableize
44 * @return string $word Tableized word
46 public static function tableize($word)
48 return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word));
52 * Convert a word in to the format for a Doctrine class name. Converts 'table_name' to 'TableName'
54 * @param string $word Word to classify
55 * @return string $word Classified word
57 public static function classify($word)
59 return str_replace(" ", "", ucwords(strtr($word, "_-", " ")));
63 * Camelize a word. This uses the classify() method and turns the first character to lowercase
66 * @return string $word
68 public static function camelize($word)
70 return lcfirst(self::classify($word));