Completed
Branch dev (71673f)
by
unknown
05:17
created

getAttributes()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Admin Page Framework
4
 * 
5
 * http://en.michaeluno.jp/admin-page-framework/
6
 * Copyright (c) 2013-2016 Michael Uno; Licensed MIT
7
 * 
8
 */
9
10
/**
11
 * Put deprecated utility methods together.
12
 *
13
 * @since       3.5.3
14
 * @package     AdminPageFramework
15
 * @subpackage  Utility
16
 * @internal
17
 * @deprecated
18
 */
19
abstract class AdminPageFramework_Utility_Deprecated {
20
    
21
    /**
22
     * @deprecated     3.7.10      Use `getCSSMinified()` instead.
23
     * @since          3.8.8       Moved from `AdminPageFramework_Utility_String`.
24
     */
25
    static public function minifyCSS( $sCSSRules ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
26
        AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getCSSMinified()' );
27
        return AdminPageFramework_Utility_String::getCSSMinified( $sCSSRules );
28
    }    
29
    
30
    /**
31
     * @deprecated  3.8.0       Use `getLengthSanitized()` instead.
32
     * @since       3.8.8       Moved from `AdminPageFramework_Utility_String`.
33
     */
34
    static public function sanitizeLength( $sLength, $sUnit='px' ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
35
        AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getLengthSanitized()' );
36
        return AdminPageFramework_Utility_String::getLengthSanitized( $sLength, $sUnit );
37
    }    
38
    
39
    /**
40
     * Retrieves a corresponding array value from the given array.
41
     * 
42
     * When there are multiple arrays and they have similar index structures but it's not certain if one has the key and the others,
43
     * use this method to retrieve the corresponding key value. 
44
     * 
45
     * @remark      This is mainly used by the field array to insert user-defined key values.
46
     * @return      string|array    If the key does not exist in the passed array, it will return the default. If the subject value is not an array, it will return the subject value itself.
47
     * @since       2.0.0
48
     * @since       2.1.3           Added the $bBlankToDefault parameter that sets the default value if the subject value is empty.
49
     * @since       2.1.5           Changed the scope to public static from protected as converting all the utility methods to all public static.
50
     * @since       3.5.3           Moved from `AdminPageFramework_Utility_Array`.
51
     * @deprecated  3.5.3           Use `getElement()`. 
52
     */
53
    public static function getCorrespondingArrayValue( $vSubject, $sKey, $sDefault='', $bBlankToDefault=false ) {    
54
                
55
        AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getElement()' );
56
                
57
        // If $vSubject is null,
58
        if ( ! isset( $vSubject ) ) { 
59
            return $sDefault; 
60
        }
61
            
62
        // If the $bBlankToDefault flag is set and the subject value is a blank string, return the default value.
63
        if ( $bBlankToDefault && $vSubject == '' ) { 
64
            return  $sDefault; 
65
        }
66
            
67
        // If $vSubject is not an array, 
68
        if ( ! is_array( $vSubject ) ) { 
69
            return ( string ) $vSubject; 
70
        } // consider it as string.
71
        
72
        // Consider $vSubject as array.
73
        if ( isset( $vSubject[ $sKey ] ) ) { 
74
            return $vSubject[ $sKey ]; 
75
        }
76
        
77
        return $sDefault;
78
        
79
    }    
80
    
81
    /**
82
     * Check if the given array is an associative array.
83
     * 
84
     * @since       3.0.0
85
     * @since       3.5.3           Moved from `AdminPageFramework_Utility_Array`.
86
     */
87
    static public function isAssociativeArray( array $aArray ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
88
        AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__ );
89
        return ( bool ) count( array_filter( array_keys( $aArray ), 'is_string' ) );
90
    }        
91
        
