REGEX_DELIMITER
regex delimiter that can be used in combination with functions by this helper file
public
string
REGEX_DELIMITER
= '/'
regex delimiter that can be used in combination with functions by this helper file
public
string
REGEX_DELIMITER
= '/'
function to translate format string to regex to retrieve entry values
format2regex(string $format[, string|null $match = null ][, bool $fullMatch = false ]) : string
sscanf
should be sufficient in most situations – but especially if the
format string doesn't contain spaces after conversion specifications, it
fails. Especially that's the case with LDAP DN definitions, which is why
this function was coded.
Usage could be e.g.
<?php
$rGroups = [
'DN' => [ 0 ],
'uid' => [ 1 ],
'dc1' => [ 2 ],
'dc2' => [ 3 ],
'dc3' => [ 4 ],
];
$dnFormat = 'uid=%s,ou=people,dc=%s,dc=%s,dc=%s';
$regex = format2regex( $dnFormat, null, true );
$mappings = getRegexOccurences( $regex, 'uid=jdoe,ou=people,dc=compartment,dc=example,dc=com', $rGroups );
echo( json_encode( $mappings, JSON_PRETTY_PRINT ) );
// [
// {
// "full": "uid=jdoe,ou=people,dc=compartment,dc=example,dc=com",
// "length": 51,
// "offset": 0,
// "DN": "uid=jdoe,ou=people,dc=compartment,dc=example,dc=com",
// "uid": "jdoe",
// "dc1": "compartment",
// "dc2": "example",
// "dc3": "com"
// }
// ]
format string to be analyzed
RegEx string to replace format parts – defaults to (.*?)
set true for a full match
RegEx to be used further
helper function to quote regular delimiter / in RegEx String
delimiter_preg_quote(string $string[, string|null $delimiter = null ]) : string
string to be quoted
delimiter to be used for quoting – defaults to null
to use REGEX_DELIMITER defined by this helper file
quoted string
function to fetch RegEx occurences from string / template
getRegexOccurences(mixed $regex, string $template[, mixed $group_attributes = null ]) : array<string|int, mixed>
the template string
fetch additional group elements and put it into key;
if value is [ 'name' => [ 1,2,3 ] ]
, the tool will return
the first non-empty group out of 1, 2 or 3
function to retrieve a specific value out of a given (nested) array by dot-joined following keys.
getArrayValue(array<string|int, mixed> $array, string $dotted_key[, mixed $default = NULL ][, bool $returnKeyTree = False ]) : mixed
array to be searched
dot-joined key-tree to retrieve the value
default value if key-tree not found; defaults to NULL
if set True
, the return value is an array
with two values: keyTree
and value
.
NULL
if default has to be returned .
extended function `getArrayValue`: will remove value (and key) from array if found
extractArrayValue(array<string|int, mixed> &$array, string $dotted_key[, mixed $default = NULL ]) : mixed
array to be searched
dot-joined key-tree to retrieve the value
default value if key-tree not found; defaults to NULL
function to remove a value specified by the key-tree from an array
rmValueByKeyTree(array<string|int, mixed> &$array[, array<string|int, mixed> $keytree = [] ]) : void
array, the value should be removed from
ordered list of array keys
function to generate a random string of a given length
randomString([int $length = 16 ][, mixed $alphabets = NULL ]) : string
length, the string should have
default is NULL
, so the random string will
consist out of 0-9a-f
; if of String
type,
the random string will be generated out of all
characters of that string; if it is a List /
Array of strings, the randomized string will –
as length is at least as high as the count of
given alphabents – contain at least one char
out of all those alphabets.
random string
Gets the value of an environment variable. Supports boolean, empty and null.
env(string $key[, mixed $default = NULL ]) : mixed
Will override existing env
function if environmental variable MACWINNIE_ENV
is true
.
helper function for env function to translate (string) values into boolean values, empty string or null
val2boolEmptyNull(string $value) : mixed
value to be transformed
transformed value
Remove a directory and all its content
rm_recursive(string $path) : bool
directory path
true
on success, false
on error
trim value if is a string
trimIfString(mixed $var[, string $chars = NULL ]) : mixed
value to be trimmed if string
defaults to NULL
so default of trim
function is used
trimmed string if string was given – or untouched value
helper function for chunking strings by a bunch of separator characters
chunkString(string $value[, string $chars = ' ' ][, string $normalizeLocale = 'de_DE' ]) : array<string|int, mixed>
string to be chunked
characters to chunk by, defaults to space
defaults to de_DE
– have a look on to iconv
list of chunks of string
Invert the camelCase or PascalCase of a string into its parts. Case of words will not be changed!
decamelize(string $camel[, mixed|string $delimiterImplode = ' ' ]) : array<string|int, mixed>|string
the camelCase / PascalCase to be split
defaults to a normal space
– if set to NULL
,
the list of elements, the given string consists of,
will be returned instead of a imploded string.
if $delimiterImplode
is set to NULL
, an array of strings
is returned – if the value of $delimiterImplode
allows to
implode the string parts of the camelCase / PascalCase
string, that imploded string is returned.
function to camleize a string
camelize(string $value[, string $chars = ' ' ][, bool $keepCamel = False ][, string $normalizeLocale = 'de_DE' ]) : string
camelCase is a naming convention in which the first letter of each word in a compound word is capitalized, except for the first word.
to convert to camelCase
string containing all characters, to separate the string at
keep camels – defaults to false
defaults to de_DE
– have a look on to iconv
documentation since that is relevant for
translating umlauts like Ä
into AE
...
function to turn a string into PascalCase
pascalize(string $value[, string $chars = ' ' ][, bool $keepCamel = False ][, string $normalizeLocale = 'de_DE' ]) : string
PascalCase is a naming convention in which the first letter of every word in a compound word is capitalized. The first letter is the only thing different to camelCase.
to convert to PascalCase
string containing all characters, to separate the string at
keep camels – defaults to false
defaults to de_DE
– have a look on to iconv
documentation since that is relevant for
translating umlauts like Ä
into AE
...
snakify a string
snakify(string $value[, string $chars = ' ' ][, string $normalizeLocale = 'de_DE' ]) : string
to convert to snake_case
string containing all characters, to separate the string at
defaults to de_DE
– have a look on to iconv
documentation since that is relevant for
translating umlauts like Ä
into AE
...
function to convert a boolean string to real boolean
str2bool(string $check[, mixed $trueStrings = ['1'] ]) : bool
string to be checked
the converted value – true
or false
function to check if a string begins with string sequence
startsWith(string $haystack, string $needle[, bool $trim = false ]) : bool|string
the haystack to search in
the string to search for in $haystack
defaults to false
By default, the boolean check result value
will be returned.
If $trim
is set true
, the trimmed string
will be returned.
function to check if a string ends with string sequence
endsWith(string $haystack, string $needle[, bool $trim = false ]) : bool|string
the haystack to search in
the string to search for in $haystack
defaults to false
By default, the boolean check result value
will be returned.
If $trim
is set true
, the trimmed string
will be returned.
recursive in_array function
in_array_recursive(mixed $needle, array<string|int, mixed> $haystack[, bool $strict = false ]) : bool
element to be searched within $haystack
haystack to be searched in
if set true, a strict check by ===
is performed
instead of the simple check ==
value found or not
Basic functionality like `compact` function – but based on an object
compactWith(mixed $object, mixed ...$properties) : array<string|int, mixed>
The object, the properties will be fetched from
Properties to be fetched
Associative array of property names to property values