php/workspace.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

76 lines
1.9 KiB
Go

package php
import (
"fmt"
"os"
"path/filepath"
"forge.lthn.ai/core/go-io"
"gopkg.in/yaml.v3"
)
// workspaceConfig holds workspace-level configuration from .core/workspace.yaml.
type workspaceConfig struct {
Version int `yaml:"version"`
Active string `yaml:"active"` // Active package name
DefaultOnly []string `yaml:"default_only"` // Default types for setup
PackagesDir string `yaml:"packages_dir"` // Where packages are cloned
}
// defaultWorkspaceConfig returns a config with default values.
func defaultWorkspaceConfig() *workspaceConfig {
return &workspaceConfig{
Version: 1,
PackagesDir: "./packages",
}
}
// loadWorkspaceConfig tries to load workspace.yaml from the given directory's .core subfolder.
// Returns nil if no config file exists.
func loadWorkspaceConfig(dir string) (*workspaceConfig, error) {
path := filepath.Join(dir, ".core", "workspace.yaml")
data, err := io.Local.Read(path)
if err != nil {
if !io.Local.IsFile(path) {
parent := filepath.Dir(dir)
if parent != dir {
return loadWorkspaceConfig(parent)
}
return nil, nil
}
return nil, fmt.Errorf("failed to read workspace config: %w", err)
}
config := defaultWorkspaceConfig()
if err := yaml.Unmarshal([]byte(data), config); err != nil {
return nil, fmt.Errorf("failed to parse workspace config: %w", err)
}
if config.Version != 1 {
return nil, fmt.Errorf("unsupported workspace config version: %d", config.Version)
}
return config, nil
}
// findWorkspaceRoot searches for the root directory containing .core/workspace.yaml.
func findWorkspaceRoot() (string, error) {
dir, err := os.Getwd()
if err != nil {
return "", err
}
for {
if io.Local.IsFile(filepath.Join(dir, ".core", "workspace.yaml")) {
return dir, nil
}
parent := filepath.Dir(dir)
if parent == dir {
break
}
dir = parent
}
return "", fmt.Errorf("not in a workspace")
}