Skip to content

Commit ec299b0

Browse files
authored
feature: explain how to stop the server (#63)
* feature: explain how to stop the server closes phpgt/Server#9 * build: remove dev repo * build: php 8.2 compatibility * tweak: suppress phpstan bug
1 parent c4a5d8c commit ec299b0

3 files changed

Lines changed: 104 additions & 58 deletions

File tree

composer.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"require": {
99
"php": ">=8.2",
1010
"phpgt/cli": "^1.3",
11-
"phpgt/server": "^1.1",
11+
"phpgt/server": "dev-master as v1.2.3",
1212
"phpgt/cron": "^1.0",
1313
"phpgt/database": "^1.6",
1414
"phpgt/build": "^1.0"
@@ -30,6 +30,17 @@
3030
}
3131
},
3232

33+
"scripts": {
34+
"phpstan": "vendor/bin/phpstan analyse --level 6 src --memory-limit 256M",
35+
"phpcs": "vendor/bin/phpcs src --standard=phpcs.xml",
36+
"phpmd": "vendor/bin/phpmd src/ text phpmd.xml",
37+
"test": [
38+
"@phpstan",
39+
"@phpcs",
40+
"@phpmd"
41+
]
42+
},
43+
3344
"funding": [
3445
{
3546
"type": "github",

composer.lock

Lines changed: 69 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Command/RunCommand.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Gt\Cli\Stream;
88
use Gt\Daemon\Pool;
99
use Gt\Daemon\Process;
10+
use Gt\GtCommand\UI\Egg\RandomStartingMessage;
1011

1112
class RunCommand extends Command {
1213
/**
@@ -40,7 +41,7 @@ public function run(?ArgumentValueList $arguments = null):void {
4041
$processList["build"] = new Process($argv[0], "build", "--watch");
4142
}
4243

43-
if(!$arguments->contains("no-cron")) {
44+
if(!$arguments->contains("no-cron") && is_file("crontab")) {
4445
$processList["cron"] = new Process($argv[0], "cron", "--watch");
4546
}
4647

@@ -64,20 +65,38 @@ public function run(?ArgumentValueList $arguments = null):void {
6465
$localUrl .= ":$portValue";
6566
}
6667

67-
usleep(100_000);
68+
$this->write("Starting WebEngine...");
69+
usleep(500_000);
6870
if($processList["serve"]->isRunning()) {
69-
$this->writeLine("To view your application in your "
71+
$this->writeLine("");
72+
usleep(500_000);
73+
$this->writeLine();
74+
$this->writeLine("To view your application in your"
7075
. " browser, visit: $localUrl");
7176
$this->writeLine("To stop running, press [CTRL]+[C].");
7277
$this->writeLine();
78+
usleep(500_000);
79+
}
80+
else {
81+
$this->writeLine("");
82+
$this->write($processList["serve"]->getOutput(Process::PIPE_ERROR), Stream::ERROR);
83+
return;
7384
}
7485

86+
$this->write($processList["serve"]->getOutput());
87+
$this->write($processList["serve"]->getOutput(Process::PIPE_ERROR), Stream::ERROR);
88+
7589
do {
7690
$this->write($pool->read());
7791
$this->write($pool->read(Process::PIPE_ERROR), Stream::ERROR);
7892
usleep(100_000);
93+
/** @var bool $isRunning
94+
* @noinspection PhpRedundantVariableDocTypeInspection
95+
* This is necessary to suppress "Do-while loop condition is always true" error from phpstan. Bug with stan?
96+
*/
97+
$isRunning = $processList["serve"]->isRunning();
7998
}
80-
while($processList["serve"]->isRunning());
99+
while($isRunning);
81100
$this->writeLine("The server process has ended.");
82101
}
83102

0 commit comments

Comments
 (0)