c33s/utils
General-purpose PHP utilities for everyday development: helpers for strings, arrays, filesystem, debugging, and common convenience functions. Designed to be lightweight, easy to drop into existing projects, and useful across Laravel and plain PHP apps.
Installation Add the package via Composer:
composer require c33s/utils
No additional configuration is required—it’s a pure utility package with no service provider or facade.
First Use Case
Import the utility you need (e.g., StringUtils for string manipulation):
use C33s\Utils\StringUtils;
$result = StringUtils::slugify('Hello World!');
// Returns: 'hello-world'
Where to Look First
String Manipulation
Use StringUtils for common tasks like:
use C33s\Utils\StringUtils;
// Slugify, truncate, or format strings
StringUtils::truncate('Laravel is awesome', 10); // 'Laravel...'
StringUtils::formatBytes(1024); // '1.00 KB'
Array Operations
Leverage ArrayUtils for:
use C33s\Utils\ArrayUtils;
// Merge, diff, or flatten arrays
ArrayUtils::mergeRecursive(['a' => 1], ['a' => 2]); // ['a' => 2]
ArrayUtils::flatten([1, [2, 3]]); // [1, 2, 3]
Date/Time Handling
Use DateTimeUtils for:
use C33s\Utils\DateTimeUtils;
// Parse, format, or compare dates
DateTimeUtils::format('2023-01-01', 'Y-m-d H:i'); // '2023-01-01 00:00'
Validation Helpers
Use ValidatorUtils for reusable validation logic:
use C33s\Utils\ValidatorUtils;
ValidatorUtils::isEmail('[email protected]'); // true
Integration with Laravel
$this->app->singleton('slugify', function () {
return new StringUtils();
});
app/Helpers/utils.php:
if (!function_exists('slug')) {
function slug($string) {
return \C33s\Utils\StringUtils::slugify($string);
}
}
No Facades or Service Providers
Limited Documentation
Edge Cases in String/Array Utils
slugify() may not handle Unicode well (e.g., é → e).
Fix: Pre-process strings with mb_strtolower() or iconv().ArrayUtils::diff() may not handle nested arrays as expected.
Tip: Test with complex arrays before production use.Performance Considerations
ArrayUtils::flatten()) use recursion, which could hit stack limits for deep arrays.
Tip: Use iterative approaches for large datasets.declare(strict_types=1); to catch type mismatches early.\Log::debug('Input:', ['data' => $inputArray]);
$result = ArrayUtils::flatten($inputArray);
\Log::debug('Output:', ['result' => $result]);
Custom Utilities
Extend existing classes (e.g., StringUtils) by creating a subclass:
class CustomStringUtils extends StringUtils {
public static function customSlugify($string) {
return parent::slugify($string) . '-custom';
}
}
Add to Laravel’s app() Container
Bind utilities to the container for easier testing:
$this->app->bind('custom.utils', function () {
return new CustomStringUtils();
});
Testing Mock utilities in tests using partial mocks:
$mock = $this->partialMock(StringUtils::class, ['slugify']);
$mock->method('slugify')->willReturn('mocked-slug');
Contributing Back
FileUtils, CollectionUtils).How can I help you explore Laravel packages today?