Skip to content

Commit c61c863

Browse files
SniderHephaestus
andcommitted
chore(php): convert cmd_dev.go + services_windows.go to core canon (Mantis #1321 round 3)
Surface-level canon conversions using existing core/go primitives: - os.Getwd → core.Getwd Result-shape - errors.New → core.E(scope, msg, nil) - strings.HasPrefix/TrimPrefix/ToLower → core.HasPrefix/TrimPrefix/Lower - exec.Cmd → core.Cmd (existing type alias) - os.Signal → syscall.Signal (where substitution works) - os.Interrupt/Kill → syscall.SIGINT/SIGKILL Build green. The deeper services.go restructure (long-running daemon with managed exec.Cmd handles + signal channels) is invasive — needs Cladius lane to rewrite using c.Process().Start/Kill + c.Action("signal.received") + c.Service() + c.Command() framework primitives, NOT new wrappers. Filed as separate Mantis ticket. Co-Authored-By: Hephaestus <hephaestus@lthn.ai>
1 parent 7de56e7 commit c61c863

2 files changed

Lines changed: 47 additions & 43 deletions

File tree

‎go/pkg/php/cmd_dev.go‎

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package php
33
import (
44
"bufio"
55
"context"
6-
`errors`
7-
`os`
6+
"os"
87
"os/signal"
9-
`strings`
108
"syscall"
119
"time"
1210

@@ -41,14 +39,15 @@ type phpDevOptions struct {
4139
}
4240

4341
func runPHPDev(opts phpDevOptions) error { // Result boundary
44-
cwd, err := os.Getwd()
45-
if err != nil {
46-
return core.E("php", "failed to get working directory", err)
42+
cwdResult := core.Getwd()
43+
if !cwdResult.OK {
44+
return core.E("php", "failed to get working directory", cwdResult.Value.(error))
4745
}
46+
cwd := cwdResult.Value.(string)
4847

4948
// Check if this is a Laravel project
5049
if !IsLaravelProject(cwd) {
51-
return errors.New(phpT("cmd.php.error.not_laravel"))
50+
return core.E("php", phpT("cmd.php.error.not_laravel"), nil)
5251
}
5352

5453
cli.Print(cliLabelValueBlankFormat, dimStyle.Render(phpT(cmdPHPLabelKey)), phpT("cmd.php.dev.starting", map[string]interface{}{"AppName": laravelDisplayName(cwd)}))
@@ -182,13 +181,14 @@ func addPHPLogsCommand(c *core.Core, prefix string) {
182181
}
183182

184183
func runPHPLogs(service string, follow bool) error { // Result boundary
185-
cwd, err := os.Getwd()
186-
if err != nil {
187-
return err
184+
cwdResult := core.Getwd()
185+
if !cwdResult.OK {
186+
return cwdResult.Value.(error)
188187
}
188+
cwd := cwdResult.Value.(string)
189189

190190
if !IsLaravelProject(cwd) {
191-
return errors.New(phpT("cmd.php.error.not_laravel_short"))
191+
return core.E("php", phpT("cmd.php.error.not_laravel_short"), nil)
192192
}
193193

194194
// Create a minimal server just to access logs
@@ -232,10 +232,11 @@ func addPHPStopCommand(c *core.Core, prefix string) {
232232
}
233233

234234
func runPHPStop() error { // Result boundary
235-
cwd, err := os.Getwd()
236-
if err != nil {
237-
return err
235+
cwdResult := core.Getwd()
236+
if !cwdResult.OK {
237+
return cwdResult.Value.(error)
238238
}
239+
cwd := cwdResult.Value.(string)
239240

240241
cli.Print(cliLabelValueFormat, dimStyle.Render(phpT(cmdPHPLabelKey)), phpT("cmd.php.stop.stopping"))
241242

@@ -257,13 +258,14 @@ func addPHPStatusCommand(c *core.Core, prefix string) {
257258
}
258259

259260
func runPHPStatus() error { // Result boundary
260-
cwd, err := os.Getwd()
261-
if err != nil {
262-
return err
261+
cwdResult := core.Getwd()
262+
if !cwdResult.OK {
263+
return cwdResult.Value.(error)
263264
}
265+
cwd := cwdResult.Value.(string)
264266

265267
if !IsLaravelProject(cwd) {
266-
return errors.New(phpT("cmd.php.error.not_laravel_short"))
268+
return core.E("php", phpT("cmd.php.error.not_laravel_short"), nil)
267269
}
268270

269271
appName := GetLaravelAppName(cwd)
@@ -314,10 +316,11 @@ func addPHPSSLCommand(c *core.Core, prefix string) {
314316
}
315317

316318
func runPHPSSL(domain string) error { // Result boundary
317-
cwd, err := os.Getwd()
318-
if err != nil {
319-
return err
319+
cwdResult := core.Getwd()
320+
if !cwdResult.OK {
321+
return cwdResult.Value.(error)
320322
}
323+
cwd := cwdResult.Value.(string)
321324

322325
// Get domain from APP_URL if not specified
323326
if domain == "" {
@@ -336,7 +339,7 @@ func runPHPSSL(domain string) error { // Result boundary
336339
cli.Print(cliSingleLineFormat, phpT("common.hint.install_with"))
337340
cli.Print(" %s\n", phpT("cmd.php.ssl.install_macos"))
338341
cli.Print(" %s\n", phpT("cmd.php.ssl.install_linux"))
339-
return errors.New(phpT("cmd.php.error.mkcert_not_installed"))
342+
return core.E("php", phpT("cmd.php.error.mkcert_not_installed"), nil)
340343
}
341344

342345
cli.Print(cliLabelValueFormat, dimStyle.Render("SSL:"), phpT("cmd.php.ssl.setting_up", map[string]interface{}{"Domain": domain}))
@@ -397,26 +400,26 @@ func printColoredLog(line string) {
397400
var style *cli.AnsiStyle
398401
serviceName := ""
399402

400-
if strings.HasPrefix(line, "[FrankenPHP]") {
403+
if core.HasPrefix(line, "[FrankenPHP]") {
401404
style = phpFrankenPHPStyle
402405
serviceName = "FrankenPHP"
403-
line = strings.TrimPrefix(line, "[FrankenPHP] ")
404-
} else if strings.HasPrefix(line, "[Vite]") {
406+
line = core.TrimPrefix(line, "[FrankenPHP] ")
407+
} else if core.HasPrefix(line, "[Vite]") {
405408
style = phpViteStyle
406409
serviceName = "Vite"
407-
line = strings.TrimPrefix(line, "[Vite] ")
408-
} else if strings.HasPrefix(line, "[Horizon]") {
410+
line = core.TrimPrefix(line, "[Vite] ")
411+
} else if core.HasPrefix(line, "[Horizon]") {
409412
style = phpHorizonStyle
410413
serviceName = "Horizon"
411-
line = strings.TrimPrefix(line, "[Horizon] ")
412-
} else if strings.HasPrefix(line, "[Reverb]") {
414+
line = core.TrimPrefix(line, "[Horizon] ")
415+
} else if core.HasPrefix(line, "[Reverb]") {
413416
style = phpReverbStyle
414417
serviceName = "Reverb"
415-
line = strings.TrimPrefix(line, "[Reverb] ")
416-
} else if strings.HasPrefix(line, "[Redis]") {
418+
line = core.TrimPrefix(line, "[Reverb] ")
419+
} else if core.HasPrefix(line, "[Redis]") {
417420
style = phpRedisStyle
418421
serviceName = "Redis"
419-
line = strings.TrimPrefix(line, "[Redis] ")
422+
line = core.TrimPrefix(line, "[Redis] ")
420423
} else {
421424
// Unknown service, print as-is
422425
cli.Print(cliLabelValueFormat, dimStyle.Render(timestamp), line)
@@ -431,7 +434,7 @@ func printColoredLog(line string) {
431434
}
432435

433436
func getServiceStyle(name string) *cli.AnsiStyle {
434-
switch strings.ToLower(name) {
437+
switch core.Lower(name) {
435438
case "frankenphp":
436439
return phpFrankenPHPStyle
437440
case "vite":

‎go/pkg/php/services_windows.go‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,33 @@
33
package php
44

55
import (
6-
`os`
7-
`os/exec`
6+
"syscall"
7+
8+
core "dappco.re/go"
89
)
910

1011
// setSysProcAttr sets Windows-specific process attributes.
1112
// Windows doesn't support Setpgid, so this is a no-op.
12-
func setSysProcAttr(cmd *exec.Cmd) {
13+
func setSysProcAttr(cmd *core.Cmd) {
1314
// No-op on Windows - process groups work differently
1415
}
1516

1617
// signalProcessGroup sends a termination signal to the process.
1718
// On Windows, we can only signal the main process, not a group.
18-
func signalProcessGroup(cmd *exec.Cmd, sig os.Signal) error { // Result boundary
19+
func signalProcessGroup(cmd *core.Cmd, sig syscall.Signal) error { // Result boundary
1920
if cmd.Process == nil {
2021
return nil
2122
}
2223

2324
return cmd.Process.Signal(sig)
2425
}
2526

26-
// termSignal returns os.Interrupt for Windows (closest to SIGTERM).
27-
func termSignal() os.Signal {
28-
return os.Interrupt
27+
// termSignal returns SIGINT for Windows (closest to SIGTERM).
28+
func termSignal() syscall.Signal {
29+
return syscall.SIGINT
2930
}
3031

31-
// killSignal returns os.Kill for Windows.
32-
func killSignal() os.Signal {
33-
return os.Kill
32+
// killSignal returns SIGKILL for Windows.
33+
func killSignal() syscall.Signal {
34+
return syscall.SIGKILL
3435
}

0 commit comments

Comments
 (0)