misatotremor / case-bundle
Symfony Case Converter Bundle
v1.2.0
2024-05-05 19:14 UTC
Requires
- php: ^7.4 || ^8.0
- twig/twig: ^2.14 || ^3.0
Requires (Dev)
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/phpunit-bridge: ^5.4 || ^6.0 || ^7.0
Conflicts
- twig/twig: <2.14.7 || >=3.0 <3.3.3
Replaces
README
将字符串或数组中的字符串转换为不同的格式。
支持:camelCase、PascalCase、Title Case 和 underscore_case。
这是jdewits 原始代码 的分支。
安装
此包在packagist上有列表。
下载包
$ composer require misatotremor/case-bundle
启用包
<?php // config/bundles.php return [ // ... Avro\CaseBundle\AvroCaseBundle::class => ['all' => true], // ... ];
配置
可选: 添加此配置
# 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); } }
如果使用Twig,以下过滤器也可用:
{{ var | camel }} {{ var | pascal }} {{ var | title }} {{ var | underscore }}