You are here

function schema_phpprint_table in Schema 5

Same name and namespace in other branches
  1. 8 schema.module \schema_phpprint_table()
  2. 6 schema.module \schema_phpprint_table()
  3. 7 schema.module \schema_phpprint_table()
2 calls to schema_phpprint_table()
schema_inspect in ./schema.module
schema_phpprint in ./schema.module

File

./schema.module, line 22

Code

function schema_phpprint_table($name, $table) {
  $cols = array();
  foreach ($table['fields'] as $colname => $col) {
    $cols[] = "'{$colname}' => " . schema_phpprint_column($col);
  }
  $unique = $index = array();
  if (isset($table['unique keys'])) {
    foreach ($table['unique keys'] as $keyname => $key) {
      $unique[] = "'{$keyname}' => " . schema_phpprint_key($key);
    }
  }
  if (isset($table['indexes'])) {
    foreach ($table['indexes'] as $keyname => $key) {
      $index[] = "'{$keyname}' => " . schema_phpprint_key($key);
    }
  }
  $out = '';
  $out .= "\$schema['" . $name . "'] = array(\n    'fields' => array(\n         ";
  $out .= implode(",\n         ", $cols);
  $out .= "),\n";
  if (isset($table['primary key'])) {
    $out .= "    'primary key' => array('" . implode("', '", $table['primary key']) . "'),\n";
  }
  if (count($unique) > 0) {
    $out .= "    'unique keys' => array(\n         ";
    $out .= implode(",\n         ", $unique);
    $out .= "),\n";
  }
  if (count($index) > 0) {
    $out .= "    'indexes' => array(\n         ";
    $out .= implode(",\n         ", $index);
    $out .= "),\n";
  }
  $out .= ");\n";
  return $out;
}