Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

[String] Add support for kebab case #48781

wants to merge 1 commit into from

Conversation

seb-jean
Copy link
Contributor

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #48780
License MIT
Doc PR n/a

I add suport for kebab case for String Component.

@@ -214,6 +214,14 @@ public function join(array $strings, string $lastGlue = null): static
return $str;
}

public function kebab(): static
{
$str = $this->camel();
Copy link
Contributor

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

Copy link
Member

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?

Copy link
Contributor Author

@seb-jean seb-jean Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

Copy link
Contributor

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;
Copy link
Member

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.

@seb-jean seb-jean closed this by deleting the head repository Jan 25, 2023
fabpot added a commit that referenced this pull request Sep 30, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[String] Add kebab() to methods to change case
6 participants