Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions system/Helpers/Array/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ final class ArrayHelper
*
* @used-by dot_array_search()
*
* @param string $index The index as dot array syntax.
* @param string $index The index as dot array syntax.
* @param array<array-key, mixed> $array
*
* @return mixed
*/
Expand Down Expand Up @@ -68,6 +69,9 @@ private static function convertToArray(string $index): array
*
* @used-by dotSearch()
*
* @param list<string> $indexes
* @param array<array-key, mixed> $array
*
* @return mixed
*/
private static function arraySearchDot(array $indexes, array $array)
Expand Down Expand Up @@ -125,6 +129,8 @@ private static function arraySearchDot(array $indexes, array $array)
* array_key_exists() with dot array syntax.
*
* If wildcard `*` is used, all items for the key after it must have the key.
*
* @param array<array-key, mixed> $array
*/
public static function dotKeyExists(string $index, array $array): bool
{
Expand Down Expand Up @@ -179,11 +185,11 @@ public static function dotKeyExists(string $index, array $array): bool
*
* @used-by array_group_by()
*
* @param array $array Data array (i.e. from query result)
* @param array $indexes Indexes to group by. Dot syntax used. Returns $array if empty
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
* @param array<array-key, mixed> $array Data array (i.e. from query result)
* @param list<string> $indexes Indexes to group by. Dot syntax used. Returns $array if empty
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
*
* @return array Result array where rows are grouped together by indexes values.
* @return array<array-key, mixed> Result array where rows are grouped together by indexes values.
*/
public static function groupBy(array $array, array $indexes, bool $includeEmpty = false): array
{
Expand All @@ -205,6 +211,12 @@ public static function groupBy(array $array, array $indexes, bool $includeEmpty
* `dot_array_search()`.
*
* @used-by groupBy()
*
* @param array<array-key, mixed> $result
* @param array<array-key, mixed> $row
* @param list<string> $indexes
*
* @return array<array-key, mixed>
*/
private static function arrayAttachIndexedValue(
array $result,
Expand Down Expand Up @@ -244,6 +256,11 @@ private static function arrayAttachIndexedValue(
/**
* Compare recursively two associative arrays and return difference as new array.
* Returns keys that exist in `$original` but not in `$compareWith`.
*
* @param array<array-key, mixed> $original
* @param array<array-key, mixed> $compareWith
*
* @return array<array-key, mixed>
*/
public static function recursiveDiff(array $original, array $compareWith): array
{
Expand Down Expand Up @@ -284,6 +301,8 @@ public static function recursiveDiff(array $original, array $compareWith): array

/**
* Recursively count all keys.
*
* @param array<array-key, mixed> $array
*/
public static function recursiveCount(array $array, int $counter = 0): int
{
Expand Down
25 changes: 14 additions & 11 deletions system/Helpers/array_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Searches an array through dot syntax. Supports
* wildcard searches, like foo.*.bar
*
* @param array<array-key, mixed> $array
*
* @return mixed
*/
function dot_array_search(string $index, array $array)
Expand All @@ -32,7 +34,8 @@ function dot_array_search(string $index, array $array)
/**
* Returns the value of an element at a key in an array of uncertain depth.
*
* @param int|string $key
* @param int|string $key
* @param array<array-key, mixed> $array
*
* @return mixed
*/
Expand Down Expand Up @@ -78,9 +81,9 @@ function array_deep_search($key, array $array)
* For information on multi-level array sorting, refer to Example #3 here:
* https://www.php.net/manual/de/function.array-multisort.php
*
* @param array $array the reference of the array to be sorted
* @param array $sortColumns an associative array of columns to sort
* after and their sorting flags
* @param array<array-key, mixed> $array The reference of the array to be sorted
* @param array<string, int> $sortColumns An associative array of columns to sort
* after and their sorting flags
*/
function array_sort_by_multiple_keys(array &$array, array $sortColumns): bool
{
Expand Down Expand Up @@ -129,10 +132,10 @@ function array_sort_by_multiple_keys(array &$array, array $sortColumns): bool
/**
* Flatten a multidimensional array using dots as separators.
*
* @param iterable $array The multi-dimensional array
* @param string $id Something to initially prepend to the flattened keys
* @param iterable<array-key, mixed> $array The multi-dimensional array
* @param string $id Something to initially prepend to the flattened keys
*
* @return array The flattened array
* @return array<string, mixed> The flattened array
*/
function array_flatten_with_dots(iterable $array, string $id = ''): array
{
Expand All @@ -156,11 +159,11 @@ function array_flatten_with_dots(iterable $array, string $id = ''): array
/**
* Groups all rows by their index values. Result's depth equals number of indexes
*
* @param array $array Data array (i.e. from query result)
* @param array $indexes Indexes to group by. Dot syntax used. Returns $array if empty
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
* @param array<array-key, mixed> $array Data array (i.e. from query result)
* @param list<string> $indexes Indexes to group by. Dot syntax used. Returns $array if empty
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
*
* @return array Result array where rows are grouped together by indexes values.
* @return array<array-key, mixed> Result array where rows are grouped together by indexes values.
*/
function array_group_by(array $array, array $indexes, bool $includeEmpty = false): array
{
Expand Down
7 changes: 5 additions & 2 deletions system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
* directory will be mapped as well.
*
* @param string $sourceDir Path to source
* @param int $directoryDepth Depth of directories to traverse
* (0 = fully recursive, 1 = current dir, etc)
* @param int $directoryDepth Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
* @param bool $hidden Whether to show hidden files
*
* @return array<array-key, array<array-key, mixed>|string>
*/
function directory_map(string $sourceDir, int $directoryDepth = 0, bool $hidden = false): array
{
Expand Down Expand Up @@ -200,6 +201,8 @@ function delete_files(string $path, bool $delDir = false, bool $htdocs = false,
* @param bool|null $includePath Whether to include the path as part of the filename; false for no path, null for a relative path, true for full path
* @param bool $hidden Whether to include hidden files (files beginning with a period)
* @param bool $includeDir Whether to include directories
*
* @return list<string>
*/
function get_filenames(
string $sourceDir,
Expand Down
82 changes: 43 additions & 39 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*
* Creates the opening portion of the form.
*
* @param string $action the URI segments of the form destination
* @param array|string $attributes a key/value pair of attributes, or string representation
* @param array $hidden a key/value pair hidden data
* @param string $action The URI segments of the form destination
* @param array<string, scalar|null>|string $attributes A key/value pair of attributes, or string representation
* @param array<string, mixed> $hidden A key/value pair hidden data
*/
function form_open(string $action = '', $attributes = [], array $hidden = []): string
{
Expand Down Expand Up @@ -80,9 +80,9 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
*
* Creates the opening portion of the form, but with "multipart/form-data".
*
* @param string $action The URI segments of the form destination
* @param array|string $attributes A key/value pair of attributes, or the same as a string
* @param array $hidden A key/value pair hidden data
* @param string $action The URI segments of the form destination
* @param array<string, scalar|null>|string $attributes A key/value pair of attributes, or the same as a string
* @param array<string, mixed> $hidden A key/value pair hidden data
*/
function form_open_multipart(string $action = '', $attributes = [], array $hidden = []): string
{
Expand All @@ -103,8 +103,8 @@ function form_open_multipart(string $action = '', $attributes = [], array $hidde
* Generates hidden fields. You can pass a simple key/value string or
* an associative array with multiple values.
*
* @param array|string $name Field name or associative array to create multiple fields
* @param array|string $value Field value
* @param array<string, mixed>|string $name Field name or associative array to create multiple fields
* @param array<array-key, mixed>|string|null $value Field value
*/
function form_hidden($name, $value = '', bool $recursing = false): string
{
Expand Down Expand Up @@ -140,8 +140,8 @@ function form_hidden($name, $value = '', bool $recursing = false): string
* Text Input Field. If 'type' is passed in the $type field, it will be
* used as the input type, for making 'email', 'phone', etc input fields.
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_input($data = '', string $value = '', $extra = '', string $type = 'text'): string
{
Expand All @@ -161,8 +161,8 @@ function form_input($data = '', string $value = '', $extra = '', string $type =
*
* Identical to the input function but adds the "password" type
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_password($data = '', string $value = '', $extra = ''): string
{
Expand All @@ -181,8 +181,8 @@ function form_password($data = '', string $value = '', $extra = ''): string
*
* Identical to the input function but adds the "file" type
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_upload($data = '', string $value = '', $extra = ''): string
{
Expand All @@ -205,8 +205,8 @@ function form_upload($data = '', string $value = '', $extra = ''): string
/**
* Textarea field
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_textarea($data = '', string $value = '', $extra = ''): string
{
Expand Down Expand Up @@ -241,8 +241,10 @@ function form_textarea($data = '', string $value = '', $extra = ''): string
/**
* Multi-select menu
*
* @param array|string $name
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, mixed>|string $name
* @param array<array-key, array<array-key, string>|string> $options
* @param array<array-key, int|string> $selected
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_multiselect($name = '', array $options = [], array $selected = [], $extra = ''): string
{
Expand All @@ -260,10 +262,10 @@ function form_multiselect($name = '', array $options = [], array $selected = [],
/**
* Drop-down Menu
*
* @param array|string $data
* @param array|string $options
* @param array|string $selected
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, mixed>|string $data
* @param array<array-key, array<array-key, string>|string>|string $options
* @param array<array-key, int|string>|string $selected
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_dropdown($data = '', $options = [], $selected = [], $extra = ''): string
{
Expand Down Expand Up @@ -348,8 +350,8 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''):
/**
* Checkbox Field
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_checkbox($data = '', string $value = '', bool $checked = false, $extra = ''): string
{
Expand Down Expand Up @@ -381,8 +383,8 @@ function form_checkbox($data = '', string $value = '', bool $checked = false, $e
/**
* Radio Button
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_radio($data = '', string $value = '', bool $checked = false, $extra = ''): string
{
Expand All @@ -399,8 +401,8 @@ function form_radio($data = '', string $value = '', bool $checked = false, $extr
/**
* Submit Button
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_submit($data = '', string $value = '', $extra = ''): string
{
Expand All @@ -412,8 +414,8 @@ function form_submit($data = '', string $value = '', $extra = ''): string
/**
* Reset Button
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_reset($data = '', string $value = '', $extra = ''): string
{
Expand All @@ -425,8 +427,8 @@ function form_reset($data = '', string $value = '', $extra = ''): string
/**
* Form Button
*
* @param array|string $data
* @param array|object|string $extra string, array, object that can be cast to array
* @param array<string, scalar|null>|string $data
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
*/
function form_button($data = '', string $content = '', $extra = ''): string
{
Expand All @@ -450,9 +452,9 @@ function form_button($data = '', string $content = '', $extra = ''): string
/**
* Form Label Tag
*
* @param string $labelText The text to appear onscreen
* @param string $id The id the label applies to
* @param array $attributes Additional attributes
* @param string $labelText The text to appear onscreen
* @param string $id The id the label applies to
* @param array<string, scalar|null> $attributes Additional attributes
*/
function form_label(string $labelText = '', string $id = '', array $attributes = []): string
{
Expand All @@ -477,6 +479,8 @@ function form_label(string $labelText = '', string $id = '', array $attributes =
* The <datalist> element specifies a list of pre-defined options for an <input> element.
* Users will see a drop-down list of pre-defined options as they input data.
* The list attribute of the <input> element, must refer to the id attribute of the <datalist> element.
*
* @param list<string> $options
*/
function form_datalist(string $name, string $value, array $options): string
{
Expand Down Expand Up @@ -506,8 +510,8 @@ function form_datalist(string $name, string $value, array $options): string
* Used to produce <fieldset><legend>text</legend>. To close fieldset
* use form_fieldset_close()
*
* @param string $legendText The legend text
* @param array $attributes Additional attributes
* @param string $legendText The legend text
* @param array<string, scalar|null> $attributes Additional attributes
*/
function form_fieldset(string $legendText = '', array $attributes = []): string
{
Expand Down Expand Up @@ -770,8 +774,8 @@ function validation_show_error(string $field, string $template = 'single'): stri
*
* @internal
*
* @param array|string $attributes List of attributes
* @param array $default Default values
* @param array<string, scalar|null>|string $attributes List of attributes
* @param array<string, scalar|null> $default Default values
*/
function parse_form_attributes($attributes, array $default): string
{
Expand Down
Loading
Loading