Skip to content

Convert strings to different case formats. Pascal, title, camel, underscore.

Notifications You must be signed in to change notification settings

MisatoTremor/AvroCaseBundle

 
 

Repository files navigation

AvroCaseBundle Build Status codecov

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 }}

About

Convert strings to different case formats. Pascal, title, camel, underscore.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%