@todo Validate by schema instead

@throws Exception\RuntimeException
@throws Exception\DomainException
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();
    }
766251
public function validateForm()
    {
        $validator = $this->getValidationFactory()->make(
            $this->requestData(),
            $this->rules()
        );

        if ($validator->fails())
            throw new \Exception($this->formatErrors($validator->errors()));
    }
962983
public static function validate($dataSource, $schema, $numPeekRows = 10, $csvDialect = null)
    {
        try {
            $table = new static($dataSource, $schema, $csvDialect);
        } catch (Exceptions\DataSourceException $e) {
            return [new SchemaValidationError(SchemaValidationError::LOAD_FAILED, $e->getMessage())];
        }
        if ($numPeekRows > 0) {
            $i = 0;
            try {
                foreach ($table as $row) {
                    if (++$i > $numPeekRows) {
                        break;
                    }
                }
            } catch (Exceptions\DataSourceException $e) {
                // general error in getting the next row from the data source
                return [new SchemaValidationError(SchemaValidationError::ROW_VALIDATION, [
                    'row' => $i,
                    'error' => $e->getMessage(),
                ])];
            } catch (Exceptions\FieldValidationException $e) {
                // validation error in one of the fields
                return array_map(function ($validationError) use ($i) {
                    return new SchemaValidationError(SchemaValidationError::ROW_FIELD_VALIDATION, [
                        'row' => $i + 1,
                        'field' => $validationError->extraDetails['field'],
                        'error' => $validationError->extraDetails['error'],
                        'value' => $validationError->extraDetails['value'],
                    ]);
                }, $e->validationErrors);
            }
        }

        return [];
    }
785084
public function validationApplies()
    {
        $return = true;

        if ($criteria = $this->owner->validationLogicCriteria) {
            $fields = $this->owner->rootFieldList();
            if (eval($criteria->phpEvalString()) === false) {
                throw new Exception("There is a syntax error in the constaint logic phpEvalString \"{$criteria->phpEvalString()}\"");
            }
            $return = eval('return ' . $criteria->phpEvalString());
        }

        return $return;
    }
321673
public function validate() {

		if ($this->getCurrency() === null) {
			throw new ValidationException("'currency' can't be null", 'currency', $this);
		}
		if ($this->getProduct() === null) {
			throw new ValidationException("'product' can't be null", 'product', $this);
		}
		if ($this->getSubscription() === null) {
			throw new ValidationException("'subscription' can't be null", 'subscription', $this);
		}
	}
995552
protected function validate(stdClass $data): void
    {
        $config = $this->getConfig();
        $schema = $this->readSchema();

        // No need to validate empty data (empty() does not work on objects)
        $dataArray = Convert::objectToArray($data);
        if (empty($dataArray)) {
            if ($config['allowEmptyData'] === false) {
                throw new JsonValidationException('Empty data is not allowed.');
            }
            $this->warnings[] = "Skipping validation of empty data";

            return;
        }

        // No need to validate with empty schema (empty() does not work on objects)
        $schemaArray = Convert::objectToArray($schema);
        if (empty($schemaArray)) {
            if ($config['allowEmptySchema'] === false) {
                throw new JsonValidationException('Empty schema is not allowed.');
            }
            $this->warnings[] = "Skipping validation with empty schema";

            return;
        }

        $this->runValidator($data, $schema);
    }
521802
private function validateXml() : void
    {
        if (!isset($this->xml->project) || !isset($this->xml->project->metrics)) {
            throw new RuntimeException('invalid clover xml file');
        }
    }
806843
public function validate($schema = '')
    {
        
        $forced = $this->valid;
        $this->valid = true;
        
        try{
        	switch($this->sourceType){
        		case self::SOURCE_FILE:
	        		//check file
			   		if(!file_exists($this->source)){
			    		throw new Exception("File {$this->source} not found.");
			    	}
			    	if(!is_readable($this->source)){
			    		throw new Exception("Unable to read file {$this->source}.");
			    	}
			   		if(!preg_match("/\.zip$/", basename($this->source))){
			    		throw new Exception("Wrong file extension in {$this->source}, zip extension is expected");
			    	}
			   		if(!tao_helpers_File::securityCheck($this->source)){
			    		throw new Exception("{$this->source} seems to contain some security issues");
			    	}
			    	break;
                case self::SOURCE_FLYFILE:
                    //check file
                    if (!$this->source->exists()) {
                        throw new Exception("File {$this->source->getBasename()} not found.");
                    }
                    if (!preg_match("/\.zip$/", $this->source->getBasename())) {
                        throw new Exception("Wrong file extension in {$this->source->getBasename()}, zip extension is expected");
                    }
                    $this->extract();
			    	break;
        		default:
	        		throw new Exception("Only regular files are allowed as package source");
	        		break;
        	}
        }
        catch(Exception $e){
        	if($forced){
        		throw $e;
        	}
        	else{
        		$this->addError($e);
        	}
        }   
             
        if($this->valid && !$forced){	//valida can be true if forceValidation has been called
        	
        	$this->valid = false;
        	
			try{
	    		$zip = new ZipArchive();
	    		//check the archive opening and the consistency
	    		$res = $zip->open($this->source, ZIPARCHIVE::CHECKCONS);
				if( $res !== true){
				   
				    switch($res) {
				        case ZipArchive::ER_NOZIP :
				             $msg = 'not a zip archive';
				             break;
				        case ZipArchive::ER_INCONS :
				            $msg ='consistency check failed';
				            break;
				        case ZipArchive::ER_CRC :
				            $msg = 'checksum failed';
				            break;
				        default:
				            $msg ='Bad Zip file';
				    }
					throw new Exception($msg);
				}
				else{
					//check if the manifest is there
					if($zip->locateName("imsmanifest.xml") === false){
						throw new Exception("A QTI package must contains a imsmanifest.xml file  at the root of the archive");
					}
					
					$this->valid = true;
				}
				$zip->close();
			}
			catch(Exception $e){
				$this->addError($e);
			}
        }
        
    	$returnValue = $this->valid;
        
        return (bool) $returnValue;
    }
1186004
protected function validate($data)
    {
        $data = $this->validateSegment($data);
        if (! $data) {
            return $data;
        }

        $this->saveInternalEncoding();
        if (! $this->isValidHostLength($data)) {
            $this->restoreInternalEncoding();
            throw new RuntimeException('Invalid hostname, check its length');
        }

        if (! $this->isValidHostPattern($data)) {
            $this->restoreInternalEncoding();
            throw new RuntimeException('Invalid host label, check its content');
        }

        if (! $this->isValidHostLabels($data)) {
            $this->restoreInternalEncoding();
            throw new RuntimeException('Invalid host label counts, check its count');
        }

        $data = $this->sanitizeValue($data);
        $data = explode(
            $this->delimiter,
            $this->punycode->decode(implode($this->delimiter, $data))
        );
        $this->restoreInternalEncoding();

        return $data;
    }
403183
protected function validate()
    {
        // Do not perform request validation/transformation if it is disable
        if ($this[self::DISABLE_VALIDATION]) {
            return;
        }

        $errors = array();
        $validator = $this->getValidator();
        foreach ($this->operation->getParams() as $name => $schema) {
            $value = $this[$name];
            if (!$validator->validate($schema, $value)) {
                $errors = array_merge($errors, $validator->getErrors());
            } elseif ($value !== $this[$name]) {
                // Update the config value if it changed and no validation errors were encountered
                $this->data[$name] = $value;
            }
        }

        // Validate additional parameters
        $hidden = $this[self::HIDDEN_PARAMS];

        if ($properties = $this->operation->getAdditionalParameters()) {
            foreach ($this->toArray() as $name => $value) {
                // It's only additional if it isn't defined in the schema
                if (!$this->operation->hasParam($name) && !in_array($name, $hidden)) {
                    // Always set the name so that error messages are useful
                    $properties->setName($name);
                    if (!$validator->validate($properties, $value)) {
                        $errors = array_merge($errors, $validator->getErrors());
                    } elseif ($value !== $this[$name]) {
                        $this->data[$name] = $value;
                    }
                }
            }
        }

        if (!empty($errors)) {
            $e = new ValidationException('Validation errors: ' . implode("\n", $errors));
            $e->setErrors($errors);
            throw $e;
        }
    }
