4 changed files with 92 additions and 58 deletions
@ -0,0 +1,42 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace RouterOS\Helpers; |
||||
|
|
||||
|
/** |
||||
|
* Class ArrayHelper |
||||
|
* |
||||
|
* @package RouterOS\Helpers |
||||
|
* @since 0.7 |
||||
|
*/ |
||||
|
class ArrayHelper |
||||
|
{ |
||||
|
/** |
||||
|
* Check if required keys in array |
||||
|
* |
||||
|
* @param array $keys |
||||
|
* @param array $array |
||||
|
* @return string|bool Return true if all fine, and string with name of key which was not found |
||||
|
*/ |
||||
|
public static function checkIfKeysNotExist(array $keys, array $array) |
||||
|
{ |
||||
|
$output = []; |
||||
|
foreach ($keys as $key) { |
||||
|
if (!array_key_exists($key, $array) && isset($array[$key])) { |
||||
|
$output[] = $key; |
||||
|
} |
||||
|
} |
||||
|
return !empty($output) ? implode(',', $output) : true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Check if key in list of parameters |
||||
|
* |
||||
|
* @param string $key |
||||
|
* @param array $array |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public static function checkIfKeyNotExist(string $key, array $array): bool |
||||
|
{ |
||||
|
return (!array_key_exists($key, $array)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace RouterOS\Helpers; |
||||
|
|
||||
|
/** |
||||
|
* Class TypeHelper |
||||
|
* |
||||
|
* @package RouterOS\Helpers |
||||
|
* @since 0.7 |
||||
|
*/ |
||||
|
class TypeHelper |
||||
|
{ |
||||
|
/** |
||||
|
* Compare data types of some value |
||||
|
* |
||||
|
* @param string $name Name of value |
||||
|
* @param mixed $whatType What type has value |
||||
|
* @param mixed $isType What type should be |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public static function checkIfTypeMismatch(string $name, $whatType, $isType): bool |
||||
|
{ |
||||
|
return ($whatType !== $isType); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue