You are here

protected function DbDumpCommand::fieldSizeMap in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Command/DbDumpCommand.php \Drupal\Core\Command\DbDumpCommand::fieldSizeMap()

Given a database field type, return a Drupal size.

Parameters

\Drupal\Core\Database\Connection $connection: The database connection to use.

string $type: The MySQL field type.

Return value

string|null The Drupal schema field size.

1 call to DbDumpCommand::fieldSizeMap()
DbDumpCommand::getTableSchema in core/lib/Drupal/Core/Command/DbDumpCommand.php
Returns a schema array for a given table.

File

core/lib/Drupal/Core/Command/DbDumpCommand.php, line 343

Class

DbDumpCommand
Provides a command to dump the current database to a script.

Namespace

Drupal\Core\Command

Code

protected function fieldSizeMap(Connection $connection, $type) {

  // Convert everything to lowercase.
  $map = array_map('strtolower', $connection
    ->schema()
    ->getFieldTypeMap());
  $map = array_flip($map);

  // Do nothing if the field type is not defined.
  if (!isset($map[$type])) {
    return NULL;
  }
  $schema_type = explode(':', $map[$type])[0];

  // Only specify size on these types.
  if (in_array($schema_type, [
    'blob',
    'float',
    'int',
    'text',
  ])) {

    // The MySql map contains type:size. Remove the type part.
    return explode(':', $map[$type])[1];
  }
}