904850
public function getCurrentSchema()
    {
        try {
            $schema = $this->dbal->getDatabase();
        } catch (\Exception $e) {
            throw new Exception\RuntimeException('Cannot retrieve current schema:' . $e->getMessage());
        }

        return $schema;
    }
714688
public function evaluate(): void
    {
        $typeMap = $this->context->getSchema()->getTypeMap();

        foreach ($typeMap as $type) {
            if (!($type instanceof NamedTypeInterface)) {
                $this->context->reportError(
                    new SchemaValidationException(
                        \sprintf('Expected GraphQL named type but got: %s.', toString($type)),
                        $type instanceof ASTNodeAwareInterface ? [$type->getAstNode()] : null
                    )
                );

                continue;
            }

            // Ensure it is named correctly (excluding introspection types).
            /** @noinspection PhpParamsInspection */
            if (!isIntrospectionType($type)) {
                $this->validateName($type);
            }

            if ($type instanceof ObjectType) {
                // Ensure fields are valid.
                $this->validateFields($type);
                // Ensure objects implement the interfaces they claim to.
                $this->validateObjectInterfaces($type);
                continue;
            }

            if ($type instanceof InterfaceType) {
                // Ensure fields are valid.
                $this->validateFields($type);
                continue;
            }

            if ($type instanceof UnionType) {
                // Ensure Unions include valid member types.
                $this->validateUnionMembers($type);
                continue;
            }

            if ($type instanceof EnumType) {
                // Ensure Enums have valid values.
                $this->validateEnumValues($type);
                continue;
            }

            if ($type instanceof InputObjectType) {
                // Ensure Input Object fields are valid.
                $this->validateInputFields($type);
                continue;
            }
        }
    }
1154003
public function validate()
    {
        if (!$this->translatable) {
            throw new MappingException(sprintf('No translatable specified for %s', $this->name));
        }

        if (!$this->targetEntity) {
            throw new MappingException(sprintf('No translatable targetEntity specified for %s', $this->name));
        }

        if (!$this->locale) {
            throw new MappingException(sprintf('No locale specified for %s', $this->name));
        }
    }
427933
public function setValidationRules($table, string $field, Validator $validator, array $options = []) : Validator
    {
        $handler = self::getByTableField($table, $field);
        $validator = $handler->setValidationRules($validator, $options);
        if (! $validator instanceof Validator) {
            throw new RuntimeException(
                sprintf('Field Handler returned value must be an instance of %s.', Validator::class)
            );
        }

        return $validator;
    }
821354
protected function performValidation()
    {
        // All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.
        foreach (array_keys($this->attributes()) as $attribute) {
            if (is_array($this->$attribute)) {
                foreach ($this->$attribute as $k => $v) {
                    if (!preg_match('~^[a-zA-Z0-9\.\-_]+$~', $k)) {
                        $this->addError("Invalid key '$k' used in Components Object for attribute '$attribute', does not match ^[a-zA-Z0-9\.\-_]+\$.");
                    }
                }
            }
        }
    }
726387
protected function performValidation()
    {
        $this->requireProperties(['name', 'in']);
        if ($this->in === 'path') {
            $this->requireProperties(['required']);
            if (!$this->required) {
                $this->addError("Parameter 'required' must be true for 'in': 'path'.");
            }
        }
        if (!empty($this->content) && !empty($this->schema)) {
            $this->addError("A Parameter Object MUST contain either a schema property, or a content property, but not both. ");
        }
    }
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;
    }