1
0
Fork 0
mirror of https://github.com/laravel-ls/go-php synced 2026-06-16 12:04:56 +02:00
go-php/cmd/main.go
2025-11-02 10:47:20 +01:00

53 lines
914 B
Go

package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"strings"
_ "embed"
"github.com/laravel-ls/go-php"
)
//go:embed configs.php
var source []byte
type Entry struct {
Value string `json:"value"`
File string `json:"file"`
Line int `json:"line"`
}
// call with ./prog /path/to/laravel/project app.key for example.
func main() {
if len(os.Args) < 2 {
fmt.Printf("usage: %s <path> <key>\n", os.Args[0])
os.Exit(1)
}
php.Init()
defer php.Exit()
prog, err := php.Compile(source)
if err != nil {
panic(err)
}
defer prog.Free()
buffer := bytes.Buffer{}
php.Output(&buffer).SetPath(os.Args[1]).Exec(prog)
data := map[string]Entry{}
json.NewDecoder(&buffer).Decode(&data)
for name, ent := range data {
if strings.HasPrefix(name, os.Args[2]) {
fmt.Println("Name:", name)
fmt.Println("File:", ent.File)
fmt.Println("Value:", ent.Value)
fmt.Println("---")
}
}
}