Skip to content

Commit

Permalink
implement
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Jan 6, 2024
1 parent bb181b2 commit d92dfde
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Yii Strings Change Log

## 2.4.1 under development
## 3.0.0 under development

- no changes in this release.
- Chg #112: Change default value of `$strict` parameter in `Inflector::toSnakeCase()` to `false` (@vjik)

## 2.4.0 December 22, 2023

Expand Down
13 changes: 12 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ In a big application however there may be more things to consider, which are exp
> Note: The following upgrading instructions are cumulative. That is, if you want to upgrade from a version A to version
> C and there is a version B between A and C, you need to follow the instructions for both A and B.
## Upgrade from 1.2.0
## Upgrade from 2.x to 3.x

Default value of `$strict` parameter in `Inflector::toSnakeCase()` changed to `false`. To keep previous behaviour add
`strict: true` to call methods `Inflector::toSnakeCase()` without `strict` argument. For example:

```php
Inflector::toSnakeCase($name);
// change to
Inflector::toSnakeCase($name, true);
```

## Upgrade from 1.x to 2.x

`\Yiisoft\Strings\WildCardPattern` was changed.

Expand Down
4 changes: 2 additions & 2 deletions src/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,11 @@ public function toCamelCase(string $input): string
* so "who's online" will be converted to "who_s_online".
*
* @param string $input The word to convert.
* @param bool $strict Whether to insert a separator between two consecutive uppercase chars, defaults to true.
* @param bool $strict Whether to insert a separator between two consecutive uppercase chars, defaults to false.
*
* @return string The "snake_cased" string.
*/
public function toSnakeCase(string $input, bool $strict = true): string
public function toSnakeCase(string $input, bool $strict = false): string
{
return $this->pascalCaseToId(preg_replace('/[^\pL\pN]+/u', '_', $input), '_', $strict);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/InflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ public function dataToSnakeCase(): array
{
return [
[['input' => 'userName'], 'user_name'],
[['input' => 'travelSGuide'], 'travel_s_guide'],
[['input' => 'travelSGuide', 'strict' => true], 'travel_s_guide'],
[['input' => 'ひらがなHepimiz'], 'ひらがな_hepimiz'],
[['input' => 'Let\'s say "Hello, World!" yii 3 😂'], 'let_s_say_hello_world_yii_3'],
[['input' => 'HTML'], 'h_t_m_l'],
[['input' => 'createMyDTO'], 'create_my_d_t_o'],
[['input' => 'HTML', 'strict' => false], 'html'],
[['input' => 'createMyDTO', 'strict' => false], 'create_my_dto'],
[['input' => 'HTML', 'strict' => true], 'h_t_m_l'],
[['input' => 'createMyDTO', 'strict' => true], 'create_my_d_t_o'],
[['input' => 'HTML'], 'html'],
[['input' => 'createMyDTO'], 'create_my_dto'],
];
}

Expand Down

0 comments on commit d92dfde

Please sign in to comment.