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.
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],
// ...
];
Optional: Add this config
# config/packages/avro_case.yaml
avro_case:
use_twig: false #disable the twig extension (true by default)
<?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 }}