Validates a database driver
@return boolean
768687
protected function validateDbTypeInstall()
    {
        $field = 'database.type';

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

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

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

        $drivers = \PDO::getAvailableDrivers();

        if (in_array($value, $drivers)) {
            return true;
        }

        $error = $this->translation->text('Unsupported database driver. Available drivers: @list', array(
            '@list' => implode(',', $drivers)));

        $this->setError($field, $error);
        return false;
    }
1097559
protected function validate_mysql( $mysql ) {
		if ( ! empty( $mysql['version'] ) ) {
			$this->results['mysql']['version']  = version_compare( $this->get_current_mysql_ver(), $mysql['version'], $this->version_compare_operator );
			$this->required['mysql']['version'] = $mysql['version'];
		}
	}
1031699
protected function validateInputDbTypeInstall()
    {
        $drivers = PDO::getAvailableDrivers();
        $title = $this->text('Database type (enter a number)');
        $input = $this->menu(array_combine($drivers, $drivers), 'mysql', $title);

        if (!$this->isValidInput($input, 'database.type', 'install')) {
            $this->errors();
            $this->validateInputDbTypeInstall();
        }
    }
429607
protected function validateData()
    {
        foreach ($this->relationalData as $attribute => &$data) {
            /** @var ActiveRecord $model */
            /** @var ActiveQuery $activeQuery */
            $activeQuery = $data['activeQuery'];
            foreach ($data['newModels'] as &$model) {
                if (!$model->validate()) {
                    $_errors = $model->getErrors();
                    $errors = [];

                    foreach ($_errors as $relatedAttribute => $error) {
                        if (!$activeQuery->multiple || !isset($activeQuery->link[$relatedAttribute])) {
                            $errors[$relatedAttribute] = $error;
                        }
                    }

                    if (count($errors)) {
                        $this->owner->addError($attribute, $errors);

                        return false;
                    }
                }
            }
        }

        return true;
    }
115844
private void validateSQLFields()
	{

		boolean flag = controller.isEnableSQLDatabaseOutput();

		enableSQLDatabaseConnection.setSelected(flag);

		sqlHostLabel.setEnabled(flag);
		sqlHostField.setEnabled(flag);
		sqlDatabaseLabel.setEnabled(flag);
		sqlDatabaseField.setEnabled(flag);
		sqlUserLabel.setEnabled(flag);
		sqlUserField.setEnabled(flag);
		sqlPasswordLabel.setEnabled(flag);
		sqlPasswordField.setEnabled(flag);

		enableZipEncodingCheckBox.setEnabled(flag);
	}
513248
public static function requireDriver($driver)
    {
        if (empty($driver)) {
            throw new \Exception("Database driver name can not be empty.");
        }

        // clients now use indirect association to drivers, dblib can be sqlsrv or sqlanywhere
        if ('dblib' === $driver) {
            $driver = 'sqlsrv';
        }
        $pdoDriver = null;
        switch ($driver) {
            case 'ibm':
                if (!extension_loaded('ibm_db2')) {
                    throw new \Exception("Required extension 'ibm_db2' is not detected, but may be compiled in.");
                }
                $pdoDriver = 'ibm';
                break;
            case 'mysql':
                if (!extension_loaded('mysql') && !extension_loaded('mysqlnd')) {
                    throw new \Exception("Required extension 'mysql' is not detected, but may be compiled in.");
                }
                $pdoDriver = 'mysql';
                break;
            case 'oracle':
                if (!extension_loaded('oci8')) {
                    throw new \Exception("Required extension 'oci8' is not detected, but may be compiled in.");
                }
                break;
            case 'pgsql':
                if (!extension_loaded('pgsql')) {
                    throw new \Exception("Required extension 'pgsql' is not detected, but may be compiled in.");
                }
                $pdoDriver = 'pgsql';
                break;
            case 'sqlanywhere':
                $extension = 'mssql';
                if (!extension_loaded($extension)) {
                    throw new \Exception("Required extension 'mssql' is not detected, but may be compiled in.");
                }
                $pdoDriver = 'dblib';
                break;
            case 'sqlite':
                if (!extension_loaded('sqlite3')) {
                    throw new \Exception("Required extension 'sqlite3' is not detected, but may be compiled in.");
                }
                $pdoDriver = 'sqlite';
                break;
            case 'sqlsrv':
                $pdoDriver = 'sqlsrv';
                $extension = 'sqlsrv';

                if (!extension_loaded($extension)) {
                    $pdoDriver = 'dblib';
                    $extension = 'mssql';
                    if (!extension_loaded($extension)) {
                        throw new \Exception("Required extension '$extension' is not detected, but may be compiled in.");
                    }
                }
                break;
            default:
                throw new \Exception("Driver '$driver' is not supported by this software.");
                break;
        }

        if ($pdoDriver) {
            static::checkForPdoDriver($pdoDriver);
        }

        return true;
    }
