diff --git a/tests/coverage/Doctrine.html b/tests/coverage/Doctrine.html
index 2da749e65..9bfb00f13 100644
--- a/tests/coverage/Doctrine.html
+++ b/tests/coverage/Doctrine.html
@@ -16,7 +16,7 @@
/*
|
3 |
- * $Id: Doctrine.php 2989 2007-10-22 16:32:07Z romanb $
+ | * $Id: Doctrine.php 3015 2007-10-26 04:13:29Z Jonathan.Wage $
|
4 |
*
@@ -103,7 +103,7 @@
| * @since 1.0
|
32 |
- * @version $Revision: 2989 $
+ | * @version $Revision: 3015 $
|
33 |
*/
@@ -1315,1971 +1315,2105 @@
| private static $_debug = false;
|
436 |
-
+ |
|
437 |
/**
|
438 |
- * __construct
+ | * _loadedModels
|
439 |
- *
+ | *
|
440 |
- * @return void
+ | * Array of all the loaded models and the path to each one for autoloading
|
441 |
- * @throws Doctrine_Exception
+ | *
|
442 |
- */
+ | * @var string
|
443 |
- public function __construct()
+ | */
|
444 |
- {
+ | private static $_loadedModels = array();
|
445 |
- throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
+ |
|
446 |
- }
+ | /**
|
447 |
-
+ | * __construct
|
448 |
- /**
+ | *
|
449 |
- * debug
+ | * @return void
|
450 |
- *
- |
-451 |
- * @param string $bool
- |
-452 |
- * @return void
- |
-453 |
- */
- |
-454 |
- public static function debug($bool = null)
- |
-455 |
- {
- |
-456 |
- if ($bool !== null) {
- |
-457 |
- self::$_debug = (bool) $bool;
- |
-458 |
- }
- |
-459 |
-
- |
-460 |
- return self::$_debug;
- |
-461 |
- }
- |
-462 |
-
- |
-463 |
- /**
- |
-464 |
- * getPath
- |
-465 |
- * returns the doctrine root
- |
-466 |
- *
- |
-467 |
- * @return string
- |
-468 |
- */
- |
-469 |
- public static function getPath()
- |
-470 |
- {
- |
-471 |
- if ( ! self::$_path) {
- |
-472 |
- self::$_path = dirname(__FILE__);
- |
-473 |
- }
- |
-474 |
-
- |
-475 |
- return self::$_path;
- |
-476 |
- }
- |
-477 |
-
- |
-478 |
- /**
- |
-479 |
- * loadAll
- |
-480 |
- * loads all runtime classes
- |
-481 |
- *
- |
-482 |
- * @return void
- |
-483 |
- */
- |
-484 |
- public static function loadAll()
- |
-485 |
- {
- |
-486 |
- return self::loadAllRuntimeClasses();
- |
-487 |
- }
- |
-488 |
-
- |
-489 |
- /**
- |
-490 |
- * importSchema
- |
-491 |
- * method for importing existing schema to Doctrine_Record classes
- |
-492 |
- *
- |
-493 |
- * @param string $directory Directory to write your models to
- |
-494 |
- * @param array $databases Array of databases to generate models for
- |
-495 |
- * @return boolean
- |
-496 |
- */
- |
-497 |
- public static function importSchema($directory, array $databases = array())
- |
-498 |
- {
- |
-499 |
- return self::generateModelsFromDb($directory, $databases);
- |
-500 |
- }
- |
-501 |
-
- |
-502 |
- /**
- |
-503 |
- * exportSchema
- |
-504 |
- * method for exporting Doctrine_Record classes to a schema
- |
-505 |
- *
- |
-506 |
- * @param string $directory Directory containing your models
- |
-507 |
- * @return void
- |
-508 |
- */
- |
-509 |
- public static function exportSchema($directory = null)
- |
-510 |
- {
- |
-511 |
- return self::createTablesFromModels($directory);
- |
-512 |
- }
- |
-513 |
-
- |
-514 |
- /**
- |
-515 |
- * exportSql
- |
-516 |
- * method for exporting Doctrine_Record classes to a schema
- |
-517 |
- *
- |
-518 |
- * @param string $directory
- |
-519 |
- */
- |
-520 |
- public static function exportSql($directory = null)
- |
-521 |
- {
- |
-522 |
- return self::generateSqlFromModels($directory);
- |
-523 |
- }
- |
-524 |
-
- |
-525 |
- /**
- |
-526 |
- * loadAllRuntimeClasses
- |
-527 |
- *
- |
-528 |
- * loads all runtime classes
- |
-529 |
- *
- |
-530 |
- * @return void
- |
-531 |
- */
- |
-532 |
- public static function loadAllRuntimeClasses()
- |
-533 |
- {
- |
-534 |
- $classes = Doctrine_Compiler::getRuntimeClasses();
- |
-535 |
-
- |
-536 |
- foreach ($classes as $class) {
- |
-537 |
- self::autoload($class);
- |
-538 |
- }
- |
-539 |
- }
- |
-540 |
-
- |
-541 |
- /**
- |
-542 |
- * loadModels
- |
-543 |
- *
- |
-544 |
- * Recursively load all models from a directory or array of directories
- |
-545 |
- *
- |
-546 |
- * @param string $directory Path to directory of models or array of directory paths
- |
-547 |
- * @return array $loadedModels
- |
-548 |
- */
- |
-549 |
- public static function loadModels($directory)
- |
-550 |
- {
- |
-551 |
- $declared = get_declared_classes();
- |
-552 |
-
- |
-553 |
- if ($directory !== null) {
- |
-554 |
- foreach ((array) $directory as $dir) {
- |
-555 |
- $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
- |
-556 |
- RecursiveIteratorIterator::LEAVES_ONLY);
- |
-557 |
-
- |
-558 |
- foreach ($it as $file) {
- |
-559 |
- $e = explode('.', $file->getFileName());
- |
-560 |
- if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
- |
-561 |
- require_once $file->getPathName();
- |
-562 |
- }
- |
-563 |
- }
- |
-564 |
- }
- |
-565 |
-
- |
-566 |
- $declared = array_diff(get_declared_classes(), $declared);
- |
-567 |
- }
- |
-568 |
-
- |
-569 |
- return self::getLoadedModels($declared);
- |
-570 |
- }
- |
-571 |
-
- |
-572 |
- /**
- |
-573 |
- * getLoadedModels
- |
-574 |
- *
- |
-575 |
- * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes()
- |
-576 |
- *
- |
-577 |
- * Will filter through an array of classes and return the Doctrine_Records out of them.
- |
-578 |
- * If you do not specify $classes it will return all of the currently loaded Doctrine_Records
- |
-579 |
- *
- |
-580 |
- * @param $classes Array of classes to filter through, otherwise uses get_declared_classes()
- |
-581 |
- * @return array $loadedModels
- |
-582 |
- */
- |
-583 |
- public static function getLoadedModels($classes = null)
- |
-584 |
- {
- |
-585 |
- if ($classes === null) {
- |
-586 |
- $classes = get_declared_classes();
- |
-587 |
- }
- |
-588 |
-
- |
-589 |
- $parent = new ReflectionClass('Doctrine_Record');
- |
-590 |
-
- |
-591 |
- $loadedModels = array();
- |
-592 |
-
- |
-593 |
- foreach ((array) $classes as $name) {
- |
-594 |
- $class = new ReflectionClass($name);
- |
-595 |
-
- |
-596 |
- // Skip the following classes
- |
-597 |
- // - abstract classes
- |
-598 |
- // - not a subclass of Doctrine_Record
- |
-599 |
- // - don't have a setTableDefinition method
- |
-600 |
- if ($class->isAbstract() ||
- |
-601 |
- !$class->isSubClassOf($parent) ||
- |
-602 |
- !$class->hasMethod('setTableDefinition')) {
- |
-603 |
- continue;
- |
-604 |
- }
- |
-605 |
-
- |
-606 |
- $loadedModels[] = $name;
- |
-607 |
- }
- |
-608 |
-
- |
-609 |
- return $loadedModels;
- |
-610 |
- }
- |
-611 |
-
- |
-612 |
- /**
- |
-613 |
- * getConnectionByTableName
- |
-614 |
- *
- |
-615 |
- * Get the connection object for a table by the actual table name
- |
-616 |
- *
- |
-617 |
- * @param string $tableName
- |
-618 |
- * @return object Doctrine_Connection
- |
-619 |
- */
- |
-620 |
- public static function getConnectionByTableName($tableName)
- |
-621 |
- {
- |
-622 |
- $loadedModels = self::getLoadedModels();
- |
-623 |
-
- |
-624 |
- foreach ($loadedModels as $name) {
- |
-625 |
- $model = new $name();
- |
-626 |
- $table = $model->getTable();
- |
-627 |
-
- |
-628 |
- if ($table->getTableName() == $tableName) {
- |
-629 |
- return $table->getConnection();
- |
-630 |
- }
- |
-631 |
- }
- |
-632 |
-
- |
-633 |
- return Doctrine_Manager::connection();
- |
-634 |
- }
- |
-635 |
-
- |
-636 |
- /**
- |
-637 |
- * generateModelsFromDb
- |
-638 |
- *
- |
-639 |
- * method for importing existing schema to Doctrine_Record classes
- |
-640 |
- *
- |
-641 |
- * @param string $directory Directory to write your models to
- |
-642 |
- * @param array $databases Array of databases to generate models for
- |
-643 |
- * @return boolean
- |
-644 |
- * @throws Exception
- |
-645 |
- */
- |
-646 |
- public static function generateModelsFromDb($directory, array $databases = array())
- |
-647 |
- {
- |
-648 |
- return Doctrine_Manager::connection()->import->importSchema($directory, $databases);
- |
-649 |
- }
- |
-650 |
-
- |
-651 |
- /**
- |
-652 |
- * generateYamlFromDb
- |
-653 |
- *
- |
-654 |
- * Generates models from database to temporary location then uses those models to generate a yaml schema file.
- |
-655 |
- * This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
- |
-656 |
- *
- |
-657 |
- * @param string $yamlPath Path to write oyur yaml schema file to
- |
-658 |
- * @return void
- |
-659 |
- */
- |
-660 |
- public static function generateYamlFromDb($yamlPath)
- |
-661 |
- {
- |
-662 |
- $directory = '/tmp/tmp_doctrine_models';
- |
-663 |
-
- |
-664 |
- Doctrine::generateModelsFromDb($directory);
- |
-665 |
-
- |
-666 |
- $export = new Doctrine_Export_Schema();
- |
-667 |
-
- |
-668 |
- $result = $export->exportSchema($yamlPath, 'yml', $directory);
- |
-669 |
-
- |
-670 |
- exec('rm -rf ' . $directory);
- |
-671 |
-
- |
-672 |
- return $result;
- |
-673 |
- }
- |
-674 |
-
- |
-675 |
- /**
- |
-676 |
- * generateModelsFromYaml
- |
-677 |
- *
- |
-678 |
- * Generate a yaml schema file from an existing directory of models
- |
-679 |
- *
- |
-680 |
- * @param string $yamlPath Path to your yaml schema files
- |
-681 |
- * @param string $directory Directory to generate your models in
- |
-682 |
- * @return void
- |
-683 |
- */
- |
-684 |
- public static function generateModelsFromYaml($yamlPath, $directory)
- |
-685 |
- {
- |
-686 |
- $import = new Doctrine_Import_Schema();
- |
-687 |
- $import->generateBaseClasses(true);
- |
-688 |
-
- |
-689 |
- return $import->importSchema($yamlPath, 'yml', $directory);
- |
-690 |
- }
- |
-691 |
-
- |
-692 |
- /**
- |
-693 |
- * createTablesFromModels
- |
-694 |
- *
- |
-695 |
- * Creates database tables for the models in the specified directory
- |
-696 |
- *
- |
-697 |
- * @param string $directory Directory containing your models
- |
-698 |
- * @return void
- |
-699 |
- */
- |
-700 |
- public static function createTablesFromModels($directory = null)
- |
-701 |
- {
- |
-702 |
- return Doctrine_Manager::connection()->export->exportSchema($directory);
- |
-703 |
- }
- |
-704 |
-
- |
-705 |
- /**
- |
-706 |
- * generateSqlFromModels
- |
-707 |
- *
- |
-708 |
- * @param string $directory
- |
-709 |
- * @return string $build String of sql queries. One query per line
- |
-710 |
- */
- |
-711 |
- public static function generateSqlFromModels($directory = null)
- |
-712 |
- {
- |
-713 |
- $sql = Doctrine_Manager::connection()->export->exportSql($directory);
- |
-714 |
-
- |
-715 |
- $build = '';
- |
-716 |
- foreach ($sql as $query) {
- |
-717 |
- $build .= $query.";\n";
- |
-718 |
- }
- |
-719 |
-
- |
-720 |
- return $build;
- |
-721 |
- }
- |
-722 |
-
- |
-723 |
- /**
- |
-724 |
- * generateYamlFromModels
- |
-725 |
- *
- |
-726 |
- * Generate yaml schema file for the models in the specified directory
- |
-727 |
- *
- |
-728 |
- * @param string $yamlPath Path to your yaml schema files
- |
-729 |
- * @param string $directory Directory to generate your models in
- |
-730 |
- * @return void
- |
-731 |
- */
- |
-732 |
- public static function generateYamlFromModels($yamlPath, $directory)
- |
-733 |
- {
- |
-734 |
- $export = new Doctrine_Export_Schema();
- |
-735 |
-
- |
-736 |
- return $export->exportSchema($yamlPath, 'yml', $directory);
- |
-737 |
- }
- |
-738 |
-
- |
-739 |
- /**
- |
-740 |
- * createDatabases
- |
-741 |
- *
- |
-742 |
- * Creates databases for connections
- |
-743 |
- *
- |
-744 |
- * @param string $specifiedConnections Array of connections you wish to create the database for
- |
-745 |
- * @return void
- |
-746 |
- */
- |
-747 |
- public static function createDatabases($specifiedConnections = array())
- |
-748 |
- {
- |
-749 |
- if ( ! is_array($specifiedConnections)) {
- |
-750 |
- $specifiedConnections = (array) $specifiedConnections;
- |
-751 |
- }
- |
-752 |
-
- |
-753 |
- $manager = Doctrine_Manager::getInstance();
- |
-754 |
- $connections = $manager->getConnections();
- |
-755 |
-
- |
-756 |
- foreach ($connections as $name => $connection) {
- |
-757 |
- if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
- |
-758 |
- continue;
- |
-759 |
- }
- |
-760 |
-
- |
-761 |
- $info = $manager->parsePdoDsn($connection->getOption('dsn'));
- |
-762 |
- $username = $connection->getOption('username');
- |
-763 |
- $password = $connection->getOption('password');
- |
-764 |
-
- |
-765 |
- // Make connection without database specified so we can create it
- |
-766 |
- $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false);
- |
-767 |
-
- |
-768 |
- try {
- |
-769 |
- // Create database
- |
-770 |
- $connect->export->createDatabase($name);
- |
-771 |
-
- |
-772 |
- // Close the tmp connection with no database
- |
-773 |
- $manager->closeConnection($connect);
- |
-774 |
-
- |
-775 |
- // Close original connection
- |
-776 |
- $manager->closeConnection($connection);
- |
-777 |
-
- |
-778 |
- // Reopen original connection with newly created database
- |
-779 |
- $manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true);
- |
-780 |
- } catch (Exception $e) {
- |
-781 |
-
- |
-782 |
- }
- |
-783 |
- }
- |
-784 |
- }
- |
-785 |
-
- |
-786 |
- /**
- |
-787 |
- * dropDatabases
- |
-788 |
- *
- |
-789 |
- * Drops databases for connections
- |
-790 |
- *
- |
-791 |
- * @param string $specifiedConnections Array of connections you wish to drop the database for
- |
-792 |
- * @return void
- |
-793 |
- */
- |
-794 |
- public static function dropDatabases($specifiedConnections = array())
- |
-795 |
- {
- |
-796 |
- if ( ! is_array($specifiedConnections)) {
- |
-797 |
- $specifiedConnections = (array) $specifiedConnections;
- |
-798 |
- }
- |
-799 |
-
- |
-800 |
- $manager = Doctrine_Manager::getInstance();
- |
-801 |
-
- |
-802 |
- $connections = $manager->getConnections();
- |
-803 |
-
- |
-804 |
- foreach ($connections as $name => $connection) {
- |
-805 |
- if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
- |
-806 |
- continue;
- |
-807 |
- }
- |
-808 |
-
- |
-809 |
- try {
- |
-810 |
- $connection->export->dropDatabase($name);
- |
-811 |
- } catch (Exception $e) {
- |
-812 |
-
- |
-813 |
- }
- |
-814 |
- }
- |
-815 |
- }
- |
-816 |
-
- |
-817 |
- /**
- |
-818 |
- * dumpData
- |
-819 |
- *
- |
-820 |
- * Dump data to a yaml fixtures file
- |
-821 |
- *
- |
-822 |
- * @param string $yamlPath Path to write the yaml data fixtures to
- |
-823 |
- * @param string $individualFiles Whether or not to dump data to individual fixtures files
- |
-824 |
- * @return void
- |
-825 |
- */
- |
-826 |
- public static function dumpData($yamlPath, $individualFiles = false)
- |
-827 |
- {
- |
-828 |
- $data = new Doctrine_Data();
- |
-829 |
-
- |
-830 |
- return $data->exportData($yamlPath, 'yml', array(), $individualFiles);
- |
-831 |
- }
- |
-832 |
-
- |
-833 |
- /**
- |
-834 |
- * loadData
- |
-835 |
- *
- |
-836 |
- * Load data from a yaml fixtures file.
- |
-837 |
- * The output of dumpData can be fed to loadData
- |
-838 |
- *
- |
-839 |
- * @param string $yamlPath Path to your yaml data fixtures
- |
-840 |
- * @param string $append Whether or not to append the data
- |
-841 |
- * @return void
- |
-842 |
- */
- |
-843 |
- public static function loadData($yamlPath, $append = false)
- |
-844 |
- {
- |
-845 |
- $data = new Doctrine_Data();
- |
-846 |
-
- |
-847 |
- if ( ! $append) {
- |
-848 |
- $data->purge();
- |
-849 |
- }
- |
-850 |
-
- |
-851 |
- return $data->importData($yamlPath, 'yml');
- |
-852 |
- }
- |
-853 |
-
- |
-854 |
- /**
- |
-855 |
- * loadDummyData
- |
-856 |
- *
- |
-857 |
- * Populdate your models with dummy data
- |
-858 |
- *
- |
-859 |
- * @param string $append Whether or not to append the data
- |
-860 |
- * @param string $num Number of records to populate
- |
-861 |
- * @return void
- |
-862 |
- */
- |
-863 |
- public static function loadDummyData($append, $num = 5)
- |
-864 |
- {
- |
-865 |
- $data = new Doctrine_Data();
- |
-866 |
-
- |
-867 |
- if ( ! $append) {
- |
-868 |
- $data->purge();
- |
-869 |
- }
- |
-870 |
-
- |
-871 |
- return $data->importDummyData($num);
- |
-872 |
- }
- |
-873 |
-
- |
-874 |
- /**
- |
-875 |
- * migrate
- |
-876 |
- *
- |
-877 |
- * Migrate database to specified $to version. Migrates from current to latest if you do not specify.
- |
-878 |
- *
- |
-879 |
- * @param string $migrationsPath Path to migrations directory which contains your migration classes
- |
-880 |
- * @param string $to Version you wish to migrate to.
- |
-881 |
- * @return bool true
- |
-882 |
- * @throws new Doctrine_Migration_Exception
- |
-883 |
- */
- |
-884 |
- public static function migrate($migrationsPath, $to = null)
- |
-885 |
- {
- |
-886 |
- $migration = new Doctrine_Migration($migrationsPath);
- |
-887 |
-
- |
-888 |
- return $migration->migrate($to);
- |
-889 |
- }
- |
-890 |
-
- |
-891 |
- /**
- |
-892 |
- * generateMigrationClass
- |
-893 |
- *
- |
-894 |
- * Generate new migration class skeleton
- |
-895 |
- *
- |
-896 |
- * @param string $className Name of the Migration class to generate
- |
-897 |
- * @param string $migrationsPath Path to directory which contains your migration classes
- |
-898 |
- */
- |
-899 |
- public static function generateMigrationClass($className, $migrationsPath)
- |
-900 |
- {
- |
-901 |
- $builder = new Doctrine_Migration_Builder($migrationsPath);
- |
-902 |
-
- |
-903 |
- return $builder->generateMigrationClass($className);
- |
-904 |
- }
- |
-905 |
-
- |
-906 |
- /**
- |
-907 |
- * generateMigrationsFromDb
- |
-908 |
- *
- |
-909 |
- * @param string $migrationsPath
- |
-910 |
- * @return void
- |
-911 |
- * @throws new Doctrine_Migration_Exception
- |
-912 |
- */
- |
-913 |
- public static function generateMigrationsFromDb($migrationsPath)
- |
-914 |
- {
- |
-915 |
- $builder = new Doctrine_Migration_Builder($migrationsPath);
- |
-916 |
-
- |
-917 |
- return $builder->generateMigrationsFromDb();
- |
-918 |
- }
- |
-919 |
-
- |
-920 |
- /**
- |
-921 |
- * generateMigrationsFromModels
- |
-922 |
- *
- |
-923 |
- * @param string $migrationsPath
- |
-924 |
- * @param string $modelsPath
- |
-925 |
- * @return void
- |
-926 |
- */
- |
-927 |
- public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null)
- |
-928 |
- {
- |
-929 |
- $builder = new Doctrine_Migration_Builder($migrationsPath);
- |
-930 |
-
- |
-931 |
- return $builder->generateMigrationsFromModels($modelsPath);
- |
-932 |
- }
- |
-933 |
-
- |
-934 |
- /**
- |
-935 |
- * getTable
- |
-936 |
- *
- |
-937 |
- * @param string $tableName
- |
-938 |
- * @return void
- |
-939 |
- */
- |
-940 |
- public static function getTable($tableName)
- |
-941 |
- {
- |
-942 |
- return Doctrine_Manager::table($tableName);
- |
-943 |
- }
- |
-944 |
-
- |
-945 |
- /**
- |
-946 |
- * connection
- |
-947 |
- *
- |
-948 |
- * @param string $adapter
- |
-949 |
- * @param string $name
- |
-950 |
- * @return void
- |
-951 |
- */
- |
-952 |
- public static function connection($adapter, $name = null)
- |
-953 |
- {
- |
-954 |
- return Doctrine_Manager::connection($adapter, $name);
- |
-955 |
- }
- |
-956 |
-
- |
-957 |
- /**
- |
-958 |
- * fileFinder
- |
-959 |
- *
- |
-960 |
- * @param string $type
- |
-961 |
- * @return void
- |
-962 |
- */
- |
-963 |
- public static function fileFinder($type)
- |
-964 |
- {
- |
-965 |
- return Doctrine_FileFinder::type($type);
- |
-966 |
- }
- |
-967 |
-
- |
-968 |
- /**
- |
-969 |
- * compile
- |
-970 |
- * method for making a single file of most used doctrine runtime components
- |
-971 |
- * including the compiled file instead of multiple files (in worst
- |
-972 |
- * cases dozens of files) can improve performance by an order of magnitude
- |
-973 |
- *
- |
-974 |
- * @param string $target
- |
-975 |
- *
- |
-976 |
* @throws Doctrine_Exception
|
-977 |
+
451 |
+ */
+ |
+452 |
+ public function __construct()
+ |
+453 |
+ {
+ |
+454 |
+ throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
+ |
+455 |
+ }
+ |
+456 |
+
+ |
+457 |
+ /**
+ |
+458 |
+ * debug
+ |
+459 |
+ *
+ |
+460 |
+ * @param string $bool
+ |
+461 |
* @return void
|
-978 |
+
462 |
*/
|
-979 |
- public static function compile($target = null, $includedDrivers = array())
+ |
463 |
+ public static function debug($bool = null)
|
-980 |
+
464 |
{
|
-981 |
- return Doctrine_Compiler::compile($target, $includedDrivers);
+ |
465 |
+ if ($bool !== null) {
|
-982 |
- }
+ |
466 |
+ self::$_debug = (bool) $bool;
|
-983 |
-
+ |
467 |
+ }
|
-984 |
- /**
- |
-985 |
- * simple autoload function
- |
-986 |
- * returns true if the class was loaded, otherwise false
- |
-987 |
- *
- |
-988 |
- * @param string $classname
- |
-989 |
- * @return boolean
- |
-990 |
- */
- |
-991 |
- public static function autoload($classname)
- |
-992 |
- {
- |
-993 |
- if (class_exists($classname, false)) {
- |
-994 |
- return false;
- |
-995 |
- }
- |
-996 |
+
468 |
|
-997 |
- if ( ! self::$_path) {
+ |
469 |
+ return self::$_debug;
|
-998 |
+
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__);
|
-999 |
+
482 |
}
|
-1000 |
+
483 |
|
-1001 |
- $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $classname) . '.php';
+ |
484 |
+ return self::$_path;
|
-1002 |
-
- |
-1003 |
- if ( ! file_exists($class)) {
- |
-1004 |
- return false;
- |
-1005 |
- }
- |
-1006 |
-
- |
-1007 |
- require_once($class);
- |
-1008 |
-
- |
-1009 |
- return true;
- |
-1010 |
+
485 |
}
|
-1011 |
+
486 |
|
-1012 |
+
487 |
/**
|
-1013 |
- * dump
+ |
488 |
+ * loadAll
|
-1014 |
+
489 |
+ * loads all runtime classes
+ |
+490 |
*
|
-1015 |
- * dumps a given variable
+ |
491 |
+ * @return void
|
-1016 |
- *
- |
-1017 |
- * @param mixed $var a variable of any type
- |
-1018 |
- * @param boolean $output whether to output the content
- |
-1019 |
- * @return void|string
- |
-1020 |
+
492 |
*/
|
-1021 |
- public static function dump($var, $output = true)
+ |
493 |
+ public static function loadAll()
|
-1022 |
+
494 |
{
|
-1023 |
- $ret = array();
+ |
495 |
+ return self::loadAllRuntimeClasses();
|
-1024 |
- switch (gettype($var)) {
- |
-1025 |
- case 'array':
- |
-1026 |
- $ret[] = 'Array(';
- |
-1027 |
- foreach ($var as $k => $v) {
- |
-1028 |
- $ret[] = $k . ' : ' . self::dump($v, false);
- |
-1029 |
- }
- |
-1030 |
- $ret[] = ")";
- |
-1031 |
- break;
- |
-1032 |
- case 'object':
- |
-1033 |
- $ret[] = 'Object(' . get_class($var) . ')';
- |
-1034 |
- break;
- |
-1035 |
- default:
- |
-1036 |
- $ret[] = var_export($var, true);
- |
-1037 |
- }
- |
-1038 |
- if ($output) {
- |
-1039 |
- print implode("\n", $ret);
- |
-1040 |
- }
- |
-1041 |
- return implode("\n", $ret);
- |
-1042 |
+
496 |
}
|
-1043 |
+
497 |
|
-1044 |
+
498 |
/**
|
-1045 |
- * returns table name from class name
+ |
499 |
+ * importSchema
|
-1046 |
+
500 |
+ * method for importing existing schema to Doctrine_Record classes
+ |
+501 |
*
|
-1047 |
- * @param string $classname
+ |
502 |
+ * @param string $directory Directory to write your models to
|
-1048 |
- * @return string
+ |
503 |
+ * @param array $databases Array of databases to generate models for
|
-1049 |
- */
- |
-1050 |
- public static function tableize($classname)
- |
-1051 |
- {
- |
-1052 |
- return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
- |
-1053 |
- }
- |
-1054 |
-
- |
-1055 |
- /**
- |
-1056 |
- * returns class name from table name
- |
-1057 |
- *
- |
-1058 |
- * @param string $tablename
- |
-1059 |
- * @return string
- |
-1060 |
- */
- |
-1061 |
- public static function classify($tablename)
- |
-1062 |
- {
- |
-1063 |
- return preg_replace_callback('~(_?)(_)([\w])~', array("Doctrine", "classifyCallback"), ucfirst($tablename));
- |
-1064 |
- }
- |
-1065 |
-
- |
-1066 |
- /**
- |
-1067 |
- * Callback function to classify a classname propperly.
- |
-1068 |
- *
- |
-1069 |
- * @param array $matches An array of matches from a pcre_replace call
- |
-1070 |
- * @return string A string with matches 1 and mathces 3 in upper case.
- |
-1071 |
- */
- |
-1072 |
- public static function classifyCallback($matches)
- |
-1073 |
- {
- |
-1074 |
- return $matches[1] . strtoupper($matches[3]);
- |
-1075 |
- }
- |
-1076 |
-
- |
-1077 |
- /**
- |
-1078 |
- * checks for valid class name (uses camel case and underscores)
- |
-1079 |
- *
- |
-1080 |
- * @param string $classname
- |
-1081 |
+
504 |
* @return boolean
|
-1082 |
+
505 |
*/
|
-1083 |
- public static function isValidClassname($classname)
+ |
506 |
+ public static function importSchema($directory, array $databases = array())
|
-1084 |
+
507 |
{
|
+508 |
+ return self::generateModelsFromDb($directory, $databases);
+ |
+509 |
+ }
+ |
+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 |
+ /**
+ |
+524 |
+ * exportSql
+ |
+525 |
+ * method for exporting Doctrine_Record classes to a schema
+ |
+526 |
+ *
+ |
+527 |
+ * @param string $directory
+ |
+528 |
+ */
+ |
+529 |
+ public static function exportSql($directory = 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 |
+ $classes = get_declared_classes();
+ |
+594 |
+ }
+ |
+595 |
+
+ |
+596 |
+ $parent = new ReflectionClass('Doctrine_Record');
+ |
+597 |
+
+ |
+598 |
+ $loadedModels = array();
+ |
+599 |
+
+ |
+600 |
+ foreach ((array) $classes as $name) {
+ |
+601 |
+ $class = new ReflectionClass($name);
+ |
+602 |
+
+ |
+603 |
+ // Skip the following classes
+ |
+604 |
+ // - abstract classes
+ |
+605 |
+ // - not a subclass of Doctrine_Record
+ |
+606 |
+ // - don't have a setTableDefinition method
+ |
+607 |
+ if ($class->isAbstract() ||
+ |
+608 |
+ !$class->isSubClassOf($parent) ||
+ |
+609 |
+ !$class->hasMethod('setTableDefinition')) {
+ |
+610 |
+ continue;
+ |
+611 |
+ }
+ |
+612 |
+
+ |
+613 |
+ $loadedModels[] = $name;
+ |
+614 |
+ }
+ |
+615 |
+
+ |
+616 |
+ return $loadedModels;
+ |
+617 |
+ }
+ |
+618 |
+
+ |
+619 |
+ /**
+ |
+620 |
+ * getConnectionByTableName
+ |
+621 |
+ *
+ |
+622 |
+ * Get the connection object for a table by the actual table name
+ |
+623 |
+ *
+ |
+624 |
+ * @param string $tableName
+ |
+625 |
+ * @return object Doctrine_Connection
+ |
+626 |
+ */
+ |
+627 |
+ public static function getConnectionByTableName($tableName)
+ |
+628 |
+ {
+ |
+629 |
+ $loadedModels = self::getLoadedModels();
+ |
+630 |
+
+ |
+631 |
+ foreach ($loadedModels as $name) {
+ |
+632 |
+ $model = new $name();
+ |
+633 |
+ $table = $model->getTable();
+ |
+634 |
+
+ |
+635 |
+ if ($table->getTableName() == $tableName) {
+ |
+636 |
+ return $table->getConnection();
+ |
+637 |
+ }
+ |
+638 |
+ }
+ |
+639 |
+
+ |
+640 |
+ return Doctrine_Manager::connection();
+ |
+641 |
+ }
+ |
+642 |
+
+ |
+643 |
+ /**
+ |
+644 |
+ * generateModelsFromDb
+ |
+645 |
+ *
+ |
+646 |
+ * method for importing existing schema to Doctrine_Record classes
+ |
+647 |
+ *
+ |
+648 |
+ * @param string $directory Directory to write your models to
+ |
+649 |
+ * @param array $databases Array of databases to generate models for
+ |
+650 |
+ * @return boolean
+ |
+651 |
+ * @throws Exception
+ |
+652 |
+ */
+ |
+653 |
+ public static function generateModelsFromDb($directory, array $databases = array())
+ |
+654 |
+ {
+ |
+655 |
+ return Doctrine_Manager::connection()->import->importSchema($directory, $databases);
+ |
+656 |
+ }
+ |
+657 |
+
+ |
+658 |
+ /**
+ |
+659 |
+ * generateYamlFromDb
+ |
+660 |
+ *
+ |
+661 |
+ * Generates models from database to temporary location then uses those models to generate a yaml schema file.
+ |
+662 |
+ * This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
+ |
+663 |
+ *
+ |
+664 |
+ * @param string $yamlPath Path to write oyur yaml schema file to
+ |
+665 |
+ * @return void
+ |
+666 |
+ */
+ |
+667 |
+ public static function generateYamlFromDb($yamlPath)
+ |
+668 |
+ {
+ |
+669 |
+ $directory = '/tmp/tmp_doctrine_models';
+ |
+670 |
+
+ |
+671 |
+ Doctrine::generateModelsFromDb($directory);
+ |
+672 |
+
+ |
+673 |
+ $export = new Doctrine_Export_Schema();
+ |
+674 |
+
+ |
+675 |
+ $result = $export->exportSchema($yamlPath, 'yml', $directory);
+ |
+676 |
+
+ |
+677 |
+ exec('rm -rf ' . $directory);
+ |
+678 |
+
+ |
+679 |
+ return $result;
+ |
+680 |
+ }
+ |
+681 |
+
+ |
+682 |
+ /**
+ |
+683 |
+ * generateModelsFromYaml
+ |
+684 |
+ *
+ |
+685 |
+ * Generate a yaml schema file from an existing directory of models
+ |
+686 |
+ *
+ |
+687 |
+ * @param string $yamlPath Path to your yaml schema files
+ |
+688 |
+ * @param string $directory Directory to generate your models in
+ |
+689 |
+ * @param array $options Array of options to pass to the schema importer
+ |
+690 |
+ * @return void
+ |
+691 |
+ */
+ |
+692 |
+ public static function generateModelsFromYaml($yamlPath, $directory, $options = array())
+ |
+693 |
+ {
+ |
+694 |
+ $import = new Doctrine_Import_Schema();
+ |
+695 |
+ $import->setOption('generateBaseClasses', true);
+ |
+696 |
+
+ |
+697 |
+ return $import->importSchema($yamlPath, 'yml', $directory);
+ |
+698 |
+ }
+ |
+699 |
+
+ |
+700 |
+ /**
+ |
+701 |
+ * createTablesFromModels
+ |
+702 |
+ *
+ |
+703 |
+ * Creates database tables for the models in the specified directory
+ |
+704 |
+ *
+ |
+705 |
+ * @param string $directory Directory containing your models
+ |
+706 |
+ * @return void
+ |
+707 |
+ */
+ |
+708 |
+ public static function createTablesFromModels($directory = null)
+ |
+709 |
+ {
+ |
+710 |
+ return Doctrine_Manager::connection()->export->exportSchema($directory);
+ |
+711 |
+ }
+ |
+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 |
+
+ |
+728 |
+ return $build;
+ |
+729 |
+ }
+ |
+730 |
+
+ |
+731 |
+ /**
+ |
+732 |
+ * generateYamlFromModels
+ |
+733 |
+ *
+ |
+734 |
+ * Generate yaml schema file for the models in the specified directory
+ |
+735 |
+ *
+ |
+736 |
+ * @param string $yamlPath Path to your yaml schema files
+ |
+737 |
+ * @param string $directory Directory to generate your models in
+ |
+738 |
+ * @return void
+ |
+739 |
+ */
+ |
+740 |
+ public static function generateYamlFromModels($yamlPath, $directory)
+ |
+741 |
+ {
+ |
+742 |
+ $export = new Doctrine_Export_Schema();
+ |
+743 |
+
+ |
+744 |
+ return $export->exportSchema($yamlPath, 'yml', $directory);
+ |
+745 |
+ }
+ |
+746 |
+
+ |
+747 |
+ /**
+ |
+748 |
+ * createDatabases
+ |
+749 |
+ *
+ |
+750 |
+ * Creates databases for connections
+ |
+751 |
+ *
+ |
+752 |
+ * @param string $specifiedConnections Array of connections you wish to create the database for
+ |
+753 |
+ * @return void
+ |
+754 |
+ */
+ |
+755 |
+ public static function createDatabases($specifiedConnections = array())
+ |
+756 |
+ {
+ |
+757 |
+ if ( ! is_array($specifiedConnections)) {
+ |
+758 |
+ $specifiedConnections = (array) $specifiedConnections;
+ |
+759 |
+ }
+ |
+760 |
+
+ |
+761 |
+ $manager = Doctrine_Manager::getInstance();
+ |
+762 |
+ $connections = $manager->getConnections();
+ |
+763 |
+
+ |
+764 |
+ foreach ($connections as $name => $connection) {
+ |
+765 |
+ if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) {
+ |
+766 |
+ continue;
+ |
+767 |
+ }
+ |
+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
+ |
+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 |
+ } catch (Exception $e) {
+ |
+789 |
+
+ |
+790 |
+ }
+ |
+791 |
+ }
+ |
+792 |
+ }
+ |
+793 |
+
+ |
+794 |
+ /**
+ |
+795 |
+ * dropDatabases
+ |
+796 |
+ *
+ |
+797 |
+ * Drops databases for connections
+ |
+798 |
+ *
+ |
+799 |
+ * @param string $specifiedConnections Array of connections you wish to drop the database for
+ |
+800 |
+ * @return void
+ |
+801 |
+ */
+ |
+802 |
+ public static function dropDatabases($specifiedConnections = array())
+ |
+803 |
+ {
+ |
+804 |
+ if ( ! is_array($specifiedConnections)) {
+ |
+805 |
+ $specifiedConnections = (array) $specifiedConnections;
+ |
+806 |
+ }
+ |
+807 |
+
+ |
+808 |
+ $manager = Doctrine_Manager::getInstance();
+ |
+809 |
+
+ |
+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 |
+ }
+ |
+861 |
+
+ |
+862 |
+ /**
+ |
+863 |
+ * loadDummyData
+ |
+864 |
+ *
+ |
+865 |
+ * Populdate your models with dummy data
+ |
+866 |
+ *
+ |
+867 |
+ * @param string $append Whether or not to append the data
+ |
+868 |
+ * @param string $num Number of records to populate
+ |
+869 |
+ * @return void
+ |
+870 |
+ */
+ |
+871 |
+ public static function loadDummyData($append, $num = 5)
+ |
+872 |
+ {
+ |
+873 |
+ $data = new Doctrine_Data();
+ |
+874 |
+
+ |
+875 |
+ if ( ! $append) {
+ |
+876 |
+ $data->purge();
+ |
+877 |
+ }
+ |
+878 |
+
+ |
+879 |
+ return $data->importDummyData($num);
+ |
+880 |
+ }
+ |
+881 |
+
+ |
+882 |
+ /**
+ |
+883 |
+ * migrate
+ |
+884 |
+ *
+ |
+885 |
+ * Migrate database to specified $to version. Migrates from current to latest if you do not specify.
+ |
+886 |
+ *
+ |
+887 |
+ * @param string $migrationsPath Path to migrations directory which contains your migration classes
+ |
+888 |
+ * @param string $to Version you wish to migrate to.
+ |
+889 |
+ * @return bool true
+ |
+890 |
+ * @throws new Doctrine_Migration_Exception
+ |
+891 |
+ */
+ |
+892 |
+ public static function migrate($migrationsPath, $to = null)
+ |
+893 |
+ {
+ |
+894 |
+ $migration = new Doctrine_Migration($migrationsPath);
+ |
+895 |
+
+ |
+896 |
+ return $migration->migrate($to);
+ |
+897 |
+ }
+ |
+898 |
+
+ |
+899 |
+ /**
+ |
+900 |
+ * generateMigrationClass
+ |
+901 |
+ *
+ |
+902 |
+ * Generate new migration class skeleton
+ |
+903 |
+ *
+ |
+904 |
+ * @param string $className Name of the Migration class to generate
+ |
+905 |
+ * @param string $migrationsPath Path to directory which contains your migration classes
+ |
+906 |
+ */
+ |
+907 |
+ public static function generateMigrationClass($className, $migrationsPath)
+ |
+908 |
+ {
+ |
+909 |
+ $builder = new Doctrine_Migration_Builder($migrationsPath);
+ |
+910 |
+
+ |
+911 |
+ return $builder->generateMigrationClass($className);
+ |
+912 |
+ }
+ |
+913 |
+
+ |
+914 |
+ /**
+ |
+915 |
+ * generateMigrationsFromDb
+ |
+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 |
+ * returns true if the class was loaded, otherwise false
+ |
+998 |
+ *
+ |
+999 |
+ * @param string $classname
+ |
+1000 |
+ * @return boolean
+ |
+1001 |
+ */
+ |
+1002 |
+ public static function autoload($className)
+ |
+1003 |
+ {
+ |
+1004 |
+ if (class_exists($className, false)) {
+ |
+1005 |
+ return false;
+ |
+1006 |
+ }
+ |
+1007 |
+
+ |
+1008 |
+ if ( ! self::$_path) {
+ |
+1009 |
+ self::$_path = dirname(__FILE__);
+ |
+1010 |
+ }
+ |
+1011 |
+
+ |
+1012 |
+ $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
+ |
+1013 |
+
+ |
+1014 |
+ if (file_exists($class)) {
+ |
+1015 |
+ require_once($class);
+ |
+1016 |
+
+ |
+1017 |
+ return true;
+ |
+1018 |
+ }
+ |
+1019 |
+
+ |
+1020 |
+ $loadedModels = self::$_loadedModels;
+ |
+1021 |
+
+ |
+1022 |
+ if (isset($loadedModels[$className]) && file_exists($loadedModels[$className])) {
+ |
+1023 |
+ require_once($loadedModels[$className]);
+ |
+1024 |
+
+ |
+1025 |
+ return true;
+ |
+1026 |
+ }
+ |
+1027 |
+
+ |
+1028 |
+ return false;
+ |
+1029 |
+ }
+ |
+1030 |
+
+ |
+1031 |
+ /**
+ |
+1032 |
+ * dump
+ |
+1033 |
+ *
+ |
+1034 |
+ * dumps a given variable
+ |
+1035 |
+ *
+ |
+1036 |
+ * @param mixed $var a variable of any type
+ |
+1037 |
+ * @param boolean $output whether to output the content
+ |
+1038 |
+ * @return void|string
+ |
+1039 |
+ */
+ |
+1040 |
+ public static function dump($var, $output = true)
+ |
+1041 |
+ {
+ |
+1042 |
+ $ret = array();
+ |
+1043 |
+ switch (gettype($var)) {
+ |
+1044 |
+ case 'array':
+ |
+1045 |
+ $ret[] = 'Array(';
+ |
+1046 |
+ foreach ($var as $k => $v) {
+ |
+1047 |
+ $ret[] = $k . ' : ' . self::dump($v, false);
+ |
+1048 |
+ }
+ |
+1049 |
+ $ret[] = ")";
+ |
+1050 |
+ break;
+ |
+1051 |
+ case 'object':
+ |
+1052 |
+ $ret[] = 'Object(' . get_class($var) . ')';
+ |
+1053 |
+ break;
+ |
+1054 |
+ default:
+ |
+1055 |
+ $ret[] = var_export($var, true);
+ |
+1056 |
+ }
+ |
+1057 |
+ if ($output) {
+ |
+1058 |
+ print implode("\n", $ret);
+ |
+1059 |
+ }
+ |
+1060 |
+ return implode("\n", $ret);
+ |
+1061 |
+ }
+ |
+1062 |
+
+ |
+1063 |
+ /**
+ |
+1064 |
+ * tableize
+ |
+1065 |
+ *
+ |
+1066 |
+ * returns table name from class name
+ |
+1067 |
+ *
+ |
+1068 |
+ * @param string $classname
+ |
+1069 |
+ * @return string
+ |
+1070 |
+ */
+ |
+1071 |
+ public static function tableize($classname)
+ |
+1072 |
+ {
+ |
+1073 |
+ return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
+ |
+1074 |
+ }
+ |
+1075 |
+
+ |
+1076 |
+ /**
+ |
+1077 |
+ * classify
+ |
+1078 |
+ *
+ |
+1079 |
+ * returns class name from table name
+ |
+1080 |
+ *
+ |
+1081 |
+ * @param string $tablename
+ |
+1082 |
+ * @return string
+ |
+1083 |
+ */
+ |
+1084 |
+ public static function classify($tablename)
+ |
1085 |
- if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) {
+ | {
|
1086 |
- return false;
+ | return preg_replace_callback('~(_?)(_)([\w])~', array("Doctrine", "classifyCallback"), ucfirst($tablename));
|
1087 |
- }
+ | }
|
1088 |
|
1089 |
- return true;
+ | /**
|
1090 |
- }
+ | * classifyCallback
|
1091 |
-}
+ | *
|
+1092 |
+ * Callback function to classify a classname propperly.
+ |
+1093 |
+ *
+ |
+1094 |
+ * @param array $matches An array of matches from a pcre_replace call
+ |
+1095 |
+ * @return string A string with matches 1 and mathces 3 in upper case.
+ |
+1096 |
+ */
+ |
+1097 |
+ public static function classifyCallback($matches)
+ |
+1098 |
+ {
+ |
+1099 |
+ return $matches[1] . strtoupper($matches[3]);
+ |
+1100 |
+ }
+ |
+1101 |
+
+ |
+1102 |
+ /**
+ |
+1103 |
+ * isValidClassName
+ |
+1104 |
+ *
+ |
+1105 |
+ * checks for valid class name (uses camel case and underscores)
+ |
+1106 |
+ *
+ |
+1107 |
+ * @param string $classname
+ |
+1108 |
+ * @return boolean
+ |
+1109 |
+ */
+ |
+1110 |
+ public static function isValidClassname($classname)
+ |
+1111 |
+ {
+ |
+1112 |
+ if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) {
+ |
+1113 |
+ return false;
+ |
+1114 |
+ }
+ |
+1115 |
+
+ |
+1116 |
+ return true;
+ |
+1117 |
+ }
+ |
+1118 |
+
+ |
+1119 |
+ /**
+ |
+1120 |
+ * makeDirectories
+ |
+1121 |
+ *
+ |
+1122 |
+ * Makes the directories for a path recursively
+ |
+1123 |
+ *
+ |
+1124 |
+ * @param string $path
+ |
+1125 |
+ * @return void
+ |
+1126 |
+ */
+ |
+1127 |
+ public static function makeDirectories($path, $mode = 0777)
+ |
+1128 |
+ {
+ |
+1129 |
+ if (is_dir($path) || is_file($path))
+ |
+1130 |
+ {
+ |
+1131 |
+ return true;
+ |
+1132 |
+ }
+ |
+1133 |
+
+ |
+1134 |
+ return mkdir($path, $mode, true);
+ |
+1135 |
+ }
+ |
+1136 |
+} |