php/extract.go
Snider ad8af2fb83
Some checks failed
CI / PHP 8.4 (push) Failing after 2m5s
CI / PHP 8.3 (push) Failing after 2m10s
feat: merge go-php Go CLI into core/php
Merge all Go code from core/go-php into core/php, creating a dual-language
repo (Go CLI + PHP framework). Module path: forge.lthn.ai/core/php.

- PHP dev/build/deploy/QA commands (cmd_*.go)
- FrankenPHP handler + bridge (handler.go, bridge.go)
- Standalone binary entry point (cmd/core-php/)
- Build/release configs (.core/)
- Full test suite

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-06 17:50:01 +00:00

49 lines
1.1 KiB
Go

package php
import (
"fmt"
"io/fs"
"os"
"path/filepath"
)
// Extract copies an embedded Laravel app (from embed.FS) to a temporary directory.
// FrankenPHP needs real filesystem paths — it cannot serve from embed.FS.
// The prefix is the embed directory name (e.g. "laravel").
// Returns the path to the extracted Laravel root. Caller must os.RemoveAll on cleanup.
func Extract(fsys fs.FS, prefix string) (string, error) {
tmpDir, err := os.MkdirTemp("", "go-php-laravel-*")
if err != nil {
return "", fmt.Errorf("create temp dir: %w", err)
}
err = fs.WalkDir(fsys, prefix, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(prefix, path)
if err != nil {
return err
}
targetPath := filepath.Join(tmpDir, relPath)
if d.IsDir() {
return os.MkdirAll(targetPath, 0o755)
}
data, err := fs.ReadFile(fsys, path)
if err != nil {
return fmt.Errorf("read embedded %s: %w", path, err)
}
return os.WriteFile(targetPath, data, 0o644)
})
if err != nil {
os.RemoveAll(tmpDir)
return "", fmt.Errorf("extract Laravel: %w", err)
}
return tmpDir, nil
}