protected function addValidators(Database $database)
    {

        $platform = $this->getGeneratorConfig()->getConfiguredPlatform();

        foreach ($database->getTables() as $table) {

            $set = new PropelSchemaReverse_ValidatorSet();

            foreach ($table->getColumns() as $col) {

                if ($col->isNotNull() && $this->isValidatorRequired(self::VALIDATORS_REQUIRED)) {
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'required'));
                }

                if (in_array($col->getType(), array(PropelTypes::CHAR, PropelTypes::VARCHAR, PropelTypes::LONGVARCHAR)) && $col->getSize() && $this->isValidatorRequired(self::VALIDATORS_MAXLENGTH)) {
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'maxLength', $col->getSize()));
                }

                if ($col->isNumericType() && $this->isValidatorRequired(self::VALIDATORS_MAXVALUE)) {
                    $this->log("WARNING: maxValue validator added for column " . $col->getName() . ". You will have to adjust the size value manually.", Project::MSG_WARN);
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'maxValue', 'REPLACEME'));
                }

                if ($col->isPhpPrimitiveType() && $this->isValidatorRequired(self::VALIDATORS_TYPE)) {
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'type', $col->getPhpType()));
                }
            }

            foreach ($table->getUnices() as $unique) {
                $colnames = $unique->getColumns();
                if (count($colnames) == 1) { // currently 'unique' validator only works w/ single columns.
                    $col = $table->getColumn($colnames[0]);
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'unique'));
                }
            }

            foreach ($set->getValidators() as $validator) {
                $table->addValidator($validator);
            }
        } // foreach table

    }
protected function addValidators(Database $database)
    {

        $platform = $this->getGeneratorConfig()->getConfiguredPlatform();

        foreach ($database->getTables() as $table) {

            $set = new PropelSchemaReverse_ValidatorSet();

            foreach ($table->getColumns() as $col) {

                if ($col->isNotNull() && $this->isValidatorRequired(self::VALIDATORS_REQUIRED)) {
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'required'));
                }

                if (in_array($col->getType(), array(PropelTypes::CHAR, PropelTypes::VARCHAR, PropelTypes::LONGVARCHAR)) && $col->getSize() && $this->isValidatorRequired(self::VALIDATORS_MAXLENGTH)) {
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'maxLength', $col->getSize()));
                }

                if ($col->isNumericType() && $this->isValidatorRequired(self::VALIDATORS_MAXVALUE)) {
                    $this->log("WARNING: maxValue validator added for column " . $col->getName() . ". You will have to adjust the size value manually.", Project::MSG_WARN);
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'maxValue', 'REPLACEME'));
                }

                if ($col->isPhpPrimitiveType() && $this->isValidatorRequired(self::VALIDATORS_TYPE)) {
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'type', $col->getPhpType()));
                }
            }

            foreach ($table->getUnices() as $unique) {
                $colnames = $unique->getColumns();
                if (count($colnames) == 1) { // currently 'unique' validator only works w/ single columns.
                    $col = $table->getColumn($colnames[0]);
                    $validator = $set->getValidator($col);
                    $validator->addRule($this->getValidatorRule($col, 'unique'));
                }
            }

            foreach ($set->getValidators() as $validator) {
                $table->addValidator($validator);
            }
        } // foreach table

    }
protected function addValidators ( Database $ database ) { $ platform = $ this -> getGeneratorConfig ( ) -> getConfiguredPlatform ( ) ; foreach ( $ database -> getTables ( ) as $ table ) { $ set = new PropelSchemaReverse_ValidatorSet ( ) ; foreach ( $ table -> getColumns ( ) as $ col ) { if ( $ col -> isNotNull ( ) && $ this -> isValidatorRequired ( self :: VALIDATORS_REQUIRED ) ) { $ validator = $ set -> getValidator ( $ col ) ; $ validator -> addRule ( $ this -> getValidatorRule ( $ col , 'required' ) ) ; } if ( in_array ( $ col -> getType ( ) , array ( PropelTypes :: CHAR , PropelTypes :: VARCHAR , PropelTypes :: LONGVARCHAR ) ) && $ col -> getSize ( ) && $ this -> isValidatorRequired ( self :: VALIDATORS_MAXLENGTH ) ) { $ validator = $ set -> getValidator ( $ col ) ; $ validator -> addRule ( $ this -> getValidatorRule ( $ col , 'maxLength' , $ col -> getSize ( ) ) ) ; } if ( $ col -> isNumericType ( ) && $ this -> isValidatorRequired ( self :: VALIDATORS_MAXVALUE ) ) { $ this -> log ( "WARNING: maxValue validator added for column " . $ col -> getName ( ) . ". You will have to adjust the size value manually." , Project :: MSG_WARN ) ; $ validator = $ set -> getValidator ( $ col ) ; $ validator -> addRule ( $ this -> getValidatorRule ( $ col , 'maxValue' , 'REPLACEME' ) ) ; } if ( $ col -> isPhpPrimitiveType ( ) && $ this -> isValidatorRequired ( self :: VALIDATORS_TYPE ) ) { $ validator = $ set -> getValidator ( $ col ) ; $ validator -> addRule ( $ this -> getValidatorRule ( $ col , 'type' , $ col -> getPhpType ( ) ) ) ; } } foreach ( $ table -> getUnices ( ) as $ unique ) { $ colnames = $ unique -> getColumns ( ) ; if ( count ( $ colnames ) == 1 ) { // currently 'unique' validator only works w/ single columns. $ col = $ table -> getColumn ( $ colnames [ 0 ] ) ; $ validator = $ set -> getValidator ( $ col ) ; $ validator -> addRule ( $ this -> getValidatorRule ( $ col , 'unique' ) ) ; } } foreach ( $ set -> getValidators ( ) as $ validator ) { $ table -> addValidator ( $ validator ) ; } } // foreach table }
Adds any requested validators to the data model.

We will add the following type specific validators:

for notNull columns: required validator
for unique indexes: unique validator
for varchar types: maxLength validators (CHAR, VARCHAR, LONGVARCHAR)
for numeric types: maxValue validators (BIGINT, SMALLINT, TINYINT, INTEGER, FLOAT, DOUBLE, NUMERIC, DECIMAL, REAL)
for integer and timestamp types: notMatch validator with [^\d]+ (BIGINT, SMALLINT, TINYINT, INTEGER, TIMESTAMP)
for float types: notMatch validator with [^\d\.]+ (FLOAT, DOUBLE, NUMERIC, DECIMAL, REAL)

@param Database $database The Database model.

@return void
@todo       find out how to evaluate the appropriate size and adjust maxValue rule values appropriate
@todo       find out if float type column values must always notMatch('[^\d\.]+'), i.e. digits and point for any db vendor, language etc.
Adds any requested validators to the data model .