mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
* feat: add CLI support * updated * debug * fix tests * Caddy php-cli command * use thread * $_SERVER and input streams support * Update frankenphp.c Co-authored-by: Francis Lavoie <lavofr@gmail.com> --------- Co-authored-by: Francis Lavoie <lavofr@gmail.com>
38 lines
752 B
Go
38 lines
752 B
Go
package caddy
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
|
|
caddycmd "github.com/caddyserver/caddy/v2/cmd"
|
|
"github.com/dunglas/frankenphp"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
caddycmd.RegisterCommand(caddycmd.Command{
|
|
Name: "php-cli",
|
|
Usage: "script.php [args ...]",
|
|
Short: "Runs a PHP command",
|
|
Long: `
|
|
Executes a PHP script similarly to the CLI SAPI.`,
|
|
CobraFunc: func(cmd *cobra.Command) {
|
|
cmd.DisableFlagParsing = true
|
|
cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdPHPCLI)
|
|
},
|
|
})
|
|
}
|
|
|
|
func cmdPHPCLI(fs caddycmd.Flags) (int, error) {
|
|
args := os.Args[2:]
|
|
if len(args) < 1 {
|
|
return 1, errors.New("the path to the PHP script is required")
|
|
}
|
|
|
|
status := frankenphp.ExecuteScriptCLI(args[0], args)
|
|
os.Exit(status)
|
|
|
|
return status, nil
|
|
}
|