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.
Str helper without introducing framework lock-in. It can be adopted incrementally (e.g., for validation, API responses, or domain-specific string logic) without disrupting existing workflows.mb_* functions or ASCII-only assumptions. This is particularly valuable for internationalization (i18n) or multilingual applications where consistent Unicode handling is non-negotiable.Str::of()->method()->value()) integrates seamlessly with Laravel’s service containers and pipeline pattern (e.g., app()->make(Str::class)), enabling reusable string-processing pipelines in middleware or form requests.Stringable trait or Str::of() helper.PhpStandardLibrary\Str) ensure zero conflicts with Laravel’s ecosystem or other Composer packages. No configuration or service provider registration is required.app('Str')) for consistency with existing Str:: usage.Str::limit() or Str::excerpt() can be directly used in Blade templates without additional setup.FormRequest validation with custom rules (e.g., Str::isAscii()) via extends or traits.mb_* functions (e.g., mb_strtolower() → Str::lower()) and Laravel’s Str helper for Unicode-aware operations.null handling, locale-specific rules).Str helper for critical paths (e.g., bulk slug generation). Expect negligible overhead for most use cases, but validate with tools like Blackfire or Laravel Debugbar.Str::of()->trim()->slug()->upper()) may create temporary strings. Test with large payloads (e.g., 10KB+ strings).Str::title() or Str::plural() may not handle all Unicode locales (e.g., Turkish dotted ‘i’). Validate against CLDR data or Laravel’s Locale service.e() or htmlspecialchars() as needed.null/empty inputs (e.g., Str::of(null)->slug() should return null or throw an exception).PhpStandardLibrary\Str methods.Str helper entirely, or only for Unicode-specific operations (e.g., Str::ascii() vs. Str::lower())?Stringable trait (e.g., Str::of($string)->method() vs. $string->method())?StrServiceProvider or facade) to standardize usage?Str::of() mocking)?null handling, empty strings, or locale-specific quirks) that could cause runtime issues?Str::slug() in a FormRequest")?Str::ascii())?mb_* function usage, fewer string-related bugs)?trim()/strtolower() in FormRequest or Validator rules (e.g., Str::lower($request->input('email'))).Str::slug() for SEO URLs, Str::title() for display names).Str::kebab() for API keys, Str::limit() for excerpts).@php echo Str::limit($post->content, 100) @endphp).Str::trim() for headers, Str::ascii() for sanitization).| Phase | Task | Tools/Dependencies | Laravel-Specific Considerations |
|---|---|---|---|
| Assessment | Benchmark against Laravel’s Str helper for critical paths (e.g., slug generation). |
Blackfire, Laravel Debugbar | Compare Str::slug() vs. Str::of()->slug()->value(). |
| Pilot | Replace 3–5 repetitive string ops in a low-risk module (e.g., user input trimming). | PHPStan, Pest | Use Str::of() for fluent chaining in controllers. |
| Validation | Test Unicode edge cases (e.g., emojis, combining characters, RTL text). | Laravel Dusk (for UI strings), Pest | Validate with Str::ascii(), Str::lower(), etc. |
| Standardization | Enforce usage via PSR-12 rules (e.g., ban mb_strtolower() in favor of Str::lower()). |
PHP-CS-Fixer | Add custom rules to php-cs-fixer.dist.php. |
| Facade Wrap | (Optional) Create a Laravel facade for consistency (e.g., app('Str')). |
Laravel Facade Generator | Extend Illuminate\Support\Facades\Facade. |
| Documentation | Add internal docs for Laravel-specific use cases (e.g., "Using Str::slug() in Routes"). |
Markdown, Confluence | Include examples for FormRequest, Middleware, etc. |
How can I help you explore Laravel packages today?