florianwolters/component-core-stringutils
StringUtils is a lightweight PHP component providing static string helper methods for everyday tasks such as emptiness checks, trimming, case conversion, and substring handling, with predictable behavior and easy integration into any PHP project.
composer require florianwolters/component-core-stringutils
The package is a component-style port of Apache Commons Lang's StringUtils — a static utility facade over PHP's native string functions. Treat the Apache Commons Javadoc as your mental model; the method names and null-handling semantics are deliberately close.
Where to look first (in order):
composer.json — check require.php, the autoload block (PSR-4 vs classmap), and whether ext-mbstring is declared. Older component packages from this author sometimes use classmap autoloading, which affects where you can place the class in your IDE.src/ — open the main StringUtils class and skim the method list. You should see familiar names: isBlank/isNotBlank, isEmpty/isNotEmpty, join, capitalize/uncapitalize, normalizeSpace, trimToNull/trimToEmpty, contains, startsWith/endsWith, substring, split.tests/ — this is the de facto specification. With only 5 stars and no README depth, the test suite is the most reliable documentation of null/empty/whitespace semantics.First use case — replacing defensive null/blank checks in a service or form request:
use FlorianWolters\Component\Core\StringUtils\StringUtils;
// Before: if ($name === null || trim($name) === '') { ... }
if (StringUtils::isBlank($input['name'] ?? null)) {
// treat as missing
}
$csv = StringUtils::join($columns, ', ');
Before committing to it, run a one-line sanity check in php -r or a throwaway test to confirm the class autoloads and the method signature matches your PHP version.
isBlank/isNotBlank — unlike empty() or trim(), they don't blow up on null and treat whitespace-only strings as blank. Use them in FormRequest authorize/prepareForValidation and in query-builder guards.normalizeSpace → trimToNull in a request DTO is a clean way to prevent leading/trailing/double-space data from reaching the database. Wrap it in one application-level helper so it isn't scattered across controllers.StringUtils::join($ids, ',') is readable and null-tolerant, but remember it does not escape quotes — for SQL IN (...) lists you still need parameter binding.capitalize/uncapitalize are useful for display names, generating property names from table columns, or converting between class and variable naming in scaffolding.App\Support\Str class that delegates to StringUtils. That gives you one seam to swap in symfony/string or Laravel's Illuminate\Support\Str later without rewriting call sites.Blank rule is trivial:Validator::extend('not_blank', fn ($attr, $value) => StringUtils::isNotBlank($value));
trimToNull returns null or ''), pin it with a small data-provider test in your own suite. Don't rely on the upstream tests staying green — the project is dormant.composer update will be safe across a PHP major.create_function, each(), deprecated ${} interpolation, or implicit nullable parameters before rolling it out.length, substring, reverse, and case conversion are often byte-oriented (strlen, substr, strtolower). For UTF-8 user input, prefer mb_* or symfony/string. Never use this package for truncating localized text.null vs empty-string semantics. Apache-style APIs sometimes return null and sometimes '' (trimToNull vs trimToEmpty, and the defaultIfBlank/defaultIfEmpty family). Confirm in the tests before feeding results into typed properties or database columns with NOT NULL.lowerCase/upperCase may delegate to strtolower/strtoupper, which are locale-aware on some setups (Turkish dotless i). If you care, wrap with mb_strtolower($s, 'UTF-8') yourself.bin2hex($value)) — most "isBlank returned false" surprises are non-breaking spaces (\xC2\xA0) or zero-width characters that native trim and this package will not strip.composer.json uses classmap, adding the class to a namespaced app directory won't work; keep the vendor path intact and import the FQCN as documented.How can I help you explore Laravel packages today?