Validates a database name
@return boolean
342538
protected function validateDbNameInstall()
    {
        $field = 'database.name';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if (empty($value)) {
            $this->setErrorRequired($field, $this->translation->text('Database name'));
            return false;
        }

        return true;
    }
435419
public function validate(): void
    {
        $required = [
            'app_root',
            'app_name',
            'default_filesystem',
            'environment',
            'default_branch',
            'default_database_adapter',
            'default_database_importexport_adapter',
            'default_dir_mode',
            'default_file_mode',
            'platform',
            'relative_document_root',
            'repo_url',
        ];
        $missingRequired = [];
        foreach ($required as $name) {
            if (empty($this->config[$name])) {
                $missingRequired[] = $name;
            }
        }
        if ($missingRequired) {
            throw new Exception\RuntimeException(
                'Missing required values for top level configuration key(s): "' . implode('", "', $missingRequired)
                . '"'
            );
        }

        if (!in_array(
            $this->config['file_layout'],
            [
                FileLayoutInterface::STRATEGY_BLUE_GREEN,
                FileLayoutInterface::STRATEGY_DEFAULT
            ]
        )) {
            throw new Exception\DomainException("Invalid file layout \"{$this->config['file_layout']}\".");
        }

        $this->buildConfig->validate();
        $this->deployConfig->validate();
        $this->snapshotConfig->validate();
        $this->skeletonConfig->validate();
    }
840403
def IsNameBased(link):
    
    if not link:
        return False

    # trimming the leading "/"
    if link.startswith('/') and len(link) > 1:
        link = link[1:]

    # Splitting the link(separated by "/") into parts 
    parts = link.split('/')

    # First part should be "dbs" 
    if len(parts) == 0 or not parts[0] or not parts[0].lower() == 'dbs':
        return False

    # The second part is the database id(ResourceID or Name) and cannot be empty
    if len(parts) < 2 or not parts[1]:
    	return False

    # Either ResourceID or database name
    databaseID = parts[1]
    	
    # Length of databaseID(in case of ResourceID) is always 8
    if len(databaseID) != 8:
        return True

    return not IsValidBase64String(str(databaseID))
329764
private function validateTableName($name)
    {
        if (! is_string($name)) {
            throw InvalidArgumentException::invalidType('key', 'string', $name);
        }

        if (! preg_match('/^[a-z0-9_.-]{3,255}$/i', $name)) {
            throw InvalidArgumentException::invalidTableName($name);
        }
    }
97049
protected function isEntityNameValid($name)
    {
        if (is_string($name) === false) {
            return false;
        }

        $match = preg_match(self::PATTERN_VALIDATE_NAME, $name);
        if ($name === '' || $match === false || $match <= 0 || ReservedKeywords::isReservedKeyword($name) !== false) {
            return false;
        } else {
            return true;
        }
    }
1259205
public function validate()
    {
        // Names must not be empty, but can be 0
        $name = $this->getName();
        if (empty($name) && !is_numeric($name)) {
            return 'The cookie name must not be empty';
        }

        // Check if any of the invalid characters are present in the cookie name
        if (strpbrk($name, self::getInvalidCharacters()) !== false) {
            return 'The cookie name must not contain invalid characters: ' . $name;
        }

        // Value must not be empty, but can be 0
        $value = $this->getValue();
        if (empty($value) && !is_numeric($value)) {
            return 'The cookie value must not be empty';
        }

        // Domains must not be empty, but can be 0
        // A "0" is not a valid internet domain, but may be used as server name in a private network
        $domain = $this->getDomain();
        if (empty($domain) && !is_numeric($domain)) {
            return 'The cookie domain must not be empty';
        }

        return true;
    }
184296
protected function validateModel()
    {
        if (!is_string($this->model)) {
            $baseName = $this->getControllerBaseName();
            $this->findModelClass($baseName);
        }
    }
759558
private function databases()
    {
        if (Configuration::read('database.config.enable') === true) {
            $databaseConfigPath = $this->configDir . DS . Configuration::read('database.config.file');
            if (file_exists($databaseConfigPath)) {
                require $databaseConfigPath;
                return true;
            }
        }
        return false;
    }
