Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data & Filesystem Helpers

Introduction

Sukarix\Utils provides small, dependency-free static helpers shared by every Sukarix application, so common array/data manipulation, filesystem checks and git introspection are not reimplemented per project.

DataUtils

  • keepIntegerInArray(?array &$array): Filters an array in place, keeping only digit-string values.
  • unsetByValue(array &$array, mixed $value): Removes the first occurrence of a value from an array.
  • getArrayFromField(array $array, int|string $key): Extracts a column from a multidimensional array (array_column-like, null for missing keys).
  • toJsonArray(array $array, bool $wrapStrings = false): Joins an array into a comma-separated string, optionally quoting each value.

Application-specific data helpers should extend Sukarix\Utils\DataUtils rather than duplicating these methods.

FileSystemUtils

  • createDirectory($path) / ensureDirectoryExists(string $directory): Create a directory recursively, throwing \RuntimeException on failure.
  • isDirectoryEmpty(string $dir): Returns false for a missing/unreadable directory as well as a non-empty one.
  • scanDirectory(string $directory, string $pattern): Recursively lists files whose name ends with $pattern.

CommandExecutor

  • gitBranch() / gitVersion(): Shell out to git (via mikehaertl/php-shellcommand) to report the checked-out branch and tag/commit, typically surfaced on a diagnostics or “about” page.

Example Usage

use Sukarix\Utils\DataUtils;
use Sukarix\Utils\FileSystemUtils;
use Sukarix\Utils\CommandExecutor;

DataUtils::toJsonArray(['a', 'b'], true); // "'a','b'"

FileSystemUtils::ensureDirectoryExists($f3->get('TEMP') . 'uploads');

$version = CommandExecutor::gitVersion();