Skip to content

Commit 4742bf2

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.8
2 parents 10ea628 + 9031536 commit 4742bf2

25 files changed

Lines changed: 736 additions & 173 deletions

‎.github/workflows/deploy-distributables.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
persist-credentials: false
173173

174174
- name: Setup Python
175-
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
175+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
176176
with:
177177
python-version: '3.12'
178178

‎.github/workflows/deploy-userguide-latest.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
coverage: none
3737

3838
- name: Setup Python
39-
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
39+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
4040
with:
4141
python-version: '3.12'
4242

‎.github/workflows/test-userguide.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
php-version: '8.2'
3333

3434
- name: Setup Python
35-
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
35+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
3636
with:
3737
python-version: '3.12'
3838

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"phpunit/phpcov": "^9.0.2 || ^10.0",
3030
"phpunit/phpunit": "^10.5.16 || ^11.2",
3131
"predis/predis": "^3.0",
32-
"rector/rector": "2.7.0",
32+
"rector/rector": "2.8.1",
3333
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
3434
},
3535
"replace": {

‎rector.php‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
use Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeRector;
4040
use Rector\TypeDeclaration\Rector\Function_\AddFunctionVoidReturnTypeWhereNoReturnRector;
4141
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
42-
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
4342
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector;
4443
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
4544
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
@@ -111,15 +110,6 @@
111110
__DIR__ . '/tests/_support/Entity/CustomUser.php',
112111
],
113112

114-
DeclareStrictTypesRector::class => [
115-
__DIR__ . '/app',
116-
__DIR__ . '/system/CodeIgniter.php',
117-
__DIR__ . '/system/Config/BaseConfig.php',
118-
__DIR__ . '/system/Test/ControllerTestTrait.php',
119-
__DIR__ . '/system/View/Parser.php',
120-
__DIR__ . '/tests/system/Debug/ExceptionsTest.php',
121-
],
122-
123113
DeclareStrictTypesTestsRector::class => [
124114
__DIR__ . '/tests/system/Debug/ExceptionsTest.php',
125115
],
@@ -176,7 +166,6 @@
176166
// auto import fully qualified class names
177167
->withImportNames()
178168
->withRules([
179-
DeclareStrictTypesRector::class,
180169
UnderscoreToCamelCaseVariableNameRector::class,
181170
PassStrictParameterToFunctionParameterRector::class,
182171
RemoveErrorSuppressInTryCatchStmtsRector::class,

‎system/CLI/Exceptions/CLIException.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
use CodeIgniter\Exceptions\DebugTraceableTrait;
1717
use CodeIgniter\Exceptions\RuntimeException;
1818

19-
/**
20-
* CLIException
21-
*/
2219
class CLIException extends RuntimeException
2320
{
2421
use DebugTraceableTrait;
@@ -33,4 +30,12 @@ public static function forInvalidColor(string $type, string $color)
3330
{
3431
return new static(lang('CLI.invalidColor', [$type, $color]));
3532
}
33+
34+
/**
35+
* Thrown when a prompt must ask again but the input has ended.
36+
*/
37+
public static function forInputEnded(): static
38+
{
39+
return new static(lang('CLI.inputEnded'));
40+
}
3641
}

‎system/CLI/InputOutput.php‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class InputOutput
2323
*/
2424
private readonly bool $readlineSupport;
2525

26+
private bool $atEnd = false;
27+
2628
public function __construct()
2729
{
2830
// Readline is an extension for PHP that makes interactivity with PHP
@@ -51,7 +53,8 @@ public function input(?string $prefix = null): string
5153
self::fwrite(STDOUT, $prefix ?? '');
5254
}
5355

54-
$input = readline($prompt);
56+
$input = readline($prompt);
57+
$this->atEnd = $input === false && (! defined('STDIN') || ! stream_isatty(STDIN));
5558

5659
return $input === false ? '' : $input;
5760
// @codeCoverageIgnoreEnd
@@ -60,7 +63,9 @@ public function input(?string $prefix = null): string
6063
// self:: skips MockInputOutput's fwrite override, whose filter bookkeeping must not nest inside input().
6164
self::fwrite(STDOUT, $prefix ?? '');
6265

63-
$input = fgets(fopen('php://stdin', 'rb'));
66+
$stdin = fopen('php://stdin', 'rb');
67+
$input = fgets($stdin);
68+
$this->atEnd = $input === false && ! stream_isatty($stdin);
6469

6570
if ($input === false) {
6671
return '';
@@ -69,6 +74,16 @@ public function input(?string $prefix = null): string
6974
return $input;
7075
}
7176

77+
/**
78+
* Whether the last `input()` found the end of an input other than a terminal,
79+
* so that no later read can bring an answer. At a terminal, `Ctrl+D` ends only
80+
* the current read, and `input()` returns an empty string as for an empty line.
81+
*/
82+
public function isAtEnd(): bool
83+
{
84+
return $this->atEnd;
85+
}
86+
7287
/**
7388
* While the library is intended for use on CLI commands,
7489
* commands can be called from controllers and elsewhere

‎system/CLI/Prompt.php‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CodeIgniter\CLI;
1515

16+
use CodeIgniter\CLI\Exceptions\CLIException;
1617
use CodeIgniter\Exceptions\InvalidArgumentException;
1718
use CodeIgniter\Validation\ValidationInterface;
1819

@@ -60,14 +61,20 @@ public function ask(string $field, array|string|null $options = null, array|stri
6061
// The reader renders the prompt itself, so readline redraws repaint it instead of erasing it.
6162
$prompt = sprintf('%s%s%s: ', $field, trim($field) !== '' ? ' ' : '', $hint);
6263

63-
do {
64+
while (true) {
6465
$this->output->setCursorAtLineStart(true);
6566

6667
$input = trim($this->output->getInputOutput()->input($prompt));
6768
$input = $input === '' ? $default : $input;
68-
} while ($rules !== [] && ! $this->validate(sprintf('"%s"', trim($field)), $input, $rules));
6969

70-
return $input;
70+
if ($rules === [] || $this->validate(sprintf('"%s"', trim($field)), $input, $rules)) {
71+
return $input;
72+
}
73+
74+
if ($this->output->getInputOutput()->isAtEnd()) {
75+
throw CLIException::forInputEnded();
76+
}
77+
}
7178
}
7279

7380
/**
@@ -140,6 +147,11 @@ public function askByMultipleKeys(string $text, array $options): array
140147
}
141148

142149
$this->output->error('Please select correctly.');
150+
151+
if ($this->output->getInputOutput()->isAtEnd()) {
152+
throw CLIException::forInputEnded();
153+
}
154+
143155
$this->output->newLine();
144156
}
145157
}

0 commit comments

Comments
 (0)