rmiller/caser
PHP case manipulation utility for converting and formatting strings between common naming styles (e.g., camelCase, snake_case, kebab-case, StudlyCase). Lightweight helper for normalizing identifiers and labels in applications and libraries.
caser package is a minimal, single-purpose utility for case manipulation (e.g., camelCase, snake_case, SCREAMING_SNAKE_CASE). It aligns well with Laravel’s utility-first philosophy and can be integrated as a standalone helper or service layer abstraction for consistent case transformations across the application.Str::camel(), Str::snake(), etc., but this package could offer additional formats (e.g., dot.case, kebab-case) or customizable rules not natively supported.Str::* methods may suffice for 80% of use cases. Justification for this package should focus on missing functionality (e.g., train-case, title case with custom rules).Str::*?
null, empty strings, mixed encodings)?Str::* methods?spatie/array-to-object) that bundle case utilities?composer require rmiller/caser).app()->bind('caseTransformer', function () { return new \RichardMiller\Caser(); });).kebab-case routes to snake_case DB columns).PascalCase for React components).strtolower() + str_replace()) with the package’s methods.// Before
$snakeCase = str_replace(' ', '_', strtolower($input));
// After
$snakeCase = app(\RichardMiller\Caser::class)->snake($input);
customTitleCase()).composer.json.é, ü) correctly?null, [], or false?composer require rmiller/caser
namespace App\Services;
use RichardMiller\Caser;
class CaseTransformer {
public function __construct(private Caser $caser) {}
public function toSnakeCase(string $input): string {
return $this->caser->snake($input);
}
}
camelCase fails for Mixed String, the TPM must investigate the underlying logic.if (!class_exists(\RichardMiller\Caser::class)) {
class CaserPolyfill {
public function snake(string $input): string { /* custom impl */ }
}
}
Str::* methods.Illuminate\Support\Facades\Cache::remember).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package stops being maintained | No updates, potential bugs. | Fork or switch to Laravel’s Str::* methods. |
| Undiscovered edge cases | Incorrect case transformations. | Add input validation (e.g., assert(is_string($input))). |
| Performance bottlenecks | Slow API responses. | Cache results or use native Str::* methods. |
| Laravel version incompatibility | Breaks on newer Laravel releases. | Test on CI with all supported Laravel versions. |
// API Request Transformation
$request->merge([
'user_id' => app(Caser::class)->snake($request->userId)
]);
Caser package for this transformation?").How can I help you explore Laravel packages today?