1.20.x config.inc public static Config::validateName($name)

Validates the configuration object name.

Parameters

string $name: The name of the configuration object.

Throws

ConfigNameException

See also

Config::MAX_NAME_LENGTH

File

includes/config.inc, line 570
This is the API for configuration storage.

Class

Config
Defines the default configuration object.

Code

public static function validateName($name) {
  // The name must be namespaced by owner.
  if (strpos($name, '.') === FALSE) {
    throw new ConfigNameException(format_string('Missing namespace in Config object name @name.', array(
      '@name' => $name,
    )));
  }
  // The name must be shorter than Config::MAX_NAME_LENGTH characters.
  if (strlen($name) > self::MAX_NAME_LENGTH) {
    throw new ConfigNameException(format_string('Config object name @name exceeds maximum allowed length of @length characters.', array(
      '@name' => $name,
      '@length' => self::MAX_NAME_LENGTH,
    )));
  }

  // The name must not contain any of the following characters:
  // : ? * < > " ' / \
  if (preg_match('/[:?*<>"\'\/\\\\]/', $name)) {
    throw new ConfigNameException(format_string('Invalid character in Config object name @name.', array(
      '@name' => $name,
    )));
  }
}