You are here

function schema_phpprint_column in Schema 6

Same name and namespace in other branches
  1. 8 schema.module \schema_phpprint_column()
  2. 5 schema.module \schema_phpprint_column()
  3. 7 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 75
The Schema module provides functionality built on the Schema API.

Code

function schema_phpprint_column($col, $multiline = FALSE) {
  $attrs = array();
  if (isset($col['description']) && trim($col['description'])) {
    $description = $col['description'];
  }
  else {
    $description = t('TODO: please describe this field!');
  }
  unset($col['description']);
  $attrs[] = "'description' => '{$description}'";
  if (isset($col['size']) && ($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]}'";
      }
      else {
        if (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) . ")";
}