-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[String] Add support for kebab case #48781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -214,6 +214,14 @@ public function join(array $strings, string $lastGlue = null): static | |||
return $str; | |||
} | |||
|
|||
public function kebab(): static | |||
{ | |||
$str = $this->camel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camel()->lower()->replace('_', '-')
Is not enough? Just asking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case, maybe we don't need yet another method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snake()
function uses the same process:
https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/String/AbstractUnicodeString.php#L349
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camel()->lower()->replace('_', '-')
Is not enough? Just asking
Your example does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it's snake()->replace('_', '-')
, I think.
@@ -390,6 +390,8 @@ public function jsonSerialize(): string | |||
return $this->string; | |||
} | |||
|
|||
abstract public function kebab(): static; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AbstractString
is not @internal
, so this is a BC-break, I believe.
…xandre-daubois) This PR was merged into the 7.2 branch. Discussion ---------- [String] Add the `AbstractString::kebab()` method | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #48780 | License | MIT Supersedes #48781. It seems there's quite a demand for this feature. I think it is a nice DX improvement which also helps readability over calling `snake()->replace('_', '-')`. Commits ------- b2b82d6 [String] Add the `AbstractString::kebab()` method
I add suport for kebab case for String Component.