deozza/philarmony-utils
Utility helpers for Philarmony projects. A small collection of PHP/Laravel-oriented functions and convenience tools intended to reduce boilerplate and streamline common tasks across applications and packages.
Installation
composer require deozza/philarmony-utils
Add the service provider to config/app.php:
Deozza\PhilarmonyUtils\PhilarmonyUtilsServiceProvider::class,
First Use Case: String Manipulation The package provides utility methods for string manipulation, often used in validation or formatting.
use Deozza\PhilarmonyUtils\StringUtils;
$formatted = StringUtils::slugify('Hello World!'); // Returns 'hello-world'
Where to Look First
PhilarmonyUtils::slugify(), PhilarmonyUtils::camelCase(), etc.src/StringUtils.php for core logic.tests/Unit/StringUtilsTest.php for usage examples.String Transformation
Use StringUtils for consistent formatting across the app (e.g., slugs, camelCase, snake_case).
// In a controller or service
$title = "User Profile Settings";
$slug = StringUtils::slugify($title); // 'user-profile-settings'
Validation Helpers Combine with Laravel’s validation for reusable rules:
use Deozza\PhilarmonyUtils\ValidationUtils;
$validator = Validator::make($request->all(), [
'username' => ['required', ValidationUtils::isAlphanumericWithUnderscores()]
]);
Integration with Blade Create a custom Blade directive for global string transformations:
// In AppServiceProvider@boot()
Blade::directive('slugify', function ($expression) {
return "<?php echo Deozza\\PhilarmonyUtils\\StringUtils::slugify({$expression}); ?>";
});
Usage in Blade:
<h1>{{ slugify('My Post Title') }}</h1> <!-- Renders as 'my-post-title' -->
API Response Formatting
Normalize responses with ArrayUtils:
use Deozza\PhilarmonyUtils\ArrayUtils;
$response = [
'data' => $user->toArray(),
'meta' => ['count' => 1]
];
return response()->json(ArrayUtils::normalizeKeys($response, 'snake_case'));
PhilarmonyUtils in unit tests to isolate logic:
$this->partialMock(PhilarmonyUtils::class, ['slugify'])
->shouldReceive('slugify')
->once()
->andReturn('mocked-slug');
Namespace Conflicts
The package uses Deozza\PhilarmonyUtils—ensure no naming collisions with other Philarmony* packages.
Performance with Large Strings
Methods like slugify() use regex. For bulk operations (e.g., 1000+ strings), cache results or batch process:
$slugs = collect($titles)->map(fn($title) => cache()->remember(
"slug_{$title}",
now()->addHours(1),
fn() => StringUtils::slugify($title)
));
Locale-Specific Transformations
slugify() defaults to ASCII. For non-English apps, extend the class:
class CustomStringUtils extends StringUtils {
public static function slugify($string, $locale = 'en') {
// Add locale-specific rules (e.g., handle 'ñ' in Spanish)
}
}
\x00). Use trim() or mb_convert_encoding() pre-processing.ValidationUtils rules fail silently, enable Laravel’s validation debugging:
$validator->setAttributeNames(['username' => 'user name']);
Custom Utilities
Extend the base classes (e.g., StringUtils) and bind them in the service provider:
$this->app->singleton('custom.string.utils', function () {
return new \App\Utils\CustomStringUtils();
});
Configuration The package lacks a config file, but you can override defaults via facades:
// Set global slug separator
config(['philarmony-utils.defaults.slug_separator' => '-']);
PhilarmonyUtils::setSlugSeparator('-');
Event Listeners Hook into string transformations via events (if the package supports them). Example for future-proofing:
event(new StringTransformed($original, $transformed));
How can I help you explore Laravel packages today?