92
    /**
93
     * Finds the dimension depth of the given array.
94
     * 
95
     * @since       2.0.0
96
     * @since       3.5.3           Moved from `AdminPageFramework_Utility_Array`.
97
     * @remark      There is a limitation that this only checks the first element so if the second or other elements have deeper dimensions, it will not be caught.
98
     * @param       array           $array     the subject array to check.
99
     * @return      integer         returns the number of dimensions of the array.
100
     * @deprecated  3.5.3
101
     */
102
    public static function getArrayDimension( $array ) {
103
        AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__ );
104
        return ( is_array( reset( $array ) ) ) 
105
            ? self::getArrayDimension( reset( $array ) ) + 1 
0 ignored issues
show
Deprecated Code introduced by
The method AdminPageFramework_Utili...ed::getArrayDimension() has been deprecated with message: 3.5.3

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
106
            : 1;
107
    }    
108
    
109
    /**
110
     * Returns the element value of the given field element.
111
     * 
112
     * When there are multiple input/select tags in one field such as for the radio and checkbox input type, 
113
     * the framework user can specify the key to apply the element value. In this case, this method will be used.
114
     * 
115
     * @since       3.0.0
116
     * @since       3.5.3       Moved from `AdminPageFramework_FieldType_Base`.
117
     * @deprecated  3.5.3       Use the `getElement()` method.
118
     */
119
    protected function getFieldElementByKey( $asElement, $sKey, $asDefault='' ) {
120
        
121
        AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getElement()' );
122
        
123
        if ( ! is_array( $asElement ) || ! isset( $sKey ) ) {
124
            return $asElement; 
125
        }
126
                
127
        $aElements = &$asElement; // it is an array
128
        return isset( $aElements[ $sKey ] )
129
            ? $aElements[ $sKey ]
130
            : $asDefault;
131
        
132
    }        
133
    
134
    /**
135
     * Shift array elements until it gets an element that yields true and re-index with numeric keys.
136
     * 
137
     * @since       3.0.1
138
     * @since       3.5.3       Moved from `AdminPageFramework_Utility_Array`.
139
     * @deprecated  3.5.3       This was used to sanitise dimensional key arrays but it does not seem to necessary.
140
     * @return      array
141
     */
142
    static public function shiftTillTrue( array $aArray ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
143
        
144
        AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__ );
145
        
146
        foreach( $aArray as &$vElem ) {
147
            
148
            if ( $vElem ) { break; }
149
            unset( $vElem );
150
            
151
        }
152
        return array_values( $aArray );
153
        
154
    }    
155
    
156
    /**
157
     * Generates a string of attributes to be embedded in an HTML tag from an associative array.
158
     * 
159
     * For example, 
160
     * <code>
161
     *     array( 'id' => 'my_id', 'name' => 'my_name', 'style' => 'background-color:#fff' )
162
     * </code>
163
     * becomes
164
     * <code>
165
     *     id="my_id" name="my_name" style="background-color:#fff"
166
     * </code>
167
     * 
168
     * This is mostly used by methods to output input fields.
169
     * 
170
     * @since       3.0.0
171
     * @since       3.3.0       Made it allow empty value.
172
     * @since       3.5.3       Deprecated. Moved from `AdminPageFramework_Utility`.
173
     * @return      string
174
     * @deprecated      Use getAttributes() in `AdminPageFramework_WPUtility`.
175
     */
176
    static public function getAttributes( array $aAttributes ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
177
        
178
        AdminPageFramework_Utility::showDeprecationNotice( __METHOD__, 'AdminPageFramework_WPUtility::getAttributes()' );
179
        
180
        $_sQuoteCharactor   ="'";
181
        $_aOutput           = array();
182
        foreach( $aAttributes as $sAttribute => $sProperty ) {
183
       
184
            // Must be resolved as a string.
185
            if ( in_array( gettype( $sProperty ), array( 'array', 'object' ) ) ) {
186
                continue;
187
            }
188
            $_aOutput[] = "{$sAttribute}={$_sQuoteCharactor}{$sProperty}{$_sQuoteCharactor}";
189
            
190
        }
191
        return implode( ' ', $_aOutput );
192
        
193
    }       
194
    
195
}
196