diff --git a/CHANGELOG.md b/CHANGELOG.md index e8a47e5..7ea8f41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/UPGRADE.md b/UPGRADE.md index dddc9d8..3d9851e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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. diff --git a/src/Inflector.php b/src/Inflector.php index 521fc26..07678d0 100644 --- a/src/Inflector.php +++ b/src/Inflector.php @@ -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); } diff --git a/tests/InflectorTest.php b/tests/InflectorTest.php index d068126..68cf25b 100644 --- a/tests/InflectorTest.php +++ b/tests/InflectorTest.php @@ -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'], ]; }