1 | <?php |
||
2 | /** |
||
3 | * Admin Page Framework |
||
4 | * |
||
5 | * http://admin-page-framework.michaeluno.jp/ |
||
6 | * Copyright (c) 2013-2022, Michael Uno; Licensed MIT |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | /** |
||
11 | * Provides utility methods dealing with variable types which do not use WordPress functions. |
||
12 | * |
||
13 | * @since 3.6.3 |
||
14 | * @package AdminPageFramework/Utility |
||
15 | * @internal |
||
16 | */ |
||
17 | abstract class AdminPageFramework_Utility_VariableType extends AdminPageFramework_Utility_Deprecated { |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
18 | |||
19 | /** |
||
20 | * Checks if the passed string is a url or path. |
||
21 | * |
||
22 | * This is used to check if an asset file can be used or not. |
||
23 | * |
||
24 | * @since 3.6.3 |
||
25 | * @return boolean |
||
26 | */ |
||
27 | static public function isResourcePath( $sPathOrURL ) { |
||
28 | |||
29 | // PHP_MAXPATHLEN is available since PHP 5.3. |
||
30 | if ( defined( 'PHP_MAXPATHLEN' ) && strlen( $sPathOrURL ) > PHP_MAXPATHLEN ) { |
||
31 | // At this point, the variable is not a file path. |
||
32 | return ( boolean ) filter_var( $sPathOrURL, FILTER_VALIDATE_URL ); |
||
33 | } |
||
34 | |||
35 | if ( file_exists( $sPathOrURL ) ) { |
||
36 | return true; |
||
37 | } |
||
38 | return ( boolean ) filter_var( $sPathOrURL, FILTER_VALIDATE_URL ); |
||
39 | |||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Checks if the given value is not null. |
||
44 | * |
||
45 | * This is mainly used for the callback function of the `array_filter()` function. |
||
46 | * |
||
47 | * @since 3.6.3 |
||
48 | * @return boolean If the passed value is not null, true; otherwise, false. |
||
49 | */ |
||
50 | static public function isNotNull( $mValue=null ) { |
||
51 | return ! is_null( $mValue ); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Checks whether the given value is numeric and can be resolved as an integer. |
||
56 | * |
||
57 | * Saves one conditional statement. |
||
58 | * Used to determine sub-sections and sub-fields elements. |
||
59 | * |
||
60 | * <code> |
||
61 | * var_dump( is_int( '0' ) ); // false |
||
62 | * var_dump( isNumericInteger( '0' ) ); // true |
||
63 | * var_dump( is_int( '' + 0 ) ); // true |
||
64 | * var_dump( isNumericInteger( '' ) ); // false |
||
65 | * </code> |
||
66 | * |
||
67 | * @since 3.5.3 |
||
68 | * @since 3.6.3 Moved from `AdminPageFramework_Utility`. |
||
69 | * @return boolean |
||
70 | */ |
||
71 | static public function isNumericInteger( $mValue ) { |
||
72 | return is_numeric( $mValue ) && is_int( $mValue + 0 ); |
||
73 | } |
||
74 | |||
75 | |||
76 | } |
||
77 |