예제 #1
0
 /**
  * Add a table
  * 
  * @param string $tableName
  * @param array $columns
  */
 public static function addTable($tableName, $columns = [])
 {
     $table = new SchemaTable($tableName, $columns);
     self::$tables[$table->getName()] = $table;
 }
예제 #2
0
 /**
  * Scans the schema for the specified table name (or prefix + table name),
  * starting with the given database and only scanning other databases if
  * the table is not found there.
  *
  * @return mixed - SchemaTable if found, null if not
  * @author Anthony Bush
  **/
 protected function findTable($tableNameMatch, SchemaTable $sourceTable)
 {
     $firstDatabase = $sourceTable->getDatabase();
     $table = $this->findTableInDatabase($tableNameMatch, $firstDatabase);
     if (is_null($table)) {
         // Try again for every other database
         $firstDatabaseName = $firstDatabase->getDatabaseName();
         foreach ($this->schema->getDatabases() as $dbName => $database) {
             if ($dbName == $firstDatabaseName || !$this->config->shouldScanForJoin($sourceTable, $database)) {
                 continue;
             }
             $table = $this->findTableInDatabase($tableNameMatch, $database);
             if (!is_null($table)) {
                 break;
             }
         }
     }
     return $table;
 }
예제 #3
0
 public function shouldGenerateForTable(SchemaTable $table)
 {
     if (!$table->hasPrimaryKey()) {
         return false;
     }
     return true;
 }
 /**
  * Returns whether or not a the $sourceTable cares about the $refDatabase when looking
  * for joins.
  * 
  * @param SchemaTable $sourceTable - the source table that is trying to link up related joins
  * @param SchemaDatabase $refDatabase - the dest database to scan if shouldScanForJoin() returns true
  * @return boolean
  * @author Anthony Bush
  * @since 2007-11-06
  **/
 public function shouldScanForJoin(SchemaTable $sourceTable, SchemaDatabase $refDatabase)
 {
     $dbName = $sourceTable->getDatabase()->getDatabaseName();
     $tableName = $sourceTable->getTableName();
     $option = $this->getConfigValue('acceptable_join_databases', $dbName, $tableName);
     if (is_array($option)) {
         // yes, but only for databases in the array.
         $refDbName = $refDatabase->getDatabaseName();
         if (in_array($refDbName, $option)) {
             return true;
         }
     } else {
         if ($option == 'all') {
             return true;
         }
     }
     return false;
 }