| 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); |
| 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); |