You are here

function schema_phpprint_column in Schema 7

Same name and namespace in other branches
  1. 8 schema.module \schema_phpprint_column()
  2. 5 schema.module \schema_phpprint_column()
  3. 6 schema.module \schema_phpprint_column()
2 calls to schema_phpprint_column()
schema_compare_table in ./schema.module
Compares a reference specification (such as one returned by a module's hook_schema) to an inspected specification from the database.
schema_phpprint_table in ./schema.module

File

./schema.module, line 252
The Schema module provides functionality built on the Schema API.

Code

function schema_phpprint_column($col, $multiline = FALSE) {
  $attrs = array();
  if (isset($col['description']) && $col['description']) {
    $description = $col['description'];
  }
  else {
    $description = t('TODO: please describe this field!');
  }
  unset($col['description']);
  $attrs[] = "'description' => '{$description}'";
  if ($col['type'] == 'varchar' || $col['size'] == 'normal') {
    unset($col['size']);
  }
  foreach (array(
    'type',
    'unsigned',
    'size',
    'length',
    'not null',
    'default',
  ) as $attr) {
    if (isset($col[$attr])) {
      if (is_string($col[$attr])) {
        $attrs[] = "'{$attr}' => '{$col[$attr]}'";
      }
      elseif (is_bool($col[$attr])) {
        $attrs[] = "'{$attr}' => " . ($col[$attr] ? 'TRUE' : 'FALSE');
      }
      else {
        $attrs[] = "'{$attr}' => {$col[$attr]}";
      }
      unset($col[$attr]);
    }
  }
  foreach (array_keys($col) as $attr) {
    if (is_string($col[$attr])) {
      $attrs[] = "'{$attr}' => '{$col[$attr]}'";
    }
    else {
      $attrs[] = "'{$attr}' => {$col[$attr]}";
    }
  }
  if ($multiline) {
    return "array(\n      " . implode(",\n      ", $attrs) . ",\n    )";
  }
  return "array(" . implode(', ', $attrs) . ")";
}