- How do I install nekland/tools in a Laravel project?
- Run `composer require nekland/tools` in your project root. The package is dependency-free and integrates seamlessly with Laravel’s autoloader via PSR-4. No additional configuration is needed for basic usage.
- Can I use StringTools instead of Laravel’s Str helper?
- Yes, but with caveats. StringTools offers additional features like `mb_ucfirst` and `removeStart/End`, while Laravel’s Str helper is optimized for framework-specific tasks. Use StringTools for extended string manipulation or portability across non-Laravel projects.
- Will TemporaryFile work in Laravel’s testing environment?
- Absolutely. TemporaryFile and TemporaryDirectory are ideal for Laravel tests, especially for isolated file operations like uploads or cache simulations. They auto-cleanup, reducing flakiness in PHPUnit or PestPHP tests. Pair with Laravel’s `RefreshDatabase` traits for full isolation.
- Does nekland/tools support PHP 8.x features like named arguments?
- Yes, the package is fully compatible with PHP 8.x. While some methods (e.g., `StringTools::camelize`) use optional arguments, they don’t rely on PHP 8.x-specific syntax. Tested with Laravel’s PHP 8.x requirements.
- How does DateTimeComparator handle edge cases like invalid inputs?
- DateTimeComparator expects `DateTimeInterface` objects. Passing invalid types may cause unexpected behavior. Mitigate this by wrapping calls in Laravel services with type hints or input validation before comparison.
- Is there a performance penalty for using ArrayTools vs. Laravel’s collect()?
- For large arrays, Laravel’s `collect()` may outperform `ArrayTools::removeValue`. Benchmark critical paths in your application. Use ArrayTools for lightweight, dependency-free operations or smaller datasets.
- Can I integrate TemporaryDirectory with Laravel’s Storage facade?
- Not natively, but you can extend the package. Create a Laravel-specific wrapper (e.g., `StorageTemporaryDirectory`) that uses the Storage facade for disk-specific temp paths. This avoids filesystem permission issues in shared hosting.
- What’s the best way to handle the camelize normalization breaking change in v2.6.0?
- Override the default behavior by passing `$normalize = false` to `StringTools::camelize`. For consistency, wrap the utility in a Laravel service layer to abstract the change from your application code.
- Are there alternatives to nekland/tools for Laravel-specific helpers?
- Laravel’s built-in helpers (e.g., `Str`, `Arr`) cover core needs, but nekland/tools fills gaps like multibyte string operations or temporary resource management. For framework-agnostic utilities, consider `spatie/array` or `php-http/message` for HTTP-specific tasks.
- How can I contribute or fork this package for Laravel-specific features?
- Fork the repository and extend classes (e.g., add `Storage` facade integration to `TemporaryFile`). Submit a pull request to Nekland or maintain your fork. Document Laravel-specific examples in the README to help others adopt your changes.