Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Fix #4051 console::writeLine() #4055

Closed
Thinkscape wants to merge 6 commits into
zendframework:masterfrom
Thinkscape:hotfix/console-writeline
Closed

Fix #4051 console::writeLine() #4055
Thinkscape wants to merge 6 commits into
zendframework:masterfrom
Thinkscape:hotfix/console-writeline

Conversation

@Thinkscape
Copy link
Copy Markdown
Member

This fixes issue #4051

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not simply use iconv_substr() here (which is built into PHP), and get red of that if statement for mbstring?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@Thinkscape
Copy link
Copy Markdown
Member Author

@DASPRiD mbstring are 5-10x faster than iconv.

@DASPRiD
Copy link
Copy Markdown
Member

DASPRiD commented Mar 16, 2013

Then why don't you use Zend\Stdlib\StringUtils::getWrapper(), it will automatically select the available wrapper for you. This would reduce duplicate code, right?

@Thinkscape
Copy link
Copy Markdown
Member Author

When Console was created a year ago, StringUtils wasn't in place. I'll take a look. Thanks for the hint.

@Thinkscape
Copy link
Copy Markdown
Member Author

@DASPRiD done.

@Thinkscape
Copy link
Copy Markdown
Member Author

@weierophinney @DASPRiD I've got a pickle here.

The original ("ambitious") implementation of Console::writeLine() for zf2 was trying to mitigate empty lines, when the string length matched window length. This means, that doing $console->writeLine(str_repeat('#', 80)) in 80x25 console window would result in a single line of ##### and carret on the following line (while most other frameworks would produce a line of #### followed by an empty line and then the carret).

The problem is that people also use writeLine() for writing multi-line strings. This increases the complexity of the above algorithm. I'd have to check the length of the longest line (or the last line) of input before deciding to output PHP_EOL or not.

As much as I like my original idea I believe the benefits do not outweight the cost needed to work around the above problem. In case someone wanted to do $console->writeLine(file_get_contents('somehugefile.txt'); the performance penality could be severe.

I think the best option here is to remove the feature of matching input with console width and instead implement the standard writeLine implementation that 99% other frameworks provide: echo $input . PHP_EOL;.

Comments ?

@weierophinney
Copy link
Copy Markdown
Member

@Thinkscape I'm in agreement. Does that need to be done prior to merging this?

weierophinney added a commit that referenced this pull request Mar 28, 2013
weierophinney added a commit that referenced this pull request Mar 28, 2013
@ghost ghost assigned weierophinney Mar 28, 2013
weierophinney added a commit to zendframework/zend-console that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-console that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-console that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants