class-arr.php
2 years ago
class-attachment.php
2 years ago
class-conditional.php
2 years ago
class-db.php
2 years ago
class-html.php
2 years ago
class-param.php
2 years ago
class-str.php
2 years ago
class-url.php
2 years ago
class-wordpress.php
2 years ago
index.php
2 years ago
class-param.php
74 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The Helper class that provides easy access to accessing params from $_GET, $_POST and $_REQUEST. |
| 4 | * |
| 5 | * @since 1.0.0 |
| 6 | * @package MyThemeShop |
| 7 | * @subpackage MyThemeShop\Helpers |
| 8 | * @author MyThemeShop <admin@mythemeshop.com> |
| 9 | */ |
| 10 | |
| 11 | namespace MyThemeShop\Helpers; |
| 12 | |
| 13 | /** |
| 14 | * Param class. |
| 15 | */ |
| 16 | class Param { |
| 17 | |
| 18 | /** |
| 19 | * Get field from query string. |
| 20 | * |
| 21 | * @param string $id Field id to get. |
| 22 | * @param mixed $default Default value to return if field is not found. |
| 23 | * @param int $filter The ID of the filter to apply. |
| 24 | * @param int $flag The ID of the flag to apply. |
| 25 | * |
| 26 | * @return mixed |
| 27 | */ |
| 28 | public static function get( $id, $default = false, $filter = FILTER_DEFAULT, $flag = [] ) { |
| 29 | return filter_has_var( INPUT_GET, $id ) ? filter_input( INPUT_GET, $id, $filter, $flag ) : $default; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get field from FORM post. |
| 34 | * |
| 35 | * @param string $id Field id to get. |
| 36 | * @param mixed $default Default value to return if field is not found. |
| 37 | * @param int $filter The ID of the filter to apply. |
| 38 | * @param int $flag The ID of the flag to apply. |
| 39 | * |
| 40 | * @return mixed |
| 41 | */ |
| 42 | public static function post( $id, $default = false, $filter = FILTER_DEFAULT, $flag = [] ) { |
| 43 | return filter_has_var( INPUT_POST, $id ) ? filter_input( INPUT_POST, $id, $filter, $flag ) : $default; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get field from request. |
| 48 | * |
| 49 | * @param string $id Field id to get. |
| 50 | * @param mixed $default Default value to return if field is not found. |
| 51 | * @param int $filter The ID of the filter to apply. |
| 52 | * @param int $flag The ID of the flag to apply. |
| 53 | * |
| 54 | * @return mixed |
| 55 | */ |
| 56 | public static function request( $id, $default = false, $filter = FILTER_DEFAULT, $flag = [] ) { |
| 57 | return isset( $_REQUEST[ $id ] ) ? filter_var( $_REQUEST[ $id ], $filter, $flag ) : $default; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get field from FORM server. |
| 62 | * |
| 63 | * @param string $id Field id to get. |
| 64 | * @param mixed $default Default value to return if field is not found. |
| 65 | * @param int $filter The ID of the filter to apply. |
| 66 | * @param int $flag The ID of the flag to apply. |
| 67 | * |
| 68 | * @return mixed |
| 69 | */ |
| 70 | public static function server( $id, $default = false, $filter = FILTER_DEFAULT, $flag = [] ) { |
| 71 | return isset( $_SERVER[ $id ] ) ? filter_var( $_SERVER[ $id ], $filter, $flag ) : $default; |
| 72 | } |
| 73 | } |
| 74 |