MailPoet\EmailEditor\Validator\Schema

String_Schema{}WC 1.0

Represents a schema for a string. See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#strings

No Hooks.

Usage

$String_Schema = new String_Schema();
// use class methods

Methods

  1. public formatDateTime()
  2. public formatEmail()
  3. public formatHexColor()
  4. public formatIp()
  5. public formatUri()
  6. public formatUuid()
  7. public maxLength( int $value )
  8. public minLength( int $value )
  9. public pattern( string $pattern )

String_Schema{} code WC 9.8.2

class String_Schema extends Schema {
	/**
	 * Schema definition.
	 *
	 * @var array
	 */
	protected $schema = array(
		'type' => 'string',
	);

	/**
	 * Set minimum length of the string.
	 *
	 * @param int $value Minimum length.
	 */
	public function minLength( int $value ): self {
		return $this->update_schema_property( 'minLength', $value );
	}

	/**
	 * Set maximum length of the string.
	 *
	 * @param int $value Maximum length.
	 */
	public function maxLength( int $value ): self {
		return $this->update_schema_property( 'maxLength', $value );
	}

	/**
	 * Parameter $pattern is a regular expression without leading/trailing delimiters.
	 * See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#pattern
	 *
	 * @param string $pattern Regular expression pattern.
	 */
	public function pattern( string $pattern ): self {
		$this->validate_pattern( $pattern );
		return $this->update_schema_property( 'pattern', $pattern );
	}

	/**
	 * Set the format of the string according to DateTime.
	 */
	public function formatDateTime(): self {
		return $this->update_schema_property( 'format', 'date-time' );
	}

	/**
	 * Set the format of the string according to email.
	 */
	public function formatEmail(): self {
		return $this->update_schema_property( 'format', 'email' );
	}

	/**
	 * Set the format of the string according to Hex color.
	 */
	public function formatHexColor(): self {
		return $this->update_schema_property( 'format', 'hex-color' );
	}

	/**
	 * Set the format of the string according to IP address.
	 */
	public function formatIp(): self {
		return $this->update_schema_property( 'format', 'ip' );
	}

	/**
	 * Set the format of the string according to uri.
	 */
	public function formatUri(): self {
		return $this->update_schema_property( 'format', 'uri' );
	}

	/**
	 * Set the format of the string according to uuid.
	 */
	public function formatUuid(): self {
		return $this->update_schema_property( 'format', 'uuid' );
	}
}