Show
Ignore:
Timestamp:
11/28/07 02:21:42 (14 months ago)
Author:
jwage
Message:

Consolidated a few things. Initial entry of Inflector class. Moved some methods from Doctrine base class to Doctrine_Lib and Doctrine_Inflector.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine.php

    r3250 r3258  
    10691069                $ret[] = var_export($var, true); 
    10701070        } 
     1071 
    10711072        if ($output) { 
    10721073            print implode("\n", $ret); 
    10731074        } 
     1075 
    10741076        return implode("\n", $ret); 
    10751077    } 
     
    10831085     * @return string 
    10841086     */ 
    1085     public static function tableize($classname) 
    1086     { 
    1087          return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname)); 
     1087    public static function tableize($className) 
     1088    { 
     1089         return Doctrine_Inflector::tableize($className); 
    10881090    } 
    10891091 
     
    10981100    public static function classify($tableName) 
    10991101    { 
    1100         return preg_replace_callback('~(_?)(_)([\w])~', array("Doctrine", "classifyCallback"), ucfirst(strtolower($tableName))); 
    1101     } 
    1102  
    1103     /** 
    1104      * classifyCallback 
    1105      * 
    1106      * Callback function to classify a classname properly. 
    1107      * 
    1108      * @param array $matches An array of matches from a pcre_replace call 
    1109      * @return string A string with matches 1 and mathces 3 in upper case. 
    1110      */ 
    1111     public static function classifyCallback($matches) 
    1112     { 
    1113         return $matches[1] . strtoupper($matches[3]); 
     1102        return Doctrine_Inflector::classify($tableName); 
    11141103    } 
    11151104 
     
    11221111     * @return boolean 
    11231112     */ 
    1124     public static function isValidClassname($classname) 
    1125     { 
    1126         if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) { 
    1127             return false; 
    1128         } 
    1129  
    1130         return true; 
    1131     } 
    1132  
    1133     /** 
    1134      * makeDirectories 
    1135      * 
    1136      * Makes the directories for a path recursively 
    1137      * 
    1138      * @param string $path 
    1139      * @return void 
    1140      */ 
    1141     public static function makeDirectories($path, $mode = 0777) 
    1142     { 
    1143         if ( ! $path) { 
    1144           return false; 
    1145         } 
    1146  
    1147         if (is_dir($path) || is_file($path)) { 
    1148           return true; 
    1149         } 
    1150  
    1151         return mkdir($path, $mode, true); 
    1152     } 
    1153  
    1154     /** 
    1155      * removeDirectories 
    1156      * 
    1157      * @param string $folderPath 
    1158      * @return void 
    1159      */ 
    1160     public static function removeDirectories($folderPath) 
    1161     { 
    1162         if (is_dir($folderPath)) 
    1163         { 
    1164             foreach (scandir($folderPath) as $value) 
    1165             { 
    1166                 if ($value != '.' && $value != '..') 
    1167                 { 
    1168                     $value = $folderPath . "/" . $value; 
    1169  
    1170                     if (is_dir($value)) { 
    1171                         self::removeDirectories($value); 
    1172                     } else if (is_file($value)) { 
    1173                         @unlink($value); 
    1174                     } 
    1175                 } 
    1176             } 
    1177  
    1178             return rmdir ( $folderPath ); 
    1179         } else { 
    1180             return false; 
    1181         } 
    1182     } 
    1183  
    1184     /** 
    1185      * getValidators 
    1186      * 
    1187      * Get available doctrine validators 
    1188      * 
    1189      * @return array $validators 
    1190      */ 
    1191     public static function getValidators() 
    1192     { 
    1193         if (empty(self::$_validators)) { 
    1194             $dir = Doctrine::getPath() . DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR . 'Validator'; 
    1195  
    1196             $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY); 
    1197             foreach ($files as $file) { 
    1198                 $e = explode('.', $file->getFileName()); 
    1199  
    1200                 if (end($e) == 'php') { 
    1201                     $name = strtolower($e[0]); 
    1202  
    1203                     self::$_validators[$name] = $name; 
    1204                 } 
    1205             } 
    1206         } 
    1207  
    1208         return self::$_validators; 
     1113    public static function isValidClassname($className) 
     1114    { 
     1115        return Doctrine_Lib::isValidClassName($className); 
    12091116    } 
    12101117}