diff options
author | PiBa-NL <PiBa.NL.dev@gmail.com> | 2018-08-21 01:15:47 +0200 |
---|---|---|
committer | PiBa-NL <PiBa.NL.dev@gmail.com> | 2018-08-21 01:15:47 +0200 |
commit | a436447f4c353344eb5539642f59ce8a4a01843e (patch) | |
tree | dd333fe6b773b4a085c5c216373a25aed1599694 | |
parent | a34bab9f4b93091e147bcae18b79e6349c60496c (diff) | |
download | pfsense-a436447f4c353344eb5539642f59ce8a4a01843e.zip pfsense-a436447f4c353344eb5539642f59ce8a4a01843e.tar.gz |
add getarraybyref() utility function for general use (used also to avoid php7 'Cannot create references to/from string offsets' messages)
-rw-r--r-- | src/etc/inc/pfsense-utils.inc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index ea09d2d..7099d60 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -3386,4 +3386,36 @@ function addrtolower($ip) { function compare_by_name($a, $b) { return strcasecmp($a['name'], $b['name']); } + +/****f* pfsense-utils/getarraybyref + * NAME + * getarraybyref + * INPUTS + * $array the array of which a items array needs to be found. + * $args.. the sub-items to be retrieved/created + * RESULT + * returns the array that was retrieved from configuration, its created if it does not exist + * NOTES + * Used by haproxy / acme / others.?. . + * can be used like this: $a_certificates = getarraybyref($config, 'installedpackages', 'acme', 'certificates', 'item'); + ******/ +function &getarraybyref(&$array) { + if (!isset($array)) { + return false; + } + if (!is_array($array)) { + $array = array(); + } + $item = &$array; + $arg = func_get_args(); + for($i = 1; $i < count($arg); $i++) { + $itemindex = $arg[$i]; + if (!is_array($item[$itemindex])) { + $item[$itemindex] = array(); + } + $item = &$item[$itemindex]; + } + return $item; +} + ?> |