src/Http/Filter.php
protected function parse_validation( $validation ) {
		$validation = explode( '|', $validation );

		$rules = array();

		foreach ( $validation as $rule ) {
			if ( 0 === strpos( $rule, 'default' ) ) {
				$rule_arr = explode( ':', $rule );

				$rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : '';
			}

			if ( 0 === strpos( $rule, 'oneof' ) ) {
				list( $rule, $values ) = explode( ':', $rule );

				$values   = explode( ',', $values );
				$callback = function ( $value ) use ( $values ) {
					if ( in_array( $value, $values, true ) ) {
						return true;
					}

					return false;
				};

				$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
			}

			switch ( $rule ) {
				case 'required':
					$rules['required'] = true;
					break;
				case 'integer':
					$callback                   = array( $this, 'validate_integer' );
					$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;

					$callback                   = array( $this, 'make_integer' );
					$rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback;
					break;
			}
		}

		return $rules;
	}
protected function parse_validation( $validation ) {
		$validation = explode( '|', $validation );

		$rules = array();

		foreach ( $validation as $rule ) {
			if ( 0 === strpos( $rule, 'default' ) ) {
				$rule_arr = explode( ':', $rule );

				$rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : '';
			}

			if ( 0 === strpos( $rule, 'oneof' ) ) {
				list( $rule, $values ) = explode( ':', $rule );

				$values   = explode( ',', $values );
				$callback = function ( $value ) use ( $values ) {
					if ( in_array( $value, $values, true ) ) {
						return true;
					}

					return false;
				};

				$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
			}

			switch ( $rule ) {
				case 'required':
					$rules['required'] = true;
					break;
				case 'integer':
					$callback                   = array( $this, 'validate_integer' );
					$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;

					$callback                   = array( $this, 'make_integer' );
					$rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback;
					break;
			}
		}

		return $rules;
	}
protected function parse_validation ( $ validation ) { $ validation = explode ( '|' , $ validation ) ; $ rules = array ( ) ; foreach ( $ validation as $ rule ) { if ( 0 === strpos ( $ rule , 'default' ) ) { $ rule_arr = explode ( ':' , $ rule ) ; $ rules [ 'default' ] = count ( $ rule_arr ) === 2 ? array_pop ( $ rule_arr ) : '' ; } if ( 0 === strpos ( $ rule , 'oneof' ) ) { list ( $ rule , $ values ) = explode ( ':' , $ rule ) ; $ values = explode ( ',' , $ values ) ; $ callback = function ( $ value ) use ( $ values ) { if ( in_array ( $ value , $ values , true ) ) { return true ; } return false ; } ; $ rules [ 'validate_callback' ] = isset ( $ rules [ 'validate_callback' ] ) ? $ this -> add_callback ( $ rules [ 'validate_callback' ] , $ callback ) : $ callback ; } switch ( $ rule ) { case 'required' : $ rules [ 'required' ] = true ; break ; case 'integer' : $ callback = array ( $ this , 'validate_integer' ) ; $ rules [ 'validate_callback' ] = isset ( $ rules [ 'validate_callback' ] ) ? $ this -> add_callback ( $ rules [ 'validate_callback' ] , $ callback ) : $ callback ; $ callback = array ( $ this , 'make_integer' ) ; $ rules [ 'sanitize_callback' ] = isset ( $ rules [ 'sanitize_callback' ] ) ? $ this -> add_callback ( $ rules [ 'sanitize_callback' ] , $ callback ) : $ callback ; break ; } } return $ rules ; }
Parses a validation string into a WP-API compatible rule.

@param string $validation

@return array

@todo The next rule added needs to refactor this process.
Parses a validation string into a WP - API compatible rule .