diff --git a/lib/Doctrine.php b/lib/Doctrine.php
index ba3d24179..97b5dcd33 100644
--- a/lib/Doctrine.php
+++ b/lib/Doctrine.php
@@ -650,6 +650,19 @@ final class Doctrine
return Doctrine_Manager::connection()->export->exportSchema($directory);
}
+ /**
+ * createTablesFromArray
+ *
+ * Creates database tables for the models in the supplied array
+ *
+ * @param array $array An array of models to be exported
+ * @return void
+ */
+ public static function createTablesFromArray($array)
+ {
+ return Doctrine_Manager::connection()->export->exportClasses($array);
+ }
+
/**
* generateSqlFromModels
*
diff --git a/tests/coverage/Doctrine.html b/tests/coverage/Doctrine.html
index 9bfb00f13..b34dd194c 100644
--- a/tests/coverage/Doctrine.html
+++ b/tests/coverage/Doctrine.html
@@ -16,7 +16,7 @@
/*
|
3 |
- * $Id: Doctrine.php 3015 2007-10-26 04:13:29Z Jonathan.Wage $
+ | * $Id: Doctrine.php 3055 2007-11-01 22:52:40Z zYne $
|
4 |
*
@@ -103,7 +103,7 @@
| * @since 1.0
|
32 |
- * @version $Revision: 3015 $
+ | * @version $Revision: 3055 $
|
33 |
*/
@@ -496,1609 +496,1609 @@
| const ATTR_TBLCLASS_FORMAT = 119;
|
163 |
- const ATTR_EXPORT = 140;
+ | const ATTR_TBLNAME_FORMAT = 120;
|
164 |
- const ATTR_DECIMAL_PLACES = 141;
+ | const ATTR_EXPORT = 140;
|
165 |
-
+ | const ATTR_DECIMAL_PLACES = 141;
|
166 |
- const ATTR_PORTABILITY = 106;
+ |
|
167 |
- const ATTR_VALIDATE = 107;
+ | const ATTR_PORTABILITY = 106;
|
168 |
- const ATTR_COLL_KEY = 108;
+ | const ATTR_VALIDATE = 107;
|
169 |
- const ATTR_QUERY_LIMIT = 109;
+ | const ATTR_COLL_KEY = 108;
|
170 |
- const ATTR_DEFAULT_TABLE_TYPE = 112;
+ | const ATTR_QUERY_LIMIT = 109;
|
171 |
- const ATTR_DEF_TEXT_LENGTH = 113;
+ | const ATTR_DEFAULT_TABLE_TYPE = 112;
|
172 |
- const ATTR_DEF_VARCHAR_LENGTH = 114;
+ | const ATTR_DEF_TEXT_LENGTH = 113;
|
173 |
- const ATTR_DEF_TABLESPACE = 115;
+ | const ATTR_DEF_VARCHAR_LENGTH = 114;
|
174 |
- const ATTR_EMULATE_DATABASE = 116;
+ | const ATTR_DEF_TABLESPACE = 115;
|
175 |
- const ATTR_USE_NATIVE_ENUM = 117;
+ | const ATTR_EMULATE_DATABASE = 116;
|
176 |
- const ATTR_DEFAULT_SEQUENCE = 133;
+ | const ATTR_USE_NATIVE_ENUM = 117;
|
177 |
-
+ | const ATTR_DEFAULT_SEQUENCE = 133;
|
178 |
- const ATTR_FETCHMODE = 118;
+ |
|
179 |
- const ATTR_NAME_PREFIX = 121;
+ | const ATTR_FETCHMODE = 118;
|
180 |
- const ATTR_CREATE_TABLES = 122;
+ | const ATTR_NAME_PREFIX = 121;
|
181 |
- const ATTR_COLL_LIMIT = 123;
+ | const ATTR_CREATE_TABLES = 122;
|
182 |
-
+ | const ATTR_COLL_LIMIT = 123;
|
183 |
- const ATTR_CACHE = 150;
+ |
|
184 |
- const ATTR_CACHE_LIFESPAN = 151;
+ | const ATTR_CACHE = 150;
|
185 |
- const ATTR_LOAD_REFERENCES = 153;
+ | const ATTR_CACHE_LIFESPAN = 151;
|
186 |
- const ATTR_RECORD_LISTENER = 154;
+ | const ATTR_LOAD_REFERENCES = 153;
|
187 |
- const ATTR_THROW_EXCEPTIONS = 155;
+ | const ATTR_RECORD_LISTENER = 154;
|
188 |
-
+ | const ATTR_THROW_EXCEPTIONS = 155;
|
189 |
- /**
+ | const ATTR_DEFAULT_PARAM_NAMESPACE = 156;
|
190 |
- * LIMIT CONSTANTS
+ |
|
191 |
- */
+ | /**
|
192 |
-
+ | * LIMIT CONSTANTS
|
193 |
- /**
+ | */
|
194 |
- * constant for row limiting
+ |
|
195 |
- */
+ | /**
|
196 |
- const LIMIT_ROWS = 1;
+ | * constant for row limiting
|
197 |
-
+ | */
|
198 |
- /**
+ | const LIMIT_ROWS = 1;
|
199 |
- * constant for record limiting
+ |
|
200 |
- */
+ | /**
|
201 |
- const LIMIT_RECORDS = 2;
+ | * constant for record limiting
|
202 |
-
+ | */
|
203 |
- /**
+ | const LIMIT_RECORDS = 2;
|
204 |
- * FETCHMODE CONSTANTS
+ |
|
205 |
- */
+ | /**
|
206 |
-
+ | * FETCHMODE CONSTANTS
|
207 |
- /**
+ | */
|
208 |
- * IMMEDIATE FETCHING
+ |
|
209 |
- * mode for immediate fetching
+ | /**
|
210 |
- */
+ | * IMMEDIATE FETCHING
|
211 |
- const FETCH_IMMEDIATE = 0;
+ | * mode for immediate fetching
|
212 |
-
+ | */
|
213 |
- /**
+ | const FETCH_IMMEDIATE = 0;
|
214 |
- * BATCH FETCHING
+ |
|
215 |
- * mode for batch fetching
+ | /**
|
216 |
- */
+ | * BATCH FETCHING
|
217 |
- const FETCH_BATCH = 1;
+ | * mode for batch fetching
|
218 |
-
+ | */
|
219 |
- /**
+ | const FETCH_BATCH = 1;
|
220 |
- * LAZY FETCHING
+ |
|
221 |
- * mode for offset fetching
+ | /**
|
222 |
- */
+ | * LAZY FETCHING
|
223 |
- const FETCH_OFFSET = 3;
+ | * mode for offset fetching
|
224 |
-
+ | */
|
225 |
- /**
+ | const FETCH_OFFSET = 3;
|
226 |
- * LAZY OFFSET FETCHING
+ |
|
227 |
- * mode for lazy offset fetching
+ | /**
|
228 |
- */
+ | * LAZY OFFSET FETCHING
|
229 |
- const FETCH_LAZY_OFFSET = 4;
+ | * mode for lazy offset fetching
|
230 |
-
+ | */
|
231 |
- /**
+ | const FETCH_LAZY_OFFSET = 4;
|
232 |
- * FETCH CONSTANTS
+ |
|
233 |
- */
+ | /**
|
234 |
-
+ | * FETCH CONSTANTS
|
235 |
-
+ | */
|
236 |
- /**
+ |
|
237 |
- * FETCH VALUEHOLDER
+ |
|
238 |
- */
+ | /**
|
239 |
- const FETCH_VHOLDER = 1;
+ | * FETCH VALUEHOLDER
|
240 |
-
+ | */
|
241 |
- /**
+ | const FETCH_VHOLDER = 1;
|
242 |
- * FETCH RECORD
+ |
|
243 |
- *
+ | /**
|
244 |
- * Specifies that the fetch method shall return Doctrine_Record
+ | * FETCH RECORD
|
245 |
- * objects as the elements of the result set.
+ | *
|
246 |
- *
+ | * Specifies that the fetch method shall return Doctrine_Record
|
247 |
- * This is the default fetchmode.
+ | * objects as the elements of the result set.
|
248 |
- */
+ | *
|
249 |
- const FETCH_RECORD = 2;
+ | * This is the default fetchmode.
|
250 |
-
+ | */
|
251 |
- /**
+ | const FETCH_RECORD = 2;
|
252 |
- * FETCH ARRAY
+ |
|
253 |
- */
+ | /**
|
254 |
- const FETCH_ARRAY = 3;
+ | * FETCH ARRAY
|
255 |
-
+ | */
|
256 |
- /**
+ | const FETCH_ARRAY = 3;
|
257 |
- * PORTABILITY CONSTANTS
+ |
|
258 |
- */
+ | /**
|
259 |
-
+ | * PORTABILITY CONSTANTS
|
260 |
- /**
+ | */
|
261 |
- * Portability: turn off all portability features.
+ |
|
262 |
- * @see self::ATTR_PORTABILITY
+ | /**
|
263 |
- */
+ | * Portability: turn off all portability features.
|
264 |
- const PORTABILITY_NONE = 0;
+ | * @see self::ATTR_PORTABILITY
|
265 |
-
+ | */
|
266 |
- /**
+ | const PORTABILITY_NONE = 0;
|
267 |
- * Portability: convert names of tables and fields to case defined in the
+ |
|
268 |
- * "field_case" option when using the query*(), fetch*() methods.
+ | /**
|
269 |
- * @see self::ATTR_PORTABILITY
+ | * Portability: convert names of tables and fields to case defined in the
|
270 |
- */
+ | * "field_case" option when using the query*(), fetch*() methods.
|
271 |
- const PORTABILITY_FIX_CASE = 1;
+ | * @see self::ATTR_PORTABILITY
|
272 |
-
+ | */
|
273 |
- /**
+ | const PORTABILITY_FIX_CASE = 1;
|
274 |
- * Portability: right trim the data output by query*() and fetch*().
+ |
|
275 |
- * @see self::ATTR_PORTABILITY
+ | /**
|
276 |
- */
+ | * Portability: right trim the data output by query*() and fetch*().
|
277 |
- const PORTABILITY_RTRIM = 2;
+ | * @see self::ATTR_PORTABILITY
|
278 |
-
+ | */
|
279 |
- /**
+ | const PORTABILITY_RTRIM = 2;
|
280 |
- * Portability: force reporting the number of rows deleted.
+ |
|
281 |
- * @see self::ATTR_PORTABILITY
+ | /**
|
282 |
- */
+ | * Portability: force reporting the number of rows deleted.
|
283 |
- const PORTABILITY_DELETE_COUNT = 4;
+ | * @see self::ATTR_PORTABILITY
|
284 |
-
+ | */
|
285 |
- /**
+ | const PORTABILITY_DELETE_COUNT = 4;
|
286 |
- * Portability: convert empty values to null strings in data output by
+ |
|
287 |
- * query*() and fetch*().
+ | /**
|
288 |
- * @see self::ATTR_PORTABILITY
+ | * Portability: convert empty values to null strings in data output by
|
289 |
- */
+ | * query*() and fetch*().
|
290 |
- const PORTABILITY_EMPTY_TO_NULL = 8;
+ | * @see self::ATTR_PORTABILITY
|
291 |
-
+ | */
|
292 |
- /**
+ | const PORTABILITY_EMPTY_TO_NULL = 8;
|
293 |
- * Portability: removes database/table qualifiers from associative indexes
+ |
|
294 |
- * @see self::ATTR_PORTABILITY
+ | /**
|
295 |
- */
+ | * Portability: removes database/table qualifiers from associative indexes
|
296 |
- const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
+ | * @see self::ATTR_PORTABILITY
|
297 |
-
+ | */
|
298 |
- /**
+ | const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
|
299 |
- * Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
+ |
|
300 |
- * @see self::ATTR_PORTABILITY
+ | /**
|
301 |
- */
+ | * Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
|
302 |
- const PORTABILITY_EXPR = 32;
- |
-303 |
-
- |
-304 |
- /**
- |
-305 |
- * Portability: turn on all portability features.
- |
-306 |
* @see self::ATTR_PORTABILITY
|
-307 |
+
303 |
*/
|
+304 |
+ const PORTABILITY_EXPR = 32;
+ |
+305 |
+
+ |
+306 |
+ /**
+ |
+307 |
+ * Portability: turn on all portability features.
+ |
308 |
- const PORTABILITY_ALL = 63;
+ | * @see self::ATTR_PORTABILITY
|
309 |
-
+ | */
|
310 |
- /**
+ | const PORTABILITY_ALL = 63;
|
311 |
- * LOCKMODE CONSTANTS
+ |
|
312 |
- */
+ | /**
|
313 |
-
+ | * LOCKMODE CONSTANTS
|
314 |
- /**
+ | */
|
315 |
- * mode for optimistic locking
+ |
|
316 |
- */
+ | /**
|
317 |
- const LOCK_OPTIMISTIC = 0;
+ | * mode for optimistic locking
|
318 |
-
+ | */
|
319 |
- /**
+ | const LOCK_OPTIMISTIC = 0;
|
320 |
- * mode for pessimistic locking
+ |
|
321 |
- */
+ | /**
|
322 |
- const LOCK_PESSIMISTIC = 1;
+ | * mode for pessimistic locking
|
323 |
-
+ | */
|
324 |
- /**
+ | const LOCK_PESSIMISTIC = 1;
|
325 |
- * EXPORT CONSTANTS
+ |
|
326 |
- */
+ | /**
|
327 |
-
+ | * EXPORT CONSTANTS
|
328 |
- /**
+ | */
|
329 |
- * EXPORT_NONE
+ |
|
330 |
- */
+ | /**
|
331 |
- const EXPORT_NONE = 0;
+ | * EXPORT_NONE
|
332 |
-
+ | */
|
333 |
- /**
+ | const EXPORT_NONE = 0;
|
334 |
- * EXPORT_TABLES
+ |
|
335 |
- */
+ | /**
|
336 |
- const EXPORT_TABLES = 1;
+ | * EXPORT_TABLES
|
337 |
-
+ | */
|
338 |
- /**
+ | const EXPORT_TABLES = 1;
|
339 |
- * EXPORT_CONSTRAINTS
+ |
|
340 |
- */
+ | /**
|
341 |
- const EXPORT_CONSTRAINTS = 2;
+ | * EXPORT_CONSTRAINTS
|
342 |
-
+ | */
|
343 |
- /**
+ | const EXPORT_CONSTRAINTS = 2;
|
344 |
- * EXPORT_PLUGINS
+ |
|
345 |
- */
+ | /**
|
346 |
- const EXPORT_PLUGINS = 4;
+ | * EXPORT_PLUGINS
|
347 |
-
+ | */
|
348 |
- /**
+ | const EXPORT_PLUGINS = 4;
|
349 |
- * EXPORT_ALL
+ |
|
350 |
- */
+ | /**
|
351 |
- const EXPORT_ALL = 7;
+ | * EXPORT_ALL
|
352 |
-
+ | */
|
353 |
- /**
+ | const EXPORT_ALL = 7;
|
354 |
- * HYDRATION CONSTANTS
+ |
|
355 |
- */
+ | /**
|
356 |
- const HYDRATE_RECORD = 2;
+ | * HYDRATION CONSTANTS
|
357 |
-
+ | */
|
358 |
- /**
+ | const HYDRATE_RECORD = 2;
|
359 |
- * HYDRATE_ARRAY
+ |
|
360 |
- */
+ | /**
|
361 |
- const HYDRATE_ARRAY = 3;
+ | * HYDRATE_ARRAY
|
362 |
-
+ | */
|
363 |
- /**
+ | const HYDRATE_ARRAY = 3;
|
364 |
- * HYDRATE_NONE
+ |
|
365 |
- */
+ | /**
|
366 |
- const HYDRATE_NONE = 4;
+ | * HYDRATE_NONE
|
367 |
-
+ | */
|
368 |
- /**
+ | const HYDRATE_NONE = 4;
|
369 |
- * VALIDATION CONSTANTS
+ |
|
370 |
- */
+ | /**
|
371 |
- const VALIDATE_NONE = 0;
+ | * VALIDATION CONSTANTS
|
372 |
-
+ | */
|
373 |
- /**
+ | const VALIDATE_NONE = 0;
|
374 |
- * VALIDATE_LENGTHS
+ |
|
375 |
- */
+ | /**
|
376 |
- const VALIDATE_LENGTHS = 1;
+ | * VALIDATE_LENGTHS
|
377 |
-
+ | */
|
378 |
- /**
+ | const VALIDATE_LENGTHS = 1;
|
379 |
- * VALIDATE_TYPES
+ |
|
380 |
- */
+ | /**
|
381 |
- const VALIDATE_TYPES = 2;
+ | * VALIDATE_TYPES
|
382 |
-
+ | */
|
383 |
- /**
+ | const VALIDATE_TYPES = 2;
|
384 |
- * VALIDATE_CONSTRAINTS
+ |
|
385 |
- */
+ | /**
|
386 |
- const VALIDATE_CONSTRAINTS = 4;
+ | * VALIDATE_CONSTRAINTS
|
387 |
-
+ | */
|
388 |
- /**
+ | const VALIDATE_CONSTRAINTS = 4;
|
389 |
- * VALIDATE_ALL
+ |
|
390 |
- */
+ | /**
|
391 |
- const VALIDATE_ALL = 7;
+ | * VALIDATE_ALL
|
392 |
-
+ | */
|
393 |
- /**
+ | const VALIDATE_ALL = 7;
|
394 |
- * IDENTIFIER_AUTOINC
+ |
|
395 |
- *
+ | /**
|
396 |
- * constant for auto_increment identifier
+ | * IDENTIFIER_AUTOINC
|
397 |
- */
+ | *
|
398 |
- const IDENTIFIER_AUTOINC = 1;
+ | * constant for auto_increment identifier
|
399 |
-
+ | */
|
400 |
- /**
+ | const IDENTIFIER_AUTOINC = 1;
|
401 |
- * IDENTIFIER_SEQUENCE
+ |
|
402 |
- *
+ | /**
|
403 |
- * constant for sequence identifier
+ | * IDENTIFIER_SEQUENCE
|
404 |
- */
+ | *
|
405 |
- const IDENTIFIER_SEQUENCE = 2;
+ | * constant for sequence identifier
|
406 |
-
+ | */
|
407 |
- /**
+ | const IDENTIFIER_SEQUENCE = 2;
|
408 |
- * IDENTIFIER_NATURAL
+ |
|
409 |
- *
+ | /**
|
410 |
- * constant for normal identifier
+ | * IDENTIFIER_NATURAL
|
411 |
- */
+ | *
|
412 |
- const IDENTIFIER_NATURAL = 3;
+ | * constant for normal identifier
|
413 |
-
+ | */
|
414 |
- /**
+ | const IDENTIFIER_NATURAL = 3;
|
415 |
- * IDENTIFIER_COMPOSITE
+ |
|
416 |
- *
+ | /**
|
417 |
- * constant for composite identifier
+ | * IDENTIFIER_COMPOSITE
|
418 |
- */
+ | *
|
419 |
- const IDENTIFIER_COMPOSITE = 4;
+ | * constant for composite identifier
|
420 |
-
- |
-421 |
- /**
- |
-422 |
- * Path
- |
-423 |
- *
- |
-424 |
- * @var string $path doctrine root directory
- |
-425 |
*/
|
-426 |
- private static $_path;
+ |
421 |
+ const IDENTIFIER_COMPOSITE = 4;
|
-427 |
+
422 |
|
-428 |
+
423 |
/**
|
-429 |
- * Debug
+ |
424 |
+ * Path
|
-430 |
+
425 |
*
|
+426 |
+ * @var string $path doctrine root directory
+ |
+427 |
+ */
+ |
+428 |
+ private static $_path;
+ |
+429 |
+
+ |
+430 |
+ /**
+ |
431 |
- * Bool true/false
+ | * Debug
|
432 |
*
|
433 |
- * @var boolean $_debug
+ | * Bool true/false
|
434 |
- */
+ | *
|
435 |
- private static $_debug = false;
+ | * @var boolean $_debug
|
436 |
-
+ | */
|
437 |
- /**
+ | private static $_debug = false;
|
438 |
- * _loadedModels
+ |
|
439 |
- *
+ | /**
|
440 |
- * Array of all the loaded models and the path to each one for autoloading
+ | * _loadedModels
|
441 |
- *
+ | *
|
442 |
- * @var string
+ | * Array of all the loaded models and the path to each one for autoloading
|
443 |
- */
+ | *
|
444 |
- private static $_loadedModels = array();
+ | * @var string
|
445 |
-
+ | */
|
446 |
- /**
+ | private static $_loadedModels = array();
|
447 |
- * __construct
+ |
|
448 |
- *
+ | /**
|
449 |
- * @return void
+ | * __construct
|
450 |
- * @throws Doctrine_Exception
+ | *
|
451 |
- */
+ | * @return void
|
452 |
- public function __construct()
+ | * @throws Doctrine_Exception
|
453 |
- {
+ | */
|
454 |
- throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
+ | public function __construct()
|
455 |
- }
+ | {
|
456 |
-
+ | throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
|
457 |
- /**
+ | }
|
458 |
- * debug
+ |
|
459 |
- *
+ | /**
|
460 |
- * @param string $bool
+ | * debug
|
461 |
- * @return void
+ | *
|
462 |
- */
+ | * @param string $bool
|
463 |
- public static function debug($bool = null)
+ | * @return void
|
464 |
- {
+ | */
|
465 |
- if ($bool !== null) {
+ | public static function debug($bool = null)
|
466 |
- self::$_debug = (bool) $bool;
+ | {
|
467 |
- }
+ | if ($bool !== null) {
|
468 |
-
+ | self::$_debug = (bool) $bool;
|
469 |
- return self::$_debug;
- |
-470 |
- }
- |
-471 |
-
- |
-472 |
- /**
- |
-473 |
- * getPath
- |
-474 |
- * returns the doctrine root
- |
-475 |
- *
- |
-476 |
- * @return string
- |
-477 |
- */
- |
-478 |
- public static function getPath()
- |
-479 |
- {
- |
-480 |
- if ( ! self::$_path) {
- |
-481 |
- self::$_path = dirname(__FILE__);
- |
-482 |
}
|
-483 |
+
470 |
|
+471 |
+ return self::$_debug;
+ |
+472 |
+ }
+ |
+473 |
+
+ |
+474 |
+ /**
+ |
+475 |
+ * getPath
+ |
+476 |
+ * returns the doctrine root
+ |
+477 |
+ *
+ |
+478 |
+ * @return string
+ |
+479 |
+ */
+ |
+480 |
+ public static function getPath()
+ |
+481 |
+ {
+ |
+482 |
+ if ( ! self::$_path) {
+ |
+483 |
+ self::$_path = dirname(__FILE__);
+ |
484 |
- return self::$_path;
+ | }
|
485 |
- }
+ |
|
486 |
-
+ | return self::$_path;
|
487 |
- /**
+ | }
|
488 |
- * loadAll
+ |
|
489 |
- * loads all runtime classes
+ | /**
|
490 |
- *
+ | * loadModels
|
491 |
- * @return void
+ | *
|
492 |
- */
+ | * Recursively load all models from a directory or array of directories
|
493 |
- public static function loadAll()
+ | *
|
494 |
- {
+ | * @param string $directory Path to directory of models or array of directory paths
|
495 |
- return self::loadAllRuntimeClasses();
+ | * @return array $loadedModels
|
496 |
- }
+ | */
|
497 |
-
+ | public static function loadModels($directory)
|
498 |
- /**
+ | {
|
499 |
- * importSchema
+ | if ($directory !== null) {
|
500 |
- * method for importing existing schema to Doctrine_Record classes
+ | $manager = Doctrine_Manager::getInstance();
|
501 |
- *
+ |
|
502 |
- * @param string $directory Directory to write your models to
+ | foreach ((array) $directory as $dir) {
|
503 |
- * @param array $databases Array of databases to generate models for
+ | $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
504 |
- * @return boolean
+ | RecursiveIteratorIterator::LEAVES_ONLY);
|
505 |
- */
+ |
|
506 |
- public static function importSchema($directory, array $databases = array())
+ | foreach ($it as $file) {
|
507 |
- {
+ | $e = explode('.', $file->getFileName());
|
508 |
- return self::generateModelsFromDb($directory, $databases);
+ | if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
509 |
- }
+ | self::$_loadedModels[$e[0]] = $file->getPathName();
|
510 |
-
+ | }
|
511 |
- /**
+ | }
|
512 |
- * exportSchema
+ | }
|
513 |
- * method for exporting Doctrine_Record classes to a schema
+ | }
|
514 |
- *
- |
-515 |
- * @param string $directory Directory containing your models
- |
-516 |
- * @return void
- |
-517 |
- */
- |
-518 |
- public static function exportSchema($directory = null)
- |
-519 |
- {
- |
-520 |
- return self::createTablesFromModels($directory);
- |
-521 |
- }
- |
-522 |
|
-523 |
+
515 |
+ return self::getLoadedModels(array_keys(self::$_loadedModels));
+ |
+516 |
+ }
+ |
+517 |
+
+ |
+518 |
/**
|
-524 |
- * exportSql
+ |
519 |
+ * getLoadedModels
|
-525 |
- * method for exporting Doctrine_Record classes to a schema
- |
-526 |
+
520 |
*
|
+521 |
+ * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes()
+ |
+522 |
+ *
+ |
+523 |
+ * Will filter through an array of classes and return the Doctrine_Records out of them.
+ |
+524 |
+ * If you do not specify $classes it will return all of the currently loaded Doctrine_Records
+ |
+525 |
+ *
+ |
+526 |
+ * @param $classes Array of classes to filter through, otherwise uses get_declared_classes()
+ |
527 |
- * @param string $directory
+ | * @return array $loadedModels
|
528 |
*/
|
529 |
- public static function exportSql($directory = null)
+ | public static function getLoadedModels($classes = null)
|
530 |
{
|
531 |
- return self::generateSqlFromModels($directory);
- |
-532 |
- }
- |
-533 |
-
- |
-534 |
- /**
- |
-535 |
- * loadAllRuntimeClasses
- |
-536 |
- *
- |
-537 |
- * loads all runtime classes
- |
-538 |
- *
- |
-539 |
- * @return void
- |
-540 |
- */
- |
-541 |
- public static function loadAllRuntimeClasses()
- |
-542 |
- {
- |
-543 |
- $classes = Doctrine_Compiler::getRuntimeClasses();
- |
-544 |
-
- |
-545 |
- foreach ($classes as $class) {
- |
-546 |
- self::autoload($class);
- |
-547 |
- }
- |
-548 |
- }
- |
-549 |
-
- |
-550 |
- /**
- |
-551 |
- * loadModels
- |
-552 |
- *
- |
-553 |
- * Recursively load all models from a directory or array of directories
- |
-554 |
- *
- |
-555 |
- * @param string $directory Path to directory of models or array of directory paths
- |
-556 |
- * @return array $loadedModels
- |
-557 |
- */
- |
-558 |
- public static function loadModels($directory)
- |
-559 |
- {
- |
-560 |
- if ($directory !== null) {
- |
-561 |
- $manager = Doctrine_Manager::getInstance();
- |
-562 |
-
- |
-563 |
- foreach ((array) $directory as $dir) {
- |
-564 |
- $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
- |
-565 |
- RecursiveIteratorIterator::LEAVES_ONLY);
- |
-566 |
-
- |
-567 |
- foreach ($it as $file) {
- |
-568 |
- $e = explode('.', $file->getFileName());
- |
-569 |
- if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
- |
-570 |
- self::$_loadedModels[$e[0]] = $file->getPathName();
- |
-571 |
- }
- |
-572 |
- }
- |
-573 |
- }
- |
-574 |
- }
- |
-575 |
-
- |
-576 |
- return self::getLoadedModels(array_keys(self::$_loadedModels));
- |
-577 |
- }
- |
-578 |
-
- |
-579 |
- /**
- |
-580 |
- * getLoadedModels
- |
-581 |
- *
- |
-582 |
- * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes()
- |
-583 |
- *
- |
-584 |
- * Will filter through an array of classes and return the Doctrine_Records out of them.
- |
-585 |
- * If you do not specify $classes it will return all of the currently loaded Doctrine_Records
- |
-586 |
- *
- |
-587 |
- * @param $classes Array of classes to filter through, otherwise uses get_declared_classes()
- |
-588 |
- * @return array $loadedModels
- |
-589 |
- */
- |
-590 |
- public static function getLoadedModels($classes = null)
- |
-591 |
- {
- |
-592 |
if ($classes === null) {
|
-593 |
+
532 |
$classes = get_declared_classes();
|
-594 |
+
533 |
+ $classes = array_merge($classes, array_keys(self::$_loadedModels));
+ |
+534 |
}
|
-595 |
+
535 |
|
-596 |
+
536 |
$parent = new ReflectionClass('Doctrine_Record');
|
-597 |
+
537 |
|
-598 |
+
538 |
$loadedModels = array();
|
-599 |
+
539 |
|
-600 |
+
540 |
foreach ((array) $classes as $name) {
|
-601 |
+
541 |
$class = new ReflectionClass($name);
|
-602 |
+
542 |
|
-603 |
+
543 |
// Skip the following classes
|
-604 |
+
544 |
// - abstract classes
|
-605 |
+
545 |
// - not a subclass of Doctrine_Record
|
-606 |
+
546 |
// - don't have a setTableDefinition method
|
-607 |
+
547 |
if ($class->isAbstract() ||
|
-608 |
+
548 |
!$class->isSubClassOf($parent) ||
|
-609 |
+
549 |
!$class->hasMethod('setTableDefinition')) {
|
-610 |
+
550 |
continue;
|
-611 |
+
551 |
}
|
-612 |
+
552 |
|
-613 |
+
553 |
$loadedModels[] = $name;
|
-614 |
+
554 |
}
|
-615 |
+
555 |
|
-616 |
+
556 |
return $loadedModels;
|
-617 |
+
557 |
}
|
-618 |
+
558 |
|
-619 |
+
559 |
/**
|
-620 |
+
560 |
* getConnectionByTableName
|
-621 |
+
561 |
*
|
-622 |
+
562 |
* Get the connection object for a table by the actual table name
|
-623 |
+
563 |
*
|
-624 |
+
564 |
* @param string $tableName
|
-625 |
+
565 |
* @return object Doctrine_Connection
|
-626 |
+
566 |
*/
|
-627 |
+
567 |
public static function getConnectionByTableName($tableName)
|
-628 |
+
568 |
{
|
-629 |
+
569 |
$loadedModels = self::getLoadedModels();
|
-630 |
+
570 |
|
-631 |
+
571 |
foreach ($loadedModels as $name) {
|
-632 |
+
572 |
$model = new $name();
|
-633 |
+
573 |
$table = $model->getTable();
|
-634 |
+
574 |
|
-635 |
+
575 |
if ($table->getTableName() == $tableName) {
|
-636 |
+
576 |
return $table->getConnection();
|
-637 |
+
577 |
}
|
-638 |
+
578 |
}
|
-639 |
+
579 |
|
-640 |
+
580 |
return Doctrine_Manager::connection();
|
-641 |
+
581 |
}
|
-642 |
+
582 |
|
-643 |
+
583 |
/**
|
-644 |
+
584 |
* generateModelsFromDb
|
-645 |
+
585 |
*
|
-646 |
+
586 |
* method for importing existing schema to Doctrine_Record classes
|
-647 |
+
587 |
*
|
-648 |
+
588 |
* @param string $directory Directory to write your models to
|
-649 |
+
589 |
* @param array $databases Array of databases to generate models for
|
-650 |
+
590 |
* @return boolean
|
-651 |
+
591 |
* @throws Exception
|
-652 |
+
592 |
*/
|
-653 |
+
593 |
public static function generateModelsFromDb($directory, array $databases = array())
|
-654 |
+
594 |
{
|
-655 |
+
595 |
return Doctrine_Manager::connection()->import->importSchema($directory, $databases);
|
-656 |
+
596 |
}
|
-657 |
+
597 |
|
-658 |
+
598 |
/**
|
-659 |
+
599 |
* generateYamlFromDb
|
-660 |
+
600 |
*
|
-661 |
+
601 |
* Generates models from database to temporary location then uses those models to generate a yaml schema file.
|
-662 |
+
602 |
* This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
|
-663 |
+
603 |
*
|
-664 |
+
604 |
* @param string $yamlPath Path to write oyur yaml schema file to
|
-665 |
+
605 |
* @return void
|
-666 |
+
606 |
*/
|
-667 |
+
607 |
public static function generateYamlFromDb($yamlPath)
|
-668 |
+
608 |
{
|
-669 |
+
609 |
$directory = '/tmp/tmp_doctrine_models';
|
-670 |
+
610 |
|
-671 |
+
611 |
Doctrine::generateModelsFromDb($directory);
|
-672 |
+
612 |
|
-673 |
+
613 |
$export = new Doctrine_Export_Schema();
|
-674 |
+
614 |
|
-675 |
+
615 |
$result = $export->exportSchema($yamlPath, 'yml', $directory);
|
-676 |
+
616 |
|
-677 |
+
617 |
exec('rm -rf ' . $directory);
|
-678 |
+
618 |
|
-679 |
+
619 |
return $result;
|
-680 |
+
620 |
}
|
-681 |
+
621 |
|
-682 |
+
622 |
/**
|
-683 |
+
623 |
* generateModelsFromYaml
|
-684 |
+
624 |
*
|
-685 |
+
625 |
* Generate a yaml schema file from an existing directory of models
|
+626 |
+ *
+ |
+627 |
+ * @param string $yamlPath Path to your yaml schema files
+ |
+628 |
+ * @param string $directory Directory to generate your models in
+ |
+629 |
+ * @param array $options Array of options to pass to the schema importer
+ |
+630 |
+ * @return void
+ |
+631 |
+ */
+ |
+632 |
+ public static function generateModelsFromYaml($yamlPath, $directory, $options = array())
+ |
+633 |
+ {
+ |
+634 |
+ $import = new Doctrine_Import_Schema();
+ |
+635 |
+ $import->setOptions($options);
+ |
+636 |
+
+ |
+637 |
+ return $import->importSchema($yamlPath, 'yml', $directory);
+ |
+638 |
+ }
+ |
+639 |
+
+ |
+640 |
+ /**
+ |
+641 |
+ * createTablesFromModels
+ |
+642 |
+ *
+ |
+643 |
+ * Creates database tables for the models in the specified directory
+ |
+644 |
+ *
+ |
+645 |
+ * @param string $directory Directory containing your models
+ |
+646 |
+ * @return void
+ |
+647 |
+ */
+ |
+648 |
+ public static function createTablesFromModels($directory = null)
+ |
+649 |
+ {
+ |
+650 |
+ return Doctrine_Manager::connection()->export->exportSchema($directory);
+ |
+651 |
+ }
+ |
+652 |
+
+ |
+653 |
+ /**
+ |
+654 |
+ * createTablesFromArray
+ |
+655 |
+ *
+ |
+656 |
+ * Creates database tables for the models in the supplied array
+ |
+657 |
+ *
+ |
+658 |
+ * @param array $array An array of models to be exported
+ |
+659 |
+ * @return void
+ |
+660 |
+ */
+ |
+661 |
+ public static function createTablesFromArray($array)
+ |
+662 |
+ {
+ |
+663 |
+ return Doctrine_Manager::connection()->export->exportClasses($array);
+ |
+664 |
+ }
+ |
+665 |
+
+ |
+666 |
+ /**
+ |
+667 |
+ * generateSqlFromModels
+ |
+668 |
+ *
+ |
+669 |
+ * @param string $directory
+ |
+670 |
+ * @return string $build String of sql queries. One query per line
+ |
+671 |
+ */
+ |
+672 |
+ public static function generateSqlFromModels($directory = null)
+ |
+673 |
+ {
+ |
+674 |
+ $sql = Doctrine_Manager::connection()->export->exportSql($directory);
+ |
+675 |
+
+ |
+676 |
+ $build = '';
+ |
+677 |
+ foreach ($sql as $query) {
+ |
+678 |
+ $build .= $query.";\n";
+ |
+679 |
+ }
+ |
+680 |
+
+ |
+681 |
+ return $build;
+ |
+682 |
+ }
+ |
+683 |
+
+ |
+684 |
+ /**
+ |
+685 |
+ * generateYamlFromModels
+ |
686 |
*
|
687 |
- * @param string $yamlPath Path to your yaml schema files
+ | * Generate yaml schema file for the models in the specified directory
|
688 |
- * @param string $directory Directory to generate your models in
+ | *
|
689 |
- * @param array $options Array of options to pass to the schema importer
+ | * @param string $yamlPath Path to your yaml schema files
|
690 |
- * @return void
+ | * @param string $directory Directory to generate your models in
|
691 |
- */
+ | * @return void
|
692 |
- public static function generateModelsFromYaml($yamlPath, $directory, $options = array())
+ | */
|
693 |
- {
+ | public static function generateYamlFromModels($yamlPath, $directory)
|
694 |
- $import = new Doctrine_Import_Schema();
+ | {
|
695 |
- $import->setOption('generateBaseClasses', true);
+ | $export = new Doctrine_Export_Schema();
|
696 |
|
697 |
- return $import->importSchema($yamlPath, 'yml', $directory);
+ | return $export->exportSchema($yamlPath, 'yml', $directory);
|
698 |
}
@@ -2110,19 +2110,19 @@
| /**
|
701 |
- * createTablesFromModels
+ | * createDatabases
|
702 |
*
|
703 |
- * Creates database tables for the models in the specified directory
+ | * Creates databases for connections
|
704 |
*
|
705 |
- * @param string $directory Directory containing your models
+ | * @param string $specifiedConnections Array of connections you wish to create the database for
|
706 |
* @return void
@@ -2131,118 +2131,118 @@
| */
|
708 |
- public static function createTablesFromModels($directory = null)
+ | public static function createDatabases($specifiedConnections = array())
|
709 |
{
|
710 |
- return Doctrine_Manager::connection()->export->exportSchema($directory);
+ | if ( ! is_array($specifiedConnections)) {
|
711 |
- }
+ | $specifiedConnections = (array) $specifiedConnections;
|
712 |
-
- |
-713 |
- /**
- |
-714 |
- * generateSqlFromModels
- |
-715 |
- *
- |
-716 |
- * @param string $directory
- |
-717 |
- * @return string $build String of sql queries. One query per line
- |
-718 |
- */
- |
-719 |
- public static function generateSqlFromModels($directory = null)
- |
-720 |
- {
- |
-721 |
- $sql = Doctrine_Manager::connection()->export->exportSql($directory);
- |
-722 |
-
- |
-723 |
- $build = '';
- |
-724 |
- foreach ($sql as $query) {
- |
-725 |
- $build .= $query.";\n";
- |
-726 |
}
|
-727 |
+
713 |
|
+714 |
+ $manager = Doctrine_Manager::getInstance();
+ |
+715 |
+ $connections = $manager->getConnections();
+ |
+716 |
+
+ |
+717 |
+ foreach ($connections as $name => $connection) {
+ |
+718 |
+ if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
+ |
+719 |
+ continue;
+ |
+720 |
+ }
+ |
+721 |
+
+ |
+722 |
+ $info = $manager->parsePdoDsn($connection->getOption('dsn'));
+ |
+723 |
+ $username = $connection->getOption('username');
+ |
+724 |
+ $password = $connection->getOption('password');
+ |
+725 |
+
+ |
+726 |
+ // Make connection without database specified so we can create it
+ |
+727 |
+ $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false);
+ |
728 |
- return $build;
+ |
|
729 |
- }
+ | try {
|
730 |
-
+ | // Create database
|
731 |
- /**
+ | $connect->export->createDatabase($name);
|
732 |
- * generateYamlFromModels
+ |
|
733 |
- *
+ | // Close the tmp connection with no database
|
734 |
- * Generate yaml schema file for the models in the specified directory
+ | $manager->closeConnection($connect);
|
735 |
- *
+ |
|
736 |
- * @param string $yamlPath Path to your yaml schema files
+ | // Close original connection
|
737 |
- * @param string $directory Directory to generate your models in
+ | $manager->closeConnection($connection);
|
738 |
- * @return void
+ |
|
739 |
- */
+ | // Reopen original connection with newly created database
|
740 |
- public static function generateYamlFromModels($yamlPath, $directory)
+ | $manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true);
|
741 |
- {
+ | } catch (Exception $e) {
|
742 |
- $export = new Doctrine_Export_Schema();
+ |
|
743 |
-
+ | }
|
744 |
- return $export->exportSchema($yamlPath, 'yml', $directory);
+ | }
|
745 |
- }
+ | }
|
746 |
@@ -2251,19 +2251,19 @@
| /**
|
748 |
- * createDatabases
+ | * dropDatabases
|
749 |
*
|
750 |
- * Creates databases for connections
+ | * Drops databases for connections
|
751 |
*
|
752 |
- * @param string $specifiedConnections Array of connections you wish to create the database for
+ | * @param string $specifiedConnections Array of connections you wish to drop the database for
|
753 |
* @return void
@@ -2272,7 +2272,7 @@
| */
|
755 |
- public static function createDatabases($specifiedConnections = array())
+ | public static function dropDatabases($specifiedConnections = array())
|
756 |
{
@@ -2293,98 +2293,98 @@
| $manager = Doctrine_Manager::getInstance();
|
762 |
- $connections = $manager->getConnections();
- |
-763 |
|
+763 |
+ $connections = $manager->getConnections();
+ |
764 |
- foreach ($connections as $name => $connection) {
+ |
|
765 |
- if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
+ | foreach ($connections as $name => $connection) {
|
766 |
- continue;
+ | if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
|
767 |
- }
+ | continue;
|
768 |
-
+ | }
|
769 |
- $info = $manager->parsePdoDsn($connection->getOption('dsn'));
+ |
|
770 |
- $username = $connection->getOption('username');
- |
-771 |
- $password = $connection->getOption('password');
- |
-772 |
-
- |
-773 |
- // Make connection without database specified so we can create it
- |
-774 |
- $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false);
- |
-775 |
-
- |
-776 |
try {
|
-777 |
- // Create database
+ |
771 |
+ $connection->export->dropDatabase($name);
|
-778 |
- $connect->export->createDatabase($name);
- |
-779 |
-
- |
-780 |
- // Close the tmp connection with no database
- |
-781 |
- $manager->closeConnection($connect);
- |
-782 |
-
- |
-783 |
- // Close original connection
- |
-784 |
- $manager->closeConnection($connection);
- |
-785 |
-
- |
-786 |
- // Reopen original connection with newly created database
- |
-787 |
- $manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true);
- |
-788 |
+
772 |
} catch (Exception $e) {
|
-789 |
+
773 |
|
-790 |
+
774 |
}
|
-791 |
+
775 |
}
|
-792 |
+
776 |
}
|
+777 |
+
+ |
+778 |
+ /**
+ |
+779 |
+ * dumpData
+ |
+780 |
+ *
+ |
+781 |
+ * Dump data to a yaml fixtures file
+ |
+782 |
+ *
+ |
+783 |
+ * @param string $yamlPath Path to write the yaml data fixtures to
+ |
+784 |
+ * @param string $individualFiles Whether or not to dump data to individual fixtures files
+ |
+785 |
+ * @return void
+ |
+786 |
+ */
+ |
+787 |
+ public static function dumpData($yamlPath, $individualFiles = false)
+ |
+788 |
+ {
+ |
+789 |
+ $data = new Doctrine_Data();
+ |
+790 |
+
+ |
+791 |
+ return $data->exportData($yamlPath, 'yml', array(), $individualFiles);
+ |
+792 |
+ }
+ |
793 |
|
@@ -2392,355 +2392,355 @@
/**
|
795 |
- * dropDatabases
+ | * loadData
|
796 |
*
|
797 |
- * Drops databases for connections
+ | * Load data from a yaml fixtures file.
|
798 |
- *
+ | * The output of dumpData can be fed to loadData
|
799 |
- * @param string $specifiedConnections Array of connections you wish to drop the database for
+ | *
|
800 |
- * @return void
+ | * @param string $yamlPath Path to your yaml data fixtures
|
801 |
- */
+ | * @param string $append Whether or not to append the data
|
802 |
- public static function dropDatabases($specifiedConnections = array())
+ | * @return void
|
803 |
- {
+ | */
|
804 |
- if ( ! is_array($specifiedConnections)) {
+ | public static function loadData($yamlPath, $append = false)
|
805 |
- $specifiedConnections = (array) $specifiedConnections;
+ | {
|
806 |
- }
+ | $data = new Doctrine_Data();
|
807 |
|
808 |
- $manager = Doctrine_Manager::getInstance();
+ | if ( ! $append) {
|
809 |
-
+ | $data->purge();
|
810 |
- $connections = $manager->getConnections();
+ | }
|
811 |
|
812 |
- foreach ($connections as $name => $connection) {
- |
-813 |
- if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
- |
-814 |
- continue;
- |
-815 |
- }
- |
-816 |
-
- |
-817 |
- try {
- |
-818 |
- $connection->export->dropDatabase($name);
- |
-819 |
- } catch (Exception $e) {
- |
-820 |
-
- |
-821 |
- }
- |
-822 |
- }
- |
-823 |
- }
- |
-824 |
-
- |
-825 |
- /**
- |
-826 |
- * dumpData
- |
-827 |
- *
- |
-828 |
- * Dump data to a yaml fixtures file
- |
-829 |
- *
- |
-830 |
- * @param string $yamlPath Path to write the yaml data fixtures to
- |
-831 |
- * @param string $individualFiles Whether or not to dump data to individual fixtures files
- |
-832 |
- * @return void
- |
-833 |
- */
- |
-834 |
- public static function dumpData($yamlPath, $individualFiles = false)
- |
-835 |
- {
- |
-836 |
- $data = new Doctrine_Data();
- |
-837 |
-
- |
-838 |
- return $data->exportData($yamlPath, 'yml', array(), $individualFiles);
- |
-839 |
- }
- |
-840 |
-
- |
-841 |
- /**
- |
-842 |
- * loadData
- |
-843 |
- *
- |
-844 |
- * Load data from a yaml fixtures file.
- |
-845 |
- * The output of dumpData can be fed to loadData
- |
-846 |
- *
- |
-847 |
- * @param string $yamlPath Path to your yaml data fixtures
- |
-848 |
- * @param string $append Whether or not to append the data
- |
-849 |
- * @return void
- |
-850 |
- */
- |
-851 |
- public static function loadData($yamlPath, $append = false)
- |
-852 |
- {
- |
-853 |
- $data = new Doctrine_Data();
- |
-854 |
-
- |
-855 |
- if ( ! $append) {
- |
-856 |
- $data->purge();
- |
-857 |
- }
- |
-858 |
-
- |
-859 |
return $data->importData($yamlPath, 'yml');
|
-860 |
+
813 |
}
|
-861 |
+
814 |
|
-862 |
+
815 |
/**
|
-863 |
- * loadDummyData
+ |
816 |
+ * migrate
|
-864 |
+
817 |
+ *
+ |
+818 |
+ * Migrate database to specified $to version. Migrates from current to latest if you do not specify.
+ |
+819 |
*
|
-865 |
- * Populdate your models with dummy data
+ |
820 |
+ * @param string $migrationsPath Path to migrations directory which contains your migration classes
|
-866 |
- *
+ |
821 |
+ * @param string $to Version you wish to migrate to.
|
-867 |
- * @param string $append Whether or not to append the data
+ |
822 |
+ * @return bool true
|
-868 |
- * @param string $num Number of records to populate
+ |
823 |
+ * @throws new Doctrine_Migration_Exception
|
-869 |
- * @return void
- |
-870 |
+
824 |
*/
|
-871 |
- public static function loadDummyData($append, $num = 5)
+ |
825 |
+ public static function migrate($migrationsPath, $to = null)
|
-872 |
+
826 |
{
|
+827 |
+ $migration = new Doctrine_Migration($migrationsPath);
+ |
+828 |
+
+ |
+829 |
+ return $migration->migrate($to);
+ |
+830 |
+ }
+ |
+831 |
+
+ |
+832 |
+ /**
+ |
+833 |
+ * generateMigrationClass
+ |
+834 |
+ *
+ |
+835 |
+ * Generate new migration class skeleton
+ |
+836 |
+ *
+ |
+837 |
+ * @param string $className Name of the Migration class to generate
+ |
+838 |
+ * @param string $migrationsPath Path to directory which contains your migration classes
+ |
+839 |
+ */
+ |
+840 |
+ public static function generateMigrationClass($className, $migrationsPath)
+ |
+841 |
+ {
+ |
+842 |
+ $builder = new Doctrine_Migration_Builder($migrationsPath);
+ |
+843 |
+
+ |
+844 |
+ return $builder->generateMigrationClass($className);
+ |
+845 |
+ }
+ |
+846 |
+
+ |
+847 |
+ /**
+ |
+848 |
+ * generateMigrationsFromDb
+ |
+849 |
+ *
+ |
+850 |
+ * @param string $migrationsPath
+ |
+851 |
+ * @return void
+ |
+852 |
+ * @throws new Doctrine_Migration_Exception
+ |
+853 |
+ */
+ |
+854 |
+ public static function generateMigrationsFromDb($migrationsPath)
+ |
+855 |
+ {
+ |
+856 |
+ $builder = new Doctrine_Migration_Builder($migrationsPath);
+ |
+857 |
+
+ |
+858 |
+ return $builder->generateMigrationsFromDb();
+ |
+859 |
+ }
+ |
+860 |
+
+ |
+861 |
+ /**
+ |
+862 |
+ * generateMigrationsFromModels
+ |
+863 |
+ *
+ |
+864 |
+ * @param string $migrationsPath
+ |
+865 |
+ * @param string $modelsPath
+ |
+866 |
+ * @return void
+ |
+867 |
+ */
+ |
+868 |
+ public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null)
+ |
+869 |
+ {
+ |
+870 |
+ $builder = new Doctrine_Migration_Builder($migrationsPath);
+ |
+871 |
+
+ |
+872 |
+ return $builder->generateMigrationsFromModels($modelsPath);
+ |
873 |
- $data = new Doctrine_Data();
+ | }
|
874 |
|
875 |
- if ( ! $append) {
- |
-876 |
- $data->purge();
- |
-877 |
- }
- |
-878 |
-
- |
-879 |
- return $data->importDummyData($num);
- |
-880 |
- }
- |
-881 |
-
- |
-882 |
/**
|
-883 |
- * migrate
+ |
876 |
+ * getTable
|
-884 |
- *
- |
-885 |
- * Migrate database to specified $to version. Migrates from current to latest if you do not specify.
- |
-886 |
+
877 |
*
|
+878 |
+ * @param string $tableName
+ |
+879 |
+ * @return void
+ |
+880 |
+ */
+ |
+881 |
+ public static function getTable($tableName)
+ |
+882 |
+ {
+ |
+883 |
+ return Doctrine_Manager::table($tableName);
+ |
+884 |
+ }
+ |
+885 |
+
+ |
+886 |
+ /**
+ |
887 |
- * @param string $migrationsPath Path to migrations directory which contains your migration classes
+ | * fileFinder
|
888 |
- * @param string $to Version you wish to migrate to.
+ | *
|
889 |
- * @return bool true
+ | * @param string $type
|
890 |
- * @throws new Doctrine_Migration_Exception
+ | * @return void
|
891 |
*/
|
892 |
- public static function migrate($migrationsPath, $to = null)
+ | public static function fileFinder($type)
|
893 |
{
|
894 |
- $migration = new Doctrine_Migration($migrationsPath);
+ | return Doctrine_FileFinder::type($type);
|
895 |
-
- |
-896 |
- return $migration->migrate($to);
- |
-897 |
}
|
-898 |
+
896 |
|
-899 |
+
897 |
/**
|
-900 |
- * generateMigrationClass
+ |
898 |
+ * compile
|
-901 |
+
899 |
*
|
+900 |
+ * method for making a single file of most used doctrine runtime components
+ |
+901 |
+ * including the compiled file instead of multiple files (in worst
+ |
902 |
- * Generate new migration class skeleton
+ | * cases dozens of files) can improve performance by an order of magnitude
|
903 |
*
|
904 |
- * @param string $className Name of the Migration class to generate
+ | * @param string $target
|
905 |
- * @param string $migrationsPath Path to directory which contains your migration classes
+ | * @param array $includedDrivers
|
906 |
- */
+ | * @throws Doctrine_Exception
|
907 |
- public static function generateMigrationClass($className, $migrationsPath)
+ | * @return void
|
908 |
- {
+ | */
|
909 |
- $builder = new Doctrine_Migration_Builder($migrationsPath);
+ | public static function compile($target = null, $includedDrivers = array())
|
910 |
-
+ | {
|
911 |
- return $builder->generateMigrationClass($className);
+ | return Doctrine_Compiler::compile($target, $includedDrivers);
|
912 |
}
@@ -2752,668 +2752,432 @@
| /**
|
915 |
- * generateMigrationsFromDb
+ | * autoload
|
916 |
*
|
917 |
- * @param string $migrationsPath
- |
-918 |
- * @return void
- |
-919 |
- * @throws new Doctrine_Migration_Exception
- |
-920 |
- */
- |
-921 |
- public static function generateMigrationsFromDb($migrationsPath)
- |
-922 |
- {
- |
-923 |
- $builder = new Doctrine_Migration_Builder($migrationsPath);
- |
-924 |
-
- |
-925 |
- return $builder->generateMigrationsFromDb();
- |
-926 |
- }
- |
-927 |
-
- |
-928 |
- /**
- |
-929 |
- * generateMigrationsFromModels
- |
-930 |
- *
- |
-931 |
- * @param string $migrationsPath
- |
-932 |
- * @param string $modelsPath
- |
-933 |
- * @return void
- |
-934 |
- */
- |
-935 |
- public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null)
- |
-936 |
- {
- |
-937 |
- $builder = new Doctrine_Migration_Builder($migrationsPath);
- |
-938 |
-
- |
-939 |
- return $builder->generateMigrationsFromModels($modelsPath);
- |
-940 |
- }
- |
-941 |
-
- |
-942 |
- /**
- |
-943 |
- * getTable
- |
-944 |
- *
- |
-945 |
- * @param string $tableName
- |
-946 |
- * @return void
- |
-947 |
- */
- |
-948 |
- public static function getTable($tableName)
- |
-949 |
- {
- |
-950 |
- return Doctrine_Manager::table($tableName);
- |
-951 |
- }
- |
-952 |
-
- |
-953 |
- /**
- |
-954 |
- * connection
- |
-955 |
- *
- |
-956 |
- * @param string $adapter
- |
-957 |
- * @param string $name
- |
-958 |
- * @return void
- |
-959 |
- */
- |
-960 |
- public static function connection($adapter, $name = null)
- |
-961 |
- {
- |
-962 |
- return Doctrine_Manager::connection($adapter, $name);
- |
-963 |
- }
- |
-964 |
-
- |
-965 |
- /**
- |
-966 |
- * fileFinder
- |
-967 |
- *
- |
-968 |
- * @param string $type
- |
-969 |
- * @return void
- |
-970 |
- */
- |
-971 |
- public static function fileFinder($type)
- |
-972 |
- {
- |
-973 |
- return Doctrine_FileFinder::type($type);
- |
-974 |
- }
- |
-975 |
-
- |
-976 |
- /**
- |
-977 |
- * compile
- |
-978 |
- *
- |
-979 |
- * method for making a single file of most used doctrine runtime components
- |
-980 |
- * including the compiled file instead of multiple files (in worst
- |
-981 |
- * cases dozens of files) can improve performance by an order of magnitude
- |
-982 |
- *
- |
-983 |
- * @param string $target
- |
-984 |
- *
- |
-985 |
- * @throws Doctrine_Exception
- |
-986 |
- * @return void
- |
-987 |
- */
- |
-988 |
- public static function compile($target = null, $includedDrivers = array())
- |
-989 |
- {
- |
-990 |
- return Doctrine_Compiler::compile($target, $includedDrivers);
- |
-991 |
- }
- |
-992 |
-
- |
-993 |
- /**
- |
-994 |
- * autoload
- |
-995 |
- *
- |
-996 |
* simple autoload function
|
-997 |
+
918 |
* returns true if the class was loaded, otherwise false
|
-998 |
+
919 |
*
|
-999 |
+
920 |
* @param string $classname
|
-1000 |
+
921 |
* @return boolean
|
-1001 |
+
922 |
*/
|
-1002 |
+
923 |
public static function autoload($className)
|
-1003 |
+
924 |
{
|
-1004 |
+
925 |
if (class_exists($className, false)) {
|
-1005 |
+
926 |
return false;
|
-1006 |
+
927 |
}
|
-1007 |
+
928 |
|
-1008 |
+
929 |
if ( ! self::$_path) {
|
-1009 |
+
930 |
self::$_path = dirname(__FILE__);
|
-1010 |
+
931 |
}
|
-1011 |
+
932 |
|
-1012 |
+
933 |
$class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
-1013 |
+
934 |
|
-1014 |
+
935 |
if (file_exists($class)) {
|
-1015 |
+
936 |
require_once($class);
|
-1016 |
+
937 |
|
-1017 |
+
938 |
return true;
|
-1018 |
+
939 |
}
|
-1019 |
+
940 |
|
-1020 |
+
941 |
$loadedModels = self::$_loadedModels;
|
-1021 |
+
942 |
|
-1022 |
+
943 |
if (isset($loadedModels[$className]) && file_exists($loadedModels[$className])) {
|
-1023 |
+
944 |
require_once($loadedModels[$className]);
|
-1024 |
+
945 |
|
-1025 |
+
946 |
return true;
|
-1026 |
+
947 |
}
|
-1027 |
+
948 |
|
-1028 |
+
949 |
return false;
|
-1029 |
+
950 |
}
|
-1030 |
+
951 |
|
-1031 |
+
952 |
/**
|
-1032 |
+
953 |
* dump
|
-1033 |
+
954 |
*
|
-1034 |
+
955 |
* dumps a given variable
|
-1035 |
+
956 |
*
|
-1036 |
+
957 |
* @param mixed $var a variable of any type
|
-1037 |
+
958 |
* @param boolean $output whether to output the content
|
-1038 |
+
959 |
* @return void|string
|
-1039 |
+
960 |
*/
|
-1040 |
+
961 |
public static function dump($var, $output = true)
|
-1041 |
+
962 |
{
|
-1042 |
+
963 |
$ret = array();
|
-1043 |
+
964 |
switch (gettype($var)) {
|
-1044 |
+
965 |
case 'array':
|
-1045 |
+
966 |
$ret[] = 'Array(';
|
-1046 |
+
967 |
foreach ($var as $k => $v) {
|
-1047 |
+
968 |
$ret[] = $k . ' : ' . self::dump($v, false);
|
-1048 |
+
969 |
}
|
-1049 |
+
970 |
$ret[] = ")";
|
-1050 |
+
971 |
break;
|
-1051 |
+
972 |
case 'object':
|
-1052 |
+
973 |
$ret[] = 'Object(' . get_class($var) . ')';
|
-1053 |
+
974 |
break;
|
-1054 |
+
975 |
default:
|
-1055 |
+
976 |
$ret[] = var_export($var, true);
|
-1056 |
+
977 |
}
|
-1057 |
+
978 |
if ($output) {
|
-1058 |
+
979 |
print implode("\n", $ret);
|
-1059 |
+
980 |
}
|
-1060 |
+
981 |
return implode("\n", $ret);
|
-1061 |
+
982 |
}
|
-1062 |
+
983 |
|
-1063 |
+
984 |
/**
|
-1064 |
+
985 |
* tableize
|
-1065 |
+
986 |
*
|
-1066 |
+
987 |
* returns table name from class name
|
-1067 |
+
988 |
*
|
-1068 |
+
989 |
* @param string $classname
|
-1069 |
+
990 |
* @return string
|
-1070 |
+
991 |
*/
|
-1071 |
+
992 |
public static function tableize($classname)
|
-1072 |
+
993 |
{
|
-1073 |
+
994 |
return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
|
-1074 |
+
995 |
}
|
-1075 |
+
996 |
|
-1076 |
+
997 |
/**
|
-1077 |
+
998 |
* classify
|
-1078 |
+
999 |
*
|
-1079 |
+
1000 |
* returns class name from table name
|
-1080 |
+
1001 |
*
|
-1081 |
+
1002 |
* @param string $tablename
|
-1082 |
+
1003 |
* @return string
|
-1083 |
+
1004 |
*/
|
-1084 |
+
1005 |
public static function classify($tablename)
|
-1085 |
+
1006 |
{
|
-1086 |
+
1007 |
return preg_replace_callback('~(_?)(_)([\w])~', array("Doctrine", "classifyCallback"), ucfirst($tablename));
|
-1087 |
+
1008 |
}
|
-1088 |
+
1009 |
|
-1089 |
+
1010 |
/**
|
-1090 |
+
1011 |
* classifyCallback
|
-1091 |
+
1012 |
*
|
-1092 |
+
1013 |
* Callback function to classify a classname propperly.
|
-1093 |
+
1014 |
*
|
-1094 |
+
1015 |
* @param array $matches An array of matches from a pcre_replace call
|
-1095 |
+
1016 |
* @return string A string with matches 1 and mathces 3 in upper case.
|
-1096 |
+
1017 |
*/
|
-1097 |
+
1018 |
public static function classifyCallback($matches)
|
-1098 |
+
1019 |
{
|
-1099 |
+
1020 |
return $matches[1] . strtoupper($matches[3]);
|
-1100 |
+
1021 |
}
|
-1101 |
+
1022 |
|
-1102 |
+
1023 |
/**
|
-1103 |
+
1024 |
* isValidClassName
|
-1104 |
+
1025 |
*
|
-1105 |
+
1026 |
* checks for valid class name (uses camel case and underscores)
|
-1106 |
+
1027 |
*
|
-1107 |
+
1028 |
* @param string $classname
|
-1108 |
+
1029 |
* @return boolean
|
-1109 |
+
1030 |
*/
|
-1110 |
+
1031 |
public static function isValidClassname($classname)
|
-1111 |
+
1032 |
{
|
-1112 |
+
1033 |
if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) {
|
-1113 |
+
1034 |
return false;
|
-1114 |
+
1035 |
}
|
-1115 |
+
1036 |
|
-1116 |
+
1037 |
return true;
|
-1117 |
+
1038 |
}
|
-1118 |
+
1039 |
|
-1119 |
+
1040 |
/**
|
-1120 |
+
1041 |
* makeDirectories
|
-1121 |
+
1042 |
*
|
-1122 |
+
1043 |
* Makes the directories for a path recursively
|
-1123 |
+
1044 |
*
|
-1124 |
+
1045 |
* @param string $path
|
-1125 |
+
1046 |
* @return void
|
-1126 |
+
1047 |
*/
|
-1127 |
+
1048 |
public static function makeDirectories($path, $mode = 0777)
|
-1128 |
+
1049 |
{
|
-1129 |
+
1050 |
if (is_dir($path) || is_file($path))
|
-1130 |
+
1051 |
{
|
-1131 |
+
1052 |
return true;
|
-1132 |
+
1053 |
}
|
-1133 |
+
1054 |
|
-1134 |
+
1055 |
return mkdir($path, $mode, true);
|
-1135 |
+
1056 |
}
|
-1136 |
-} |
+1057 |
+}
+ |