HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/appointmentbook.me/wp-content/plugins/booknetic/app/Providers/Request/Post.php
<?php

namespace BookneticApp\Providers\Request;

//That's why generics...
class Post implements Request {
	public static function string( string $key, string $default = '', array $whiteList = [] ): string {
		if ( empty( $_POST[ $key ] ) ) {
			return $default;
		}

		$field = $_POST[ $key ];

		if ( ! is_string( $field ) ) {
			return $default;
		}

		$field = trim( stripslashes_deep( $field ) );

		if ( ! empty( $whiteList ) && ! in_array( $field, $whiteList ) ) {
			return $default;
		}

		return $field;
	}

	public static function int( string $key, int $default = 0, array $whiteList = [] ): int {
		if ( empty( $_POST[ $key ] ) ) {
			return $default;
		}

		$field = $_POST[ $key ];

		if ( ! is_numeric( $field ) ) {
			return $default;
		}

		if ( ! empty( $whiteList ) && ! in_array( $field, $whiteList ) ) {
			return $default;
		}

		return (int) $field;
	}

	public static function bool( string $key, bool $default = false ): bool {
		return ! empty( $_POST[ $key ] ) ?: $default ;
	}

	public static function array( string $key, array $default = [], array $whiteList = [] ): array {
		if ( empty( $_POST[ $key ] ) ) {
			return $default;
		}

		$field = $_POST[ $key ];

		if ( ! is_array( $field ) ) {
			return $default;
		}

		$field = stripslashes_deep( $field );

		if ( ! empty( $whiteList ) && ! in_array( $field, $whiteList ) ) {
			return $default;
		}

		return $field;
	}
}