break; case 'pgsql': $db = new PostgreSQLConnection($dbServer, $dbUsername, $dbPassword, $dbDatabase); break; default: fprintf(STDERR, "Unsupported dialect: %s\n", $dialect); exit(1); } $loader = new ConnectionDDLLoader(); $ddl = $loader->loadDDL($db, false, $allowedTableNames); $db->close(); unset($db); } else { // Load new DDL from DDL file(s). $aggregateDDL = new DDL(); $res = YAMLDDLParser::loadAllDDLFiles($ddlDir, $aggregateDDL, $allowedTableNames); if ($res != 0) { exit($res); } $ddl = $aggregateDDL; unset($aggregateDDL); } ///print_r($ddl); $generator = new DAOClassGenerator(); function file_put_contents_if_changed($filename, $contents) { if (!file_exists($filename) || file_get_contents($filename) != $contents) { return file_put_contents($filename, $contents); } return strlen($contents); }
if (!empty($mapTargetTableNames)) { if (!empty($allowedTableNames)) { $allowedTableNames = array_intersect($allowedTableNames, $mapTargetTableNames); } else { $allowedTableNames = $mapTargetTableNames; } } // Load the DDL from the database, filtering out all non-allowed tables. $db = MyConnectionFactory::getConnection($connectionName); $dialect = $db->getDialect(); $loader = new ConnectionDDLLoader(); $databaseDDL = $loader->loadDDL($db, false, $databaseAllowedTableNames); $db->close(); // Load the current DDL from the DDL files. $currentDDL = new DDL(array()); if (($res = YAMLDDLParser::loadAllDDLFiles($ddlDir, $currentDDL, $allowedTableNames, $dbmap)) != 0) { exit($res); } // If we have map-target tables, remove all foreign keys from the current DDL which // reference tables which are not map targets (because those tables should not exist // in this database). if (!empty($mapTargetTableNames)) { $anyDeleted = false; for ($i = 0, $n = count($currentDDL->topLevelEntities); $i < $n; $i++) { if ($currentDDL->topLevelEntities[$i] instanceof DDLForeignKey && !in_array($currentDDL->topLevelEntities[$i]->foreignTableName, $mapTargetTableNames)) { unset($currentDDL->topLevelEntities[$i]); $anyDeleted = true; } } if ($anyDeleted) { $currentDDL->topLevelEntities = array_slice($currentDDL->topLevelEntities, 0);
// parseini_multi.php // Copyright (c) 2011-2016 Ronald B. Cemer // All rights reserved. // This software is released under the BSD license. // Please see the accompanying LICENSE.txt for details. include dirname(dirname(__FILE__)) . '/phpdaogen/AbstractINIMultiDatabaseConnectionFactory.class.php'; include dirname(dirname(__FILE__)) . '/phpdaogen/DDL.class.php'; if ($argc < 3 || $argc > 4) { fprintf(STDERR, "Please specify a single INI filename, the path to the ddl directory where the YAML schema files exist, and an optional secondary database name.\n"); exit(1); } $connectionParamsByName = AbstractINIMultiDatabaseConnectionFactory::loadDatabaseIniFile($argv[1]); $ddldir = $argv[2]; $connectionName = $argc >= 4 ? trim($argv[3]) : ''; $aggregateDDL = new DDL(); if (($res = YAMLDDLParser::loadAllDDLFiles(realpath($ddldir), $aggregateDDL)) != 0) { return $res; } $errorMsgs = AbstractINIMultiDatabaseConnectionFactory::validateDatabaseIniConfiguration($connectionParamsByName, $aggregateDDL); if (!empty($errorMsgs)) { foreach ($errorMsgs as $errorMsg) { fputs(STDERR, $errorMsg); fputs(STDERR, "\n"); } exit(20); } $params = AbstractINIMultiDatabaseConnectionFactory::getConnectionParams($connectionName, null, null, $connectionParamsByName); foreach ($params as $key => $val) { echo "ini_{$key}=" . escapeshellarg($val) . "\n"; } echo 'ini_allConnectionNames=' . implode(',', array_keys($connectionParamsByName)) . "\n";