-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[console] Add truncate method to FormatterHelper #16652
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
[console] Add truncate method to FormatterHelper #16652
Conversation
{ | ||
$computedLength = $length - strlen($suffix); | ||
|
||
if ($computedLength > strlen($message)) { |
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.
mb_strlen
?
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.
👍 thanks
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.
Actually, there's the Helper::strlen()
, so it would be better to call $this->strlen()
.
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.
thanks @jakzal, changed to $this->strlen()
Travis build fails on PHP5.3: https://travis-ci.org/symfony/symfony/jobs/92963577#L2268 What should I do in that case? |
If that's a bigger issue, I can propose a pull request to the |
@mheki as a new feature, this should go to master (3.1) P.S. don't worry about it though. Even though you submitted it to 2.8, it can still be merged to another branch by a merger. |
👍 thanks @jakzal - will make a separate pr then and close this one |
I was trying to say you don't need a new one :) |
Sorry, missed your post scriptum, I will leave it as is then |
Looks good to me but we need to check why the tests are falling. |
return $message; | ||
} | ||
|
||
return mb_substr($message, 0, $length).$suffix; |
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 $charset attribute is missing, which makes this function reliant on a global config option. Other places in this component use mb_detect_encoding($string, null, true)
.
Failures on 5.3 can be ignored: this PR will be merged on master, which require 5.5 |
Thank you @mheki. |
This PR was submitted for the 2.8 branch but it was merged into the 3.1-dev branch instead (closes #16652). Discussion ---------- [console] Add truncate method to FormatterHelper | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11977 | License | MIT | Doc PR | - This PR adds a `truncate` method to `FormatterHelper`. Message is truncated to the given length, then the suffix is appended to end of that string. If the length is negative, number of letters to truncate is counted from the end of the message. Suffix is always appended, unless truncate length is longer than message and suffix length. Commits ------- a16b1a0 [console] Add truncate method to FormatterHelper
This PR was squashed before being merged into the master branch (closes #6186). Discussion ---------- [Console] Add FormatterHelper::truncate docs | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#16652) | Applies to | 3.1 | Fixed tickets | - Commits ------- 60548b1 [Console] Add FormatterHelper::truncate docs
This PR adds a
truncate
method toFormatterHelper
.Message is truncated to the given length, then the suffix is appended to end of that string.
If the length is negative, number of letters to truncate is counted from the end of the message.
Suffix is always appended, unless truncate length is longer than message and suffix length.