mirror of
https://github.com/laravel-ls/go-php
synced 2026-06-18 13:00:02 +02:00
Initial commit
This commit is contained in:
commit
4cbf7e62b7
19 changed files with 1295 additions and 0 deletions
53
cmd/main.go
Normal file
53
cmd/main.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
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("---")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue