- How does this package differ from Laravel’s Str helper for string truncation?
- While Laravel’s `Str::of()->beforeLast()` handles single-character termination, this package excels at multi-character delimiters (e.g., `['#', '--']`) or custom termination logic. Use it when you need precise control over truncation points beyond Laravel’s built-in methods.
- Can I use this package in Laravel 10.x with PHP 8.1+?
- The package officially supports PHP 7.2+ and Laravel 7.x–10.x, but PHP 8.x compatibility is unverified. Test with `@phpstan/phpstan` or fork the package to add PHP 8.1+ support via constructor property promotion checks. Start with a pinned version (e.g., `^1.0`) to mitigate risks.
- What’s the best way to handle edge cases like no terminator found?
- The package returns the original string if no terminator is found. For Laravel integrations, consider wrapping it in a validator rule or service to enforce exceptions or null conventions. Example: `TerminatedString::terminateOrFail($input, ['#'], 'Invalid format')`.
- Should I register this as a Laravel service provider or use it standalone?
- For reusable components, bind it to Laravel’s container: `$this->app->bind(TerminatedString::class, fn() => new TerminatedString($input, $terminators));`. For one-off tasks, use it directly. Avoid global state—this package is stateless and modular.
- Does this package handle Unicode/multi-byte characters correctly?
- No, it uses `strpos()` and may fail with UTF-8 strings (e.g., `
` in non-ASCII text). Test with your locale or replace `strpos()` with `mb_strpos()` in a fork. For critical Unicode use cases, consider `symfony/string` or `league/string-data` instead.
- How can I integrate this with Laravel validation?
- Extend Laravel’s validation pipeline by creating a custom rule: `php artisan make:rule TerminatedString`. In the rule, use `TerminatedString::terminate($input, $terminators)` and fail if the result doesn’t meet expectations (e.g., length constraints).
- Are there modern alternatives with better maintenance?
- Yes, consider `symfony/string` (active maintenance, Unicode support) or `league/string-data` (feature-rich). This package is lightweight but outdated (last release 2019). Fork it or switch to a maintained alternative if long-term support is critical.
- How do I test this package in a Laravel project?
- Test in isolation with PHPUnit/Pest for unit cases, then integrate into Laravel workflows (e.g., form requests, log parsers). Mock dependencies if needed. Use `composer test` to verify core functionality, then add Laravel-specific edge cases (e.g., Str helper interactions).
- Will this package work with Laravel’s Str facade?
- No, but you can create a facade wrapper for convenience. Example: `Str::terminated('value #comment', ['#'])` by publishing a facade or using a trait. Avoid tight coupling—this package is framework-agnostic.
- What should I do if I encounter a security vulnerability?
- Pin the version in `composer.json` (e.g., `webignition/disallowed-character-terminated-string:1.0.0`) and monitor for updates via `composer audit`. Since the package has no transitive security risks, focus on input validation in your Laravel app. Fork the repo if urgent patches are needed.