Skip to content
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

[5.5] Sync Str with Stringy 3.0.1 #18974

Merged
merged 7 commits into from
Apr 28, 2017
Merged

[5.5] Sync Str with Stringy 3.0.1 #18974

merged 7 commits into from
Apr 28, 2017

Conversation

fernandobandeira
Copy link
Contributor

@fernandobandeira fernandobandeira commented Apr 27, 2017

This PR intends to sync our core Str class with the behavior provided by Stringy library.

There's a few things that we should consider:

@ was removed from the library so it no longers changes to at, the library manually changes @ to - when generating the slug, I kept the previous behavior and moved it to the slug function, this way we can override the array in the future without caring about this and we also don't change the current behavior.

The library now uses locale's to replace characters according to the specific language. This also fixes some issues we had in the past of incorrect behavior, for example:

ü previously was being replaced by ue now it is replaced by u and is replaced by ue just when using the de locale.

{
$languageSpecific = static::languageSpecificCharsArray($language);

if ($languageSpecific !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

!is_null() seems more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed 👍

@taylorotwell taylorotwell merged commit 6a2b893 into laravel:master Apr 28, 2017
@iwex
Copy link
Contributor

iwex commented Apr 28, 2017

@taylorotwell it's WIP, and lacks of additional actions like https://github.com/danielstjules/Stringy/blob/master/src/Stringy.php#L1863

@fernandobandeira
Copy link
Contributor Author

fernandobandeira commented Apr 28, 2017

@iwex I've done that I just simplified the function https://github.com/laravel/framework/pull/18974/files#diff-d19e1b0b8c742f268aabdbf1595bcfbdR614

The behavior is the same $charsArray is a local static variable with all languages that are loaded, it contains the languages that were used before and add's new entries to the array whenever you use a new one, i removed this since there's just one language it would be overkill right now...

You might have confused it with the other $charsArray variable that contains all characters...

Edit

The only reason i set the flag to WIP actually was to see if som1 could come up with an approach to get the locale directly from the config instead of passing it as a parameter, however I think we can't do that...

@fernandobandeira fernandobandeira deleted the patch-2 branch April 28, 2017 13:30
@iwex
Copy link
Contributor

iwex commented Apr 28, 2017

@fernandobandeira thanks for explanation :) Stringy has really messy method

@tillkruss tillkruss changed the title [5.5][WIP] Sync Str with Stringy 3.0.1 [5.5] Sync Str with Stringy 3.0.1 Apr 28, 2017
*
* Note: Adapted from Stringy\Stringy.
*
* @see https://github.com/danielstjules/Stringy/blob/3.0.1/LICENSE.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this link to the licence intentional, or should this link to the source file?

Copy link
Contributor Author

@fernandobandeira fernandobandeira Apr 28, 2017

Choose a reason for hiding this comment

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

I copied it from the other method that graham created, I guess it's intentional to show that we can freely use this code on our project. But we could also link to the source file...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants