8000 [Console] SymfonyStyle : fix blocks failed when $messages is null by ogizanagi · Pull Request #14654 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] SymfonyStyle : fix blocks failed when $messages is null #14654

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

Merged
merged 1 commit into from
May 22, 2015
Merged

[Console] SymfonyStyle : fix blocks failed when $messages is null #14654

merged 1 commit into from
May 22, 2015

Conversation

ogizanagi
Copy link
Contributor
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Using SymfonyStyle:block method with null as first argument failed, where most of other methods accepting both string and array arguments will simply output an empty string.

At first I wanted to output nothing, or even throw a proper exception. But then I realized how behaves other methods like text or write.

I encountered this issue while executing a console application, in non-interactive mode, that asks questions (without default value) and prints the result immediately using a note block:

$output->note($output->choice('Choice question', array('choice 1', 'choice 2'));

screenshot 2015-05-16 a 11 42 47

@@ -63,6 +63,9 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa
$messages = array_values((array) $messages);
Copy link
Member

Choose a reason for hiding this comment

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

I suggest replacing this strange code and the patch below with:
$messages = is_array($messages) ? array_values($messages) : array($messages);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fully agree.
Changes made.

Using the `SymfonyStyle:block` method with `null` as first argument
failed, where most of other methods accepting both string and array arguments will simply output an empty string.
@aitboudad
Copy link
Contributor

👍

@jakzal
Copy link
Contributor
jakzal commented May 22, 2015

👍

@fabpot
Copy link
Member
fabpot commented May 22, 2015

Thank you @ogizanagi.

@fabpot fabpot merged commit cfd1022 into symfony:2.7 May 22, 2015
fabpot added a commit that referenced this pull request May 22, 2015
…is null (ogizanagi)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] SymfonyStyle : fix blocks failed when $messages is null

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Using `SymfonyStyle:block` method with `null` as first argument failed, where most of other methods accepting both string and array arguments will simply output an empty string.

At first I wanted to output nothing, or even throw a proper exception. But then I realized how behaves other methods like text or write.

I encountered this issue while executing a console application, in non-interactive mode, that asks questions (without default value) and prints the result immediately using a note block:
```php
$output->note($output->choice('Choice question', array('choice 1', 'choice 2'));
```
![screenshot 2015-05-16 a 11 42 47](https://cloud.githubusercontent.com/assets/2211145/7665616/ba5f343c-fbc0-11e4-811d-6b109aaa8d27.PNG)

Commits
-------

cfd1022 [Console] SymfonyStyle : fix blocks failed when $messages is null.
@ogizanagi ogizanagi deleted the sf_style_blocks_null_value branch May 22, 2015 11:56
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.

5 participants
0