Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Conversation

marek-pietrzak-tg
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #11977
License MIT
Doc PR symfony/symfony-docs#6186

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.

{
$computedLength = $length - strlen($suffix);

if ($computedLength > strlen($message)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

mb_strlen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 thanks

Copy link
Contributor

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().

Copy link
Contributor Author

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()

@jakzal jakzal added the Console label Nov 24, 2015
@marek-pietrzak-tg
Copy link
Contributor Author

Travis build fails on PHP5.3: https://travis-ci.org/symfony/symfony/jobs/92963577#L2268
Result of the test suggests substr has been used instead of mb_substr. Is php5.3 on travis running with --enable-mbstring config option?

What should I do in that case?

@marek-pietrzak-tg
Copy link
Contributor Author

If that's a bigger issue, I can propose a pull request to the 3.0 branch instead, which doesn't support php 5.3.

@jakzal
Copy link
Contributor

jakzal commented Dec 11, 2015

@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.

@marek-pietrzak-tg
Copy link
Contributor Author

👍 thanks @jakzal - will make a separate pr then and close this one

@jakzal
Copy link
Contributor

jakzal commented Dec 11, 2015

I was trying to say you don't need a new one :)

@marek-pietrzak-tg
Copy link
Contributor Author

Sorry, missed your post scriptum, I will leave it as is then

@xabbuh
Copy link
Member

xabbuh commented Dec 15, 2015

Looks good to me but we need to check why the tests are falling.

return $message;
}

return mb_substr($message, 0, $length).$suffix;
Copy link
Member

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).

@nicolas-grekas
Copy link
Member

Failures on 5.3 can be ignored: this PR will be merged on master, which require 5.5

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

Thank you @mheki.

@fabpot fabpot closed this Jan 25, 2016
fabpot added a commit that referenced this pull request Jan 25, 2016
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
xabbuh added a commit to symfony/symfony-docs that referenced this pull request Feb 7, 2016
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
@fabpot fabpot mentioned this pull request May 13, 2016
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.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.