コード例 #1
0
ファイル: Schema.php プロジェクト: EchoWine/database
 /**
  * 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;
 }
コード例 #4
0
 /**
  * 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;
 }