1191418
public function validate()
    {
        $result = array();
        if(empty($this->slug)) $this->slug = $this->title;
        $this->slug = \lib\MyFunctions::slug($this->slug);
        if (empty($this->slug)) {
            $result['slug'] = Validate::cantLeaveBlank(_('Slug'));
        } else {
            $slugExists = self::checkSlug($this->slug,$this->id);
            if ($slugExists) {
                $result['slug'] = _('Repeated slug');
            }
        }
        if (empty($this->title)) {
            $result['title'] = Validate::cantLeaveBlank(_('Title'));
        }
        if (empty($this->description)) {
            $result['description'] = Validate::cantLeaveBlank(_('Description'));
        }

        return $result;
    }
388591
public function validate()
    {
        $v = $this->validator();

        /**
         * Validation map
         *
         * Format:
         *
         * 'key' =>  array(
         *    'method' => this class method name to call, string, required
         *    'method_args' => optional args for 'method' call, array, optional
         *    'v_method' => validator method to call, string, required
         *    'error' => custom error string when validation fails, optional
         *               if not set, error string fprmatted as "Invalid '$key' specified"
         *    'v_error_method' => validator method - when called returned error string
         *                        prepared by validator, optional,
         *                        if not set => see 'error'
         *    'optional' => optional value, if it's empty validation result ignored
         *
         */
        $validateMap = array(
            'name' => array('method' => 'getName',
                'v_method' => 'validatePackageName',
                'error'=>"Invalid package name, allowed: [a-zA-Z0-9_-] chars"),
            'version' => array('method' => 'getVersion',
                'v_method' => 'validateVersion',
                'error'=>"Invalid version, should be like: x.x.x"),
            'stability' => array('method' => 'getStability',
                'v_method' => 'validateStability',
                'error'=>"Invalid stability"),
            'date' => array('method' => 'getDate',
                'v_method' => 'validateDate',
                'error'=>"Invalid date, should be YYYY-DD-MM"),
            'license_uri' => array('method' => 'getLicenseUri',
                'v_method' => 'validateLicenseUrl',
                'error'=>"Invalid license URL"),
            'channel' => array('method' => 'getChannel',
                'v_method' => 'validateChannelNameOrUri',
                'error'=>"Invalid channel URL"),
            'authors' => array('method' => 'getAuthors',
                'v_method' => 'validateAuthors',
                'v_error_method' => 'getErrors'),
            'php_min' => array('method' => 'getDependencyPhpVersionMin',
                'v_method' => 'validateVersion',
                'error' => 'PHP minimum version invalid',
                'optional' => true ),
            'php_max' => array('method' => 'getDependencyPhpVersionMax',
                'v_method' => 'validateVersion',
                'error' => 'PHP maximum version invalid',
                'optional' => true ),
            'compatible' => array('method' => 'getCompatible',
                'v_method' => 'validateCompatible',
                'v_error_method' => 'getErrors'),
            'content' => array('method' => 'getContents',
                'v_method' => 'validateContents',
                'v_args' => array('config' => $this->getConfig()),
                'v_error_method' => 'getErrors'),
        );

        $errors = array();
        /**
         * Iterate validation map
         */
        foreach($validateMap as $name=>$data) {

            /**
             * Check mandatory rules fields
             */
            if(!isset($data['method'], $data['v_method'])) {
                throw new Mage_Exception("Invalid rules specified!");
            }

            $method = $data['method'];
            $validatorMethod = $data['v_method'];

            /**
             * If $optional === false, value is mandatory
             */
            $optional = isset($data['optional']) ? (bool) $data['optional'] : false;

            /**
             * Check for method availability, package
             */
            if(!method_exists($this, $method)) {
                throw new Mage_Exception("Invalid method specified for Package : $method");
            }

            /**
             * Check for method availability, validator
             */
            if(!method_exists($v, $validatorMethod)) {
                throw new Mage_Exception("Invalid method specified for Validator : $validatorMethod");
            }

            /**
             * If    $data['error'] => get error string from $data['error']
             * Else  concatenate "Invalid '{$name}' specified"
             */
            $errorString = isset($data['error']) ? $data['error'] : "Invalid '{$name}' specified";

            /**
             * Additional method args check
             * array() by default
             */
            $methodArgs = isset($data['method_args']) ? $data['method_args'] : array();

            /**
             * Call package method
             */
            $out = @call_user_func_array(array($this, $method), $methodArgs);

            /**
             * Skip if result is empty and value is optional
             */
            if(empty($out) && $optional) {
                continue;
            }

            /**
             * Additional validator arguments, merged with array($out)
             */
            $validatorArgs = isset($data['v_args']) ? array_merge(array($out), $data['v_args']) : array($out);

            /**
             * Get validation result
             */
            $result = call_user_func_array(array($v, $validatorMethod), $validatorArgs);

            /**
             * Skip if validation success
             */
            if($result) {
                continue;
            }

            /**
             * From where to get error string?
             * If    validator callback method specified, call it to get errors array
             * Else  get it from $errorString - local error string
             */
            $validatorFetchErrorsMethod = isset($data['v_error_method']) ? $data['v_error_method'] : false;
            if (false !== $validatorFetchErrorsMethod) {
                $errorString = call_user_func_array(array($v, $validatorFetchErrorsMethod), array());
            }

            /**
             * If   errors is array => merge
             * Else append
             */
            if(is_array($errorString)) {
                $errors = array_merge($errors, $errorString);
            } else {
                $errors[] = $errorString;
            }
        }
        /**
         * Set local errors
         */
        $this->setErrors($errors);
        /**
         * Return true if there's no errors :)
         */
        return ! $this->hasErrors();
    }
