Skip to content

Commit 23fd7fd

Browse files
paulbalandanclaude
andcommitted
fix: guard STDIN reference for non-CLI invocations of AbstractCommand
Page-cache tests in CodeIgniterTest exercise command() from an HTTP context where STDIN is not defined globally. Bare `STDIN` inside the CodeIgniter\CLI namespace fails to resolve in that mode. Guard with defined() and use \STDIN explicitly; a non-CLI caller cannot prompt, so the correct semantic is non-interactive. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent a754da4 commit 23fd7fd

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

system/CLI/AbstractCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,20 @@ public function hasNegation(string $name): bool
357357
* 1. An explicit `setInteractive()` call wins.
358358
* 2. Otherwise, the command is interactive when STDIN is a TTY.
359359
*
360+
* Non-CLI contexts (e.g., a controller invoking `command()`) don't expose
361+
* `STDIN` at all — those always resolve as non-interactive.
362+
*
360363
* Note: the `--no-interaction` / `-N` flag is folded into the explicit state
361364
* by `run()` before interactive hooks fire, so callers do not need to
362365
* inspect the options array themselves.
363366
*/
364367
public function isInteractive(): bool
365368
{
366-
return $this->interactive ?? CLI::streamSupports('stream_isatty', STDIN);
369+
if ($this->interactive !== null) {
370+
return $this->interactive;
371+
}
372+
373+
return defined('STDIN') && CLI::streamSupports('stream_isatty', \STDIN);
367374
}
368375

369376
/**

0 commit comments

Comments
 (0)