php/validator.php
public function validate_table($table_name, $input_data){
		$errors = array();

		$table_definition = $this->exdb->get_table_definition( $table_name );
		if( !@$table_definition ){
			$errors[':common'] = 'Table NOT Exists';
			return $errors;
		}

		// 余計な値が送られていないかチェック
		foreach( $input_data as $key=>$val ){
			if( !@$table_definition->columns->{$key} ){
				$errors[':common'] = '"'.$key.'" is NOT Exists in table "'.$table_name.'".';
			}
		}

		// --------------------------------------
		// 入力値のチェック
		foreach( $table_definition->columns as $column_definition ){
			if( !array_key_exists($column_definition->name, $input_data) ){
				// `$input_data` に含まれていないキーは調べない
				continue;
			}
			$value = @$input_data[$column_definition->name];

			$restrictions = array();
			if($column_definition->not_null){
				$restrictions['required'] = true;
			}
			$detect_errors = $this->detect_errors($value, $column_definition->type, $restrictions);

			if( count($detect_errors) ){
				$errors[$column_definition->name] = implode(' ', $detect_errors);
				continue;
			}

			// FOREIGN KEY 制約
			if( $column_definition->foreign_key ){
				$foreign_key = explode( '.', $column_definition->foreign_key );
				$foreign_row = $this->exdb->select(
					$foreign_key[0],
					array(
						$foreign_key[1] => $value,
					),
					array(
						'limit' => 1
					)
				);
				if( !$foreign_row ){
					$errors[$column_definition->name] = 'Foreign key is not exists.';
					continue;
				}
				unset($foreign_key, $foreign_row);
			}
		}

		return $errors;
	}
public function validate_table($table_name, $input_data){
		$errors = array();

		$table_definition = $this->exdb->get_table_definition( $table_name );
		if( !@$table_definition ){
			$errors[':common'] = 'Table NOT Exists';
			return $errors;
		}

		// 余計な値が送られていないかチェック
		foreach( $input_data as $key=>$val ){
			if( !@$table_definition->columns->{$key} ){
				$errors[':common'] = '"'.$key.'" is NOT Exists in table "'.$table_name.'".';
			}
		}

		// --------------------------------------
		// 入力値のチェック
		foreach( $table_definition->columns as $column_definition ){
			if( !array_key_exists($column_definition->name, $input_data) ){
				// `$input_data` に含まれていないキーは調べない
				continue;
			}
			$value = @$input_data[$column_definition->name];

			$restrictions = array();
			if($column_definition->not_null){
				$restrictions['required'] = true;
			}
			$detect_errors = $this->detect_errors($value, $column_definition->type, $restrictions);

			if( count($detect_errors) ){
				$errors[$column_definition->name] = implode(' ', $detect_errors);
				continue;
			}

			// FOREIGN KEY 制約
			if( $column_definition->foreign_key ){
				$foreign_key = explode( '.', $column_definition->foreign_key );
				$foreign_row = $this->exdb->select(
					$foreign_key[0],
					array(
						$foreign_key[1] => $value,
					),
					array(
						'limit' => 1
					)
				);
				if( !$foreign_row ){
					$errors[$column_definition->name] = 'Foreign key is not exists.';
					continue;
				}
				unset($foreign_key, $foreign_row);
			}
		}

		return $errors;
	}
public function validate_table ( $ table_name , $ input_data ) { $ errors = array ( ) ; $ table_definition = $ this -> exdb -> get_table_definition ( $ table_name ) ; if ( ! @ $ table_definition ) { $ errors [ ':common' ] = 'Table NOT Exists' ; return $ errors ; } // 余計な値が送られていないかチェック foreach ( $ input_data as $ key => $ val ) { if ( ! @ $ table_definition -> columns -> { $ key } ) { $ errors [ ':common' ] = '"' . $ key . '" is NOT Exists in table "' . $ table_name . '".' ; } } // -------------------------------------- // 入力値のチェック foreach ( $ table_definition -> columns as $ column_definition ) { if ( ! array_key_exists ( $ column_definition -> name , $ input_data ) ) { // `$input_data` に含まれていないキーは調べない continue ; } $ value = @ $ input_data [ $ column_definition -> name ] ; $ restrictions = array ( ) ; if ( $ column_definition -> not_null ) { $ restrictions [ 'required' ] = true ; } $ detect_errors = $ this -> detect_errors ( $ value , $ column_definition -> type , $ restrictions ) ; if ( count ( $ detect_errors ) ) { $ errors [ $ column_definition -> name ] = implode ( ' ' , $ detect_errors ) ; continue ; } // FOREIGN KEY 制約 if ( $ column_definition -> foreign_key ) { $ foreign_key = explode ( '.' , $ column_definition -> foreign_key ) ; $ foreign_row = $ this -> exdb -> select ( $ foreign_key [ 0 ] , array ( $ foreign_key [ 1 ] => $ value , ) , array ( 'limit' => 1 ) ) ; if ( ! $ foreign_row ) { $ errors [ $ column_definition -> name ] = 'Foreign key is not exists.' ; continue ; } unset ( $ foreign_key , $ foreign_row ) ; } } return $ errors ; }
Validate Table Values
@param  string $table_name テーブル名
@param  array $input_data 入力データ
@return array エラー配列
Validate Table Values