1108004
private static function isValidDriver(string $driver): bool
    {
        return
            class_exists($driver) &&
            Arr::contains(class_implements($driver), StorageInterface::class);
    }
582033
public function driver_name()
	{
		// Make sure the database is connected
		$this->_connection or $this->connect();

		// Getting driver name
		return $this->_connection->getAttribute(\PDO::ATTR_DRIVER_NAME);
	}
1216341
public function validate() : bool
    {
        $table = $this->getConfig()->getTable();
        foreach ([$this->config->getField(), $this->config->getDisplayField()] as $field) {
            if ($table->getSchema()->hasColumn($field)) {
                continue;
            }

            $this->errors[] = sprintf('Unknown column "%s" for table "%s"', $field, $table->getAlias());
        }

        return empty($this->errors);
    }
454970
public function valid()
    {
        if ($this->container['shoutcastDestination'] === null) {
            return false;
        }
        if ($this->container['icecast2Public'] === null) {
            return false;
        }
        if ($this->container['akamaiDestinationServer'] === null) {
            return false;
        }
        if ($this->container['shoutcastIcq'] === null) {
            return false;
        }
        if ($this->container['facebookEventSourceName'] === null) {
            return false;
        }
        if ($this->container['timeToLive'] === null) {
            return false;
        }
        if ($this->container['password'] === null) {
            return false;
        }
        if ($this->container['facebookDestType'] === null) {
            return false;
        }
        if ($this->container['rtpWrap'] === null) {
            return false;
        }
        if ($this->container['icecast2Name'] === null) {
            return false;
        }
        if ($this->container['akamaiHostId'] === null) {
            return false;
        }
        if ($this->container['icecast2Icq'] === null) {
            return false;
        }
        if ($this->container['host'] === null) {
            return false;
        }
        if ($this->container['connectionFlashVersion'] === null) {
            return false;
        }
        if ($this->container['cupertinoRenditions'] === null) {
            return false;
        }
        if ($this->container['facebookTitle'] === null) {
            return false;
        }
        if ($this->container['debugPackets'] === null) {
            return false;
        }
        if ($this->container['shoutcastPublic'] === null) {
            return false;
        }
        if ($this->container['shoutcastAim'] === null) {
            return false;
        }
        if ($this->container['profile'] === null) {
            return false;
        }
        if ($this->container['icecast2Description'] === null) {
            return false;
        }
        if ($this->container['sessionStatus'] === null) {
            return false;
        }
        if ($this->container['shoutcastMetaname'] === null) {
            return false;
        }
        if ($this->container['icecast2Genre'] === null) {
            return false;
        }
        if ($this->container['facebookDestId'] === null) {
            return false;
        }
        if ($this->container['queryString'] === null) {
            return false;
        }
        if ($this->container['akamaiEventName'] === null) {
            return false;
        }
        if ($this->container['version'] === null) {
            return false;
        }
        if ($this->container['shoutcastName'] === null) {
            return false;
        }
        if ($this->container['sendStreamCloseCommands'] === null) {
            return false;
        }
        if ($this->container['port'] === null) {
            return false;
        }
        if ($this->container['sendFCPublish'] === null) {
            return false;
        }
        if ($this->container['icecast2Aim'] === null) {
            return false;
        }
        if ($this->container['httpPlaylistCount'] === null) {
            return false;
        }
        if ($this->container['httpPlaylistTimeout'] === null) {
            return false;
        }
        if ($this->container['facebookDestName'] === null) {
            return false;
        }
        if ($this->container['audioPort'] === null) {
            return false;
        }
        if ($this->container['icecast2Metaname'] === null) {
            return false;
        }
        if ($this->container['sourceStreamName'] === null) {
            return false;
        }
        if ($this->container['connectionCode'] === null) {
            return false;
        }
        if ($this->container['localBindAddress'] === null) {
            return false;
        }
        if ($this->container['shoutcastProtocol'] === null) {
            return false;
        }
        if ($this->container['debugLogChildren'] === null) {
            return false;
        }
        if ($this->container['serverName'] === null) {
            return false;
        }
        if ($this->container['adaptiveStreaming'] === null) {
            return false;
        }
        if ($this->container['facebookEventSourceType'] === null) {
            return false;
        }
        if ($this->container['enabled'] === null) {
            return false;
        }
        if ($this->container['shoutcastIrc'] === null) {
            return false;
        }
        if ($this->container['sendReleaseStream'] === null) {
            return false;
        }
        if ($this->container['shoutcastUrl'] === null) {
            return false;
        }
        if ($this->container['icecast2Irc'] === null) {
            return false;
        }
        if ($this->container['facebookDescription'] === null) {
            return false;
        }
        if ($this->container['debugLog'] === null) {
            return false;
        }
        if ($this->container['shoutcastGenre'] === null) {
            return false;
        }
        if ($this->container['akamaiStreamId'] === null) {
            return false;
        }
        if ($this->container['akamaiHdNetwork'] === null) {
            return false;
        }
        if ($this->container['adaptiveGroups'] === null) {
            return false;
        }
        if ($this->container['httpPlaylistAcrossSessions'] === null) {
            return false;
        }
        if ($this->container['secureTokenSharedSecret'] === null) {
            return false;
        }
        if ($this->container['httpFakePosts'] === null) {
            return false;
        }
        if ($this->container['sendSSL'] === null) {
            return false;
        }
        if ($this->container['sendOriginalTimecodes'] === null) {
            return false;
        }
        if ($this->container['icecast2Destination'] === null) {
            return false;
        }
        if ($this->container['facebookAccessToken'] === null) {
            return false;
        }
        if ($this->container['userName'] === null) {
            return false;
        }
        if ($this->container['facebookPrivacy'] === null) {
            return false;
        }
        if ($this->container['streamName'] === null) {
            return false;
        }
        if ($this->container['removeDefaultAppInstance'] === null) {
            return false;
        }
        if ($this->container['videoPort'] === null) {
            return false;
        }
        if ($this->container['httpWriterDebug'] === null) {
            return false;
        }
        if ($this->container['icecast2Url'] === null) {
            return false;
        }
        if ($this->container['akamaiSendToBackupServer'] === null) {
            return false;
        }
        if ($this->container['destinationServer'] === null) {
            return false;
        }
        if ($this->container['application'] === null) {
            return false;
        }
        if ($this->container['entryName'] === null) {
            return false;
        }
        if ($this->container['streamWaitTimeout'] === null) {
            return false;
        }
        if ($this->container['appInstance'] === null) {
            return false;
        }
        if ($this->container['originalTimecodeThreshold'] === null) {
            return false;
        }
        if ($this->container['autoStartTranscoder'] === null) {
            return false;
        }
        if ($this->container['sanjoseRepresentationId'] === null) {
            return false;
        }
        return true;
    }
