. */ namespace Doctrine\Common\Util; /** * Doctrine inflector has static methods for inflecting text * * The methods in these classes are from several different sources collected * across several different php projects and several different authors. The * original author names and emails are not known * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org * @since 1.0 * @version $Revision: 3189 $ * @author Konsta Vesterinen * @author Jonathan H. Wage */ class Inflector { /** * Convert word in to the format for a Doctrine table name. Converts 'ModelName' to 'model_name' * * @param string $word Word to tableize * @return string $word Tableized word */ public static function tableize($word) { return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word)); } /** * Convert a word in to the format for a Doctrine class name. Converts 'table_name' to 'TableName' * * @param string $word Word to classify * @return string $word Classified word */ public static function classify($word) { $word = preg_replace('/[$]/', '', $word); return preg_replace_callback('~(_?)(_)([\w])~', array(__CLASS__, "classifyCallback"), ucfirst(strtolower($word))); } /** * Callback function to classify a classname properly. * * @param array $matches An array of matches from a pcre_replace call * @return string $string A string with matches 1 and mathces 3 in upper case. */ public static function classifyCallback($matches) { return $matches[1] . strtoupper($matches[3]); } /** * Camelize a word. This uses the classify() method and turns the first character to lowercase * * @param string $word * @return string $word */ public static function camelize($word) { return lcfirst(self::classify($word)); } }