misatotremor/case-bundle

Symfony Case Converter Bundle

Installs: 5 581

Dependents: 2

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 3

Type:symfony-bundle

v1.1.1 2024-04-24 22:00 UTC

README

Convert strings or strings in arrays to different case formats.

Supports: camelCase, PascalCase, Title Case, and underscore_case.

This is a fork of jdewits original code.

Installation

This bundle is listed on packagist.

Download the bundle

$ composer require misatotremor/case-bundle

Enable the bundle

<?php
// config/bundles.php

return [
    // ...
    Avro\CaseBundle\AvroCaseBundle::class => ['all' => true],
    // ...
];

Configuration

Optional: Add this config

# config/packages/avro_case.yaml
avro_case:
    use_twig: false #disable the twig extension (true by default)

Usage

<?php
use Avro\CaseBundle\Util\CaseConverter;

class SomeClass
{
    private $caseConverter;

    /**
     * @param CaseConverter $caseConverter
     */
    public function __construct(CaseConverter $caseConverter)
    {
        $this->caseConverter = $caseConverter;
    }

    /**
     * @param string $str
     */
    public function foo(string $str)
    {
        $camelCaseFormat = $this->converter->toCamelCase($str);
        $pascalCaseFormat = $this->converter->toPascalCase($str);
        $titleCaseFormat = $this->converter->toTitleCase($str);
        $underscoreCaseFormat = $this->converter->toUnderscoreCase($str);
    }
}

The following filters are also available if you use Twig

    {{ var | camel }}
    {{ var | pascal }}
    {{ var | title }}
    {{ var | underscore }}