Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Case Converter Laravel Package

jawira/case-converter

Convert strings between common case styles (camelCase, snake_case, kebab-case, PascalCase, etc.) with a simple PHP API. Handy for slugs, variable naming, and text normalization, supporting robust Unicode-aware conversions and formatting options.

View on GitHub
Deep Wiki
Context7

Using the factory

Besides \Jawira\CaseConverter\Convert you also have at your disposal:

  • \Jawira\CaseConverter\CaseConverter
  • \Jawira\CaseConverter\CaseConverterInterface

Instead of using new Convert(); you can use the convenience method from CaseConverter class.

In concrete, you have to call \Jawira\CaseConverter\CaseConverter::convert to create Convert objects.

Here an example:

<?php
namespace App;

use Jawira\CaseConverter\CaseConverterInterface;

class MySuperNameCreator
{
    protected $cc;

    public function __construct(CaseConverterInterface $cc)
    {
        $this->cc = $cc;
    }

    public function variableName(string $slug): string
    {
        // `->convert()` returns a `Convert` object.
        $myConvert = $this->cc->convert($slug);
        return $myConvert->toCamel();
    }

    public function constantName(string $slug): string
    {
        // Of course you can also chain everything.
        return $this->cc->convert($slug)->fromKebab()->toMacro();
    }
}

Please note that an interface -CaseConverterInterface- is also provided. If you are using Symfony you can use this interface with Symfony autowiring to automatically instantiate CaseConverter, otherwise if you are working in a standalone project you should try php-di project.

Using \Jawira\CaseConverter\CaseConverter::convert is preferred because:

  • Usually the new operator is considered harmful.
  • You can easily mock dependencies when writing tests.
  • It's SOLID
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests