php-standard-library/str
Lightweight string utility library for PHP, providing common helpers for formatting, parsing, and safe string handling. Designed as a simple “standard library” add-on with a small API surface and easy composer integration.
mb_* functions in validation logic or domain services—without disrupting existing Laravel utilities like Str::of() or Illuminate\Support\Stringable.mb_* functions are often underutilized or inconsistently applied. This package enforces Unicode-aware operations by default, reducing edge-case bugs in internationalized applications.Str::of($input)->trim()->slug()), enabling cleaner, more maintainable string transformations in middleware, form requests, or business logic.PhpStandardLibrary\Str namespace is distinct from Laravel’s Str facade.Str helper, allowing gradual migration (e.g., replace mb_strtolower() with Str::lower() in legacy code).$this->partialMock(Str::class, 'slug')->shouldReturn('mocked-slug');
Str::trim() vs. trim()), with ~5–10% improvement in Unicode-aware operations (e.g., Str::ascii()).Str behavior (e.g., Str::of(null)->value() returns null). Document this explicitly in team guidelines.Str::title() may not match ICU (International Components for Unicode) standards. Validate against symfony/intl if strict localization is required.Str for simple ops (e.g., str_replace()).mb_substr()).Str::of()->trim()->slug()) vs. native alternatives.Str facade entirely, or complement it (e.g., for advanced Unicode ops)?Str::of()->slug() for simple cases, but php-standard-library/str for Str::ascii() or Str::plural().Str::slug() in a StringServiceProvider.pestphp/pest-plugin-expect) for edge cases.Str::of("Café")->slug() → "cafe" (Unicode preservation).null coalescing, empty string handling) that could cause runtime issues?README.md section in your repo with Laravel-specific examples.mb_strtolower() in FormRequest rules:
'email' => ['required', Rule::unique('users')->ignore($this)->where('email', Str::lower($this->email))],
Str::of($userInput)->trim()->slug()->prepend('user-')->value();
return response()->json(['key' => Str::kebab($model->name)]);
{{ Str::title($post->title) }}
| Phase | Task | Tools/Dependencies | Laravel-Specific Notes |
|---|---|---|---|
| Assessment | Benchmark 5–10 critical string ops against Laravel’s Str and native PHP. |
Blackfire, Laravel Debugbar | Focus on Unicode-heavy ops (e.g., Str::ascii()). |
| Pilot | Replace mb_* functions in a single module (e.g., AuthServiceProvider). |
PHPStan, Pest | Use phpstan/extension-installer to detect mb_* calls. |
| Standardize | Enforce package usage via PSR-12 rules and PHPStan. | PHP-CS-Fixer, phpstan.neon |
Add rule: disallow_mb_functions: true. |
| Refactor | Replace repetitive logic in controllers, middleware, or form requests. | Laravel IDE Helper | Example: Replace str_replace() with Str::replace(). |
| Monitor | Track memory/CPU usage in production (e.g., Str::slug() in bulk API responses). |
Laravel Telescope, New Relic | Set up alerts for >100ms latency in string ops. |
PhpStandardLibrary\Str) prevents collisions with Laravel’s Str or third-party packages like symfony/string.Str::slug($title) in boot()).mb_* functions in FormRequest validation rules.Str::lower() in Rule::unique() checks.UserService::formatName()).Str::kebab() for API keys).{{ strtolower($var) }} → {{ Str::lower($var) }}).mb_* calls in old modules.^6.2) in composer.json to avoid surprises.7.x series (if released).composer.json to require PHP 8.1+.PhpStandardLibrary\Str calls, aiding issue resolution.How can I help you explore Laravel packages today?