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

[Console] Constant STDOUT might be undefined #34344

Merged
merged 1 commit into from Nov 13, 2019

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Nov 12, 2019

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #34341
License MIT
Doc PR N/A

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

fopen('php://stdout', 'w')?

@derrabus
Copy link
Member Author

fopen('php://stdout', 'w')?

Would be overkill here. The constant is defined by the CLI SAPI. Thus, if the constant is not there, we're not on CLI, thus we're not on a terminal with VT100 support.

We already have a similar check in PhpUnitBridge:

if (!\defined('STDOUT')) {
return false;
}

@nicolas-grekas
Copy link
Member

I'm not sure I agree. If the check targets the sapi, let's make it crystal clear. Checks for color support all use php://stdout. STDOUT is not used anywhere else in the codebase as far as I checked. I think we should check what we want to check in a portable way, using php://stdout Sorry my previous comment was too laconic.

@derrabus
Copy link
Member Author

STDOUT is not used anywhere else in the codebase as far as I checked.

Well yes, the method I've linked in my previous comment uses the constant to check for color support as well.

private static function hasColorSupport()
{
if (!\defined('STDOUT')) {
return false;
}
if ('Hyper' === getenv('TERM_PROGRAM')) {
return true;
}
if (\DIRECTORY_SEPARATOR === '\\') {
return (\function_exists('sapi_windows_vt100_support')
&& sapi_windows_vt100_support(STDOUT))
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM');
}
if (\function_exists('stream_isatty')) {
return stream_isatty(STDOUT);
}
if (\function_exists('posix_isatty')) {
return posix_isatty(STDOUT);
}
$stat = fstat(STDOUT);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
}

Also, I wouldn't want to change the way stdout is accessed without a Windows machine to test on. 😕

@nicolas-grekas
Copy link
Member

That's the bridge, it's not a piece of reusability, it's a tool :)
No worries about php://stdout, it does the very same job.

@derrabus
Copy link
Member Author

All right, here you go.

@lazosweb Can you please test again? Sorry for the hassle. 😃

@lazosweb
Copy link

@derrabus . All good. No issue. That will work too.

@chalasr chalasr added this to the 3.4 milestone Nov 13, 2019
@chalasr
Copy link
Member

chalasr commented Nov 13, 2019

Should be merged after #34346 and rebased on 3.4.

@derrabus
Copy link
Member Author

Should be merged after #34346 and rebased on 3.4.

@chalasr Feel free to squash my change into your PR. I don't think, we need to backport a buggy solution first. 😉

@chalasr chalasr changed the base branch from 4.3 to 3.4 November 13, 2019 07:07
fabpot pushed a commit that referenced this pull request Nov 13, 2019
This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Constant STDOUT might be undefined

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34341
| License       | MIT
| Doc PR        | N/A

Commits
-------

bb8c82c [Console] Constant STDOUT might be undefined.
@fabpot fabpot merged commit bb8c82c into symfony:3.4 Nov 13, 2019
@nicolas-grekas
Copy link
Member

Thank you @derrabus

@fabpot fabpot mentioned this pull request Nov 13, 2019
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.

None yet

6 participants