247924
protected function validate()
    {
        if (empty($this->author)) {
            throw new \Exception('Author is empty!');
        }

        if (empty($this->classname)) {
            throw new \Exception('Class name is empty!');
        }

        if (empty($this->namespace)) {
            throw new \Exception('Namespace is empty!');
        }

        /*if (empty($this->dbConfig)) {
            throw new \Exception('Database config name is empty!');
        }*/

        if (empty($this->dbTable)) {
            throw new \Exception('Database table name is empty!');
        }

        if (empty($this->cacheName)) {
            throw new \Exception('Cache name is empty!');
        }

        if (empty($this->cachePrefix)) {
            throw new \Exception('Cache prefix is empty!');
        }

        return $this;
    }
1191231
public function connectionSettingsAreValid()
    {
        // if there is no adapter how can we initialize the correct validator to check it
        if (!$this->getDbAdapter()) {
            return false;
        }

        /**
         * @var MySQLConnectionSettings $connectionSettings
         */
        $connectionSettings = $this->getDbAdapter()->getConnectionSettings();
        if (!$connectionSettings) {
            return false;
        }

        return $connectionSettings->validateProperties();
    }
667785
public function validate()
    {
        $steps = [
            'PrivateKey',
            'IdpMetadata',
            'SpMetadata'
        ];

        foreach ($steps as $step) {
            $method = 'validate' . $step;
            if (!$this->$method()) {
                return false;
            }
        }

        return true;
    }
318948
protected function validateDatabase()
    {
        $databaseConfig = DB::getConfig();
        // Gracefully fail if no DB is configured
        if (empty($databaseConfig['database'])) {
            $this->detectLegacyEnvironment();
            $this->redirectToInstaller();
        }
    }
273279
public function beforeValidate()
    {
        if (!parent::beforeValidate()) {
            return false;
        }

        $dsn = '';
        switch ($this->dbType) {
            case 'mysql':
                $dsn = "mysql:host={$this->dbHost};dbname={$this->dbName}";
                break;
        }

        // Test the Db
        $db = Yii::$app->getDb();
        $db->dsn = $dsn;
        $db->username = $this->dbUsername;
        $db->password = $this->dbPassword;
        $db->tablePrefix = $this->dbTablePrefix;
        try {
            $db->open();
        } catch (\Exception $e) {
            $this->globalError = $e->getMessage();
            return false;
        }
        return true;
    }