263313
public function validate()
    {
        // Names must not be empty, but can be 0
        $name = $this->getName();
        if (empty($name) && !is_numeric($name)) {
            return 'The cookie name must not be empty';
        }

        // Check if any of the invalid characters are present in the cookie name
        if (preg_match(
            '/[\x00-\x20\x22\x28-\x29\x2c\x2f\x3a-\x40\x5c\x7b\x7d\x7f]/',
            $name
        )) {
            return 'Cookie name must not contain invalid characters: ASCII '
                . 'Control characters (0-31;127), space, tab and the '
                . 'following characters: ()<>@,;:\"/?={}';
        }

        // Value must not be empty, but can be 0
        $value = $this->getValue();
        if (empty($value) && !is_numeric($value)) {
            return 'The cookie value must not be empty';
        }

        // Domains must not be empty, but can be 0
        // A "0" is not a valid internet domain, but may be used as server name
        // in a private network.
        $domain = $this->getDomain();
        if (empty($domain) && !is_numeric($domain)) {
            return 'The cookie domain must not be empty';
        }

        return true;
    }
908964
public function validateName($name)
    {
        if (empty($name)) {
            $this->addError('name', 'Name cannot be empty');
            return false;
        }

        if (!is_string($name)) {
            $this->addError('name', 'Name must be a string');
            return false;
        }

        if (mb_strlen($name, 'UTF-8') > 255) {
            $this->addError('name', 'Name length has to be less or equal to 255');
            return false;
        }


        return true;
    }
770165
protected function validateInputDbInstall()
    {
        $this->validatePrompt('database.name', $this->text('Database name'), 'install');
        $this->validatePrompt('database.user', $this->text('Database user'), 'install', 'root');
        $this->validatePrompt('database.password', $this->text('Database password'), 'install', '');
        $this->validatePrompt('database.port', $this->text('Database port'), 'install', '3306');
        $this->validatePrompt('database.host', $this->text('Database port'), 'install', 'localhost');

        $this->validateInputDbTypeInstall();
    }
530513
protected function validateTableName($tableName = null)
    {
        $tableName = $tableName === null ? $this->tableName : $tableName;

        if ($tableName === null) {
            throw new DbExporterException('Table name is null');
        }

        return $tableName;
    }
333336
public function validate()
    {
        $isSubmitted = false;
        foreach ($this->datasources as $ds) {
            if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
                $isSubmitted = true;
                break;
            }
        }
        return $isSubmitted? parent::validate(): false;
    }
822428
public function hasDatabase()
    {
        try {
            $pdo = new \PDO(
                'mysql:host='.$this->txpcfg['host'].';dbname='.$this->txpcfg['db'],
                $this->txpcfg['user'],
                $this->txpcfg['pass']
            );
        } catch (\PDOException $e) {
            $pdo = false;
        }

        if ($pdo === false) {
            throw new \InvalidArgumentException(
                'Unable connect to Textpattern database: '.$this->txpcfg['db'].'@'.$this->txpcfg['host']
            );
        }

        if (!$pdo->prepare('SHOW TABLES LIKE ?')->execute(array($this->txpcfg['table_prefix'] . 'textpattern'))) {
            throw new \InvalidArgumentException('Textpattern is not installed');
        }
    }
1149627
protected static function validate_database($databaseid) {
        global $DB;

        // Request and permission validation.
        $database = $DB->get_record('data', array('id' => $databaseid), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($database, 'data');

        $context = context_module::instance($cm->id);
        self::validate_context($context);
        require_capability('mod/data:viewentry', $context);

        return array($database, $course, $cm, $context);
    }
206071
protected function validateDestinationRename()
    {
        if ($this->isError()) {
            return null;
        }

        $files = $this->getSubmitted('files');

        /* @var $file \SplFileInfo */
        $file = reset($files);
        $name = $this->getSubmitted('name');

        $directory = dirname($file->getRealPath());
        $destination = gplcart_path_normalize("$directory/$name");

        if (file_exists($destination)) {
            $this->setError('name', $this->translation->text('Destination already exists'));
            return false;
        }

        $this->setSubmitted('destination', $destination);
        return true;
    }
101535
private function validateDatabaseDetails($environment)
    {
        $db_config = [];
        $configFile = DIR_CONFIG_SITE . '/database.php';
        $environmentConfig = DIR_CONFIG_SITE . "/{$environment}.database.php";

        // If the database.php file exists, load it first
        if (file_exists($configFile)) {
            $db_config = include DIR_CONFIG_SITE . '/database.php';
        }

        // If there's an environment specific database file, load that too
        if (file_exists($environmentConfig)) {
            $db_config = array_merge($db_config, include $environmentConfig);
        }

        // Make sure the default connection is set
        $defaultConnection = array_get($db_config, 'default-connection');

        // Make sure we have all the stuff we expect
        $connection = array_get($db_config, "connections.{$defaultConnection}");

        // Make sure we have all the keys we are expecting
        return $defaultConnection && $connection &&
            array_get($connection, 'database') &&
            array_get($connection, 'username') &&
            array_get($connection, 'server');
    }