| 1 | <?php |
||
| 21 | abstract class AdminPageFramework_Utility_ArraySetter extends AdminPageFramework_Utility_ArrayGetter { |
||
|
1 ignored issue
–
show
|
|||
| 22 | |||
| 23 | /** |
||
| 24 | * Calculates the subtraction of two values with the array key of `order`. |
||
| 25 | * |
||
| 26 | * This is used to sort arrays. |
||
| 27 | * |
||
| 28 | * @since 2.0.0 |
||
| 29 | * @since 3.0.0 Moved from the property class. |
||
| 30 | * @since 3.3.1 Moved from `AdminPageFramework_Base`. |
||
| 31 | * @since 3.6.0 Moved from `AdminPageFramework_Router`. |
||
| 32 | * @since DVVER Moved from `AdminPageFramework_Utility`. |
||
| 33 | * @remark a callback method for `uasort()`. |
||
| 34 | * @return integer |
||
| 35 | * @internal |
||
| 36 | */ |
||
| 37 | static public function sortArrayByKey( $a, $b, $sKey='order' ) { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Unsets an element of a multi-dimensional array by given keys. |
||
| 45 | * |
||
| 46 | * <code> |
||
| 47 | * $a = array( |
||
| 48 | * 'a' => array( |
||
| 49 | * 'b' => array( |
||
| 50 | * 'c' => array( |
||
| 51 | * 'd' => array( |
||
| 52 | * 'e' => 'eee', |
||
| 53 | * ), |
||
| 54 | * ), |
||
| 55 | * ), |
||
| 56 | * ), |
||
| 57 | * ); |
||
| 58 | * $aKeys = array( 'a', 'b', 'c' ); |
||
| 59 | * unsetDimensionalArrayElement( $a, $aKeys ); |
||
| 60 | * var_dump( $a ); |
||
| 61 | * </code> |
||
| 62 | * Will produce |
||
| 63 | * <code> |
||
| 64 | * array( |
||
| 65 | * 'a' => array( |
||
| 66 | * 'b' => array( |
||
| 67 | * ) |
||
| 68 | * ) |
||
| 69 | * ) |
||
| 70 | * </code> |
||
| 71 | * |
||
| 72 | * @remark Introduced for resetting options with dimensional keys. |
||
| 73 | * @since 3.5.3 |
||
| 74 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 75 | * @return void |
||
| 76 | */ |
||
| 77 | static public function unsetDimensionalArrayElement( &$mSubject, array $aKeys ) { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Sets a dimensional array value by dimensional array key path. |
||
| 94 | * @since 3.5.3 |
||
| 95 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 96 | * @return void |
||
| 97 | */ |
||
| 98 | static public function setMultiDimensionalArray( &$mSubject, array $aKeys, $mValue ) { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Reconstructs the given array by numerizing the keys. |
||
| 115 | * |
||
| 116 | * @since 3.0.0 |
||
| 117 | * @since 3.5.3 Added a type hint in the first parameter. |
||
| 118 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 119 | * @return array The passed array structure looks like this. |
||
| 120 | * <code> |
||
| 121 | * array( |
||
| 122 | * 0 => array( |
||
| 123 | * 'field_id_1' => array( ... ), |
||
| 124 | * 'field_id_2' => array( ... ), |
||
| 125 | * ), |
||
| 126 | * 1 => array( |
||
| 127 | * 'field_id_1' => array( ... ), |
||
| 128 | * 'field_id_2' => array( ... ), |
||
| 129 | * ), |
||
| 130 | * 'field_id_1' => array( ... ), |
||
| 131 | * 'field_id_2' => array( ... ), |
||
| 132 | * ) |
||
| 133 | * </code> |
||
| 134 | * It will be converted to to |
||
| 135 | * <code> |
||
| 136 | * array( |
||
| 137 | * 0 => array( |
||
| 138 | * 'field_id_1' => array( ... ), |
||
| 139 | * 'field_id_2' => array( ... ), |
||
| 140 | * ), |
||
| 141 | * 1 => array( |
||
| 142 | * 'field_id_1' => array( ... ), |
||
| 143 | * 'field_id_2' => array( ... ), |
||
| 144 | * ), |
||
| 145 | * 2 => array( |
||
| 146 | * 'field_id_1' => array( ... ), |
||
| 147 | * 'field_id_2' => array( ... ), |
||
| 148 | * ), |
||
| 149 | * ) |
||
| 150 | * </code> |
||
| 151 | */ |
||
| 152 | static public function numerizeElements( array $aSubject ) { |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Casts array contents into another while keeping the same key structure. |
||
| 168 | * |
||
| 169 | * @since 3.0.0 |
||
| 170 | * @since 3.5.3 Added type hints to the parameter. |
||
| 171 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 172 | * @remark It does not check key structure deeper than or equal to the second dimension. |
||
| 173 | * @remark If a key exists in the passed model array but does not exists in the subject array, |
||
| 174 | * a `null` value will be assigned to the resulting array. |
||
| 175 | * @param array $aModel the array that holds the necessary keys. |
||
| 176 | * @param array $aSubject the array from which the contents to be extracted. |
||
| 177 | * @return array the extracted array contents with the keys of the model array. |
||
| 178 | */ |
||
| 179 | public static function castArrayContents( array $aModel, array $aSubject ) { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Returns an array consisting of keys which don't exist in the other. |
||
| 195 | * |
||
| 196 | * @since 3.0.0 |
||
| 197 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 198 | * @remark It won't check key structure deeper than or equal to the second dimension. |
||
| 199 | * @param array $aModel the array that holds the necessary keys. |
||
| 200 | * @param array $aSubject the array from which the contents to be extracted. |
||
| 201 | * @return array the extracted array contents with the keys that do not exist in the model array. |
||
| 202 | */ |
||
| 203 | public static function invertCastArrayContents( array $aModel, array $aSubject ) { |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Merges multiple multi-dimensional arrays recursively. |
||
| 218 | * |
||
| 219 | * The advantage of using this method over the array unite operator or `array_merge() is |
||
| 220 | * that it merges recursively and the null values of the preceding array will be overridden. |
||
| 221 | * |
||
| 222 | * @since 2.1.2 |
||
| 223 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 224 | * @static |
||
| 225 | * @access public |
||
| 226 | * @remark The parameters are variadic and can add arrays as many as necessary. |
||
| 227 | * @return array the united array. |
||
| 228 | */ |
||
| 229 | public static function uniteArrays( /* $aPrecedence, $aArray1, $aArray2, ... */ ) { |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Merges two multi-dimensional arrays recursively. |
||
| 244 | * |
||
| 245 | * The first parameter array takes its precedence. This is useful to merge default option values. |
||
| 246 | * An alternative to `array_replace_recursive()` which is not available PHP 5.2.x or below. |
||
| 247 | * |
||
| 248 | * @since 2.0.0 |
||
| 249 | * @since 2.1.5 Changed the visibility scope to `static`. |
||
| 250 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 251 | * @access public |
||
| 252 | * @remark null values will be overwritten. |
||
| 253 | * @param array the array that overrides the same keys. |
||
| 254 | * @param array the array that is going to be overridden. |
||
| 255 | * @return array the united array. |
||
| 256 | */ |
||
| 257 | public static function uniteArraysRecursive( $aPrecedence, $aDefault ) { |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Removes array elements by the specified type. |
||
| 286 | * |
||
| 287 | * @since 3.3.1 |
||
| 288 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 289 | * @param array $aArray The subject array to parse. |
||
| 290 | * @param array $aTypes The value types to drop. The supported types are the followings. |
||
| 291 | * - boolean |
||
| 292 | * - integer |
||
| 293 | * - double |
||
| 294 | * - string |
||
| 295 | * - array |
||
| 296 | * - object |
||
| 297 | * - resource |
||
| 298 | * - NULL |
||
| 299 | * @return array The modified array. |
||
| 300 | */ |
||
| 301 | static public function dropElementsByType( array $aArray, $aTypes=array( 'array' ) ) { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Removes an array element(s) by the given value. |
||
| 313 | * @since 3.4.0 |
||
| 314 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 315 | * @return array The modified array. |
||
| 316 | */ |
||
| 317 | static public function dropElementByValue( array $aArray, $vValue ) { |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Removes given keys from the array. |
||
| 332 | * |
||
| 333 | * This is used to drop unnecessary keys for a multidimensional array as multidimensinal arrays can cause PHP warnings used with `array_diff()`. |
||
| 334 | * |
||
| 335 | * @since 3.4.6 |
||
| 336 | * @since DVVER Moved from `AdminPageFramework_Utility_Array`. |
||
| 337 | * @return array The modified array. |
||
| 338 | */ |
||
| 339 | static public function dropElementsByKey( array $aArray, $asKeys ) { |
||
| 347 | |||
| 348 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.