php

package
v1.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFPMNotInstalled = errors.New("FPM container is not installed")

ErrFPMNotInstalled is returned (wrapped) by StartFPM when the requested version's FPM container does not exist yet, so the caller knows the fix is to install it rather than just start it. Test with errors.Is.

Functions

func ClampToRange added in v1.10.0

func ClampToRange(version, min, max string) string

ClampToRange checks if version falls within [min, max] and returns the best installed version within range if it doesn't. Returns the original version if min/max are empty or the version is already in range. This is used to respect framework PHP version constraints during site linking.

func CompareMajorMinor added in v1.26.0

func CompareMajorMinor(a, b string) int

CompareMajorMinor compares two "major.minor" version strings numerically and returns -1, 0, or 1. An unparseable version sorts below any numeric one.

func DetectExtensions added in v0.5.5

func DetectExtensions(dir string) []string

DetectExtensions reads composer.json in dir and returns the list of PHP extensions declared in the require map (ext-* keys), with the "ext-" prefix stripped. Returns an empty slice on any error (non-fatal).

func DetectVersion

func DetectVersion(dir string) (string, error)

DetectVersion detects the PHP version for the given directory. It checks, in order:

  1. .lerd.yaml php_version field (explicit lerd override)
  2. .php-version file (explicit per-project pin)
  3. composer.json require.php semver (project requirement)
  4. global config default

func DetectVersionClamped added in v1.11.0

func DetectVersionClamped(dir, phpMin, phpMax, fallback string) string

DetectVersionClamped detects the PHP version and clamps it to the given range. If phpMin/phpMax are empty, no clamping is applied.

func FPMInstalled added in v1.27.0

func FPMInstalled(version, container string) bool

FPMInstalled reports whether the FPM container already exists (so it only needs starting) rather than needing a fresh build. It checks both the shared per-version units and the specific container's unit, so a custom-FPM container (lerd-cfpm-<site>, whose version isn't in the shared list) is recognised too.

func IsInstalled

func IsInstalled(version string) bool

IsInstalled returns true if the given PHP version has an FPM quadlet.

func IsPHPProject added in v1.23.0

func IsPHPProject(dir string) bool

IsPHPProject reports whether dir looks like a PHP project: it has a composer.json or any top-level .php file. Static sites (a public dir with no PHP) and non-PHP projects return false, so callers can hide PHP-only surfaces like the version dropdown, Tinker, Xdebug, dumps and FPM logs.

func ListInstalled

func ListInstalled() ([]string, error)

ListInstalled returns all PHP versions that have an FPM quadlet file or a running/existing Podman container, e.g. ["8.3", "8.4"]. The two sources are merged so users whose quadlet file is missing but whose container still exists are not excluded.

func SiteRootFor added in v1.30.0

func SiteRootFor(dir string) string

SiteRootFor returns the registered site path that contains dir, or dir itself if no registered site matches. Commands run from anywhere in a project, so this walks up to the project root the site was registered at.

func SiteUsesPHP added in v1.23.0

func SiteUsesPHP(s config.Site) bool

SiteUsesPHP reports whether the site is a PHP project served by lerd's PHP runtime (the shared FPM image or FrankenPHP), as opposed to a static site or a custom container. It mirrors the registration decision in cli.RegisterProject: a framework, a composer.json / top-level .php file, or a public dir with an index.php entrypoint all count as PHP. Custom containers and static sites (a public dir of HTML only) return false.

func StartFPM added in v1.27.0

func StartFPM(version, container string) error

StartFPM brings up a stopped-but-installed FPM container and waits for it to report running, so an exec right after doesn't race the boot. It is a no-op when the container is already running and returns ErrFPMNotInstalled (wrapped with the version) when the container doesn't exist yet. It produces no output; callers add any user-facing progress. Shared by the CLI php/artisan/shell commands and the MCP exec handlers so both auto-start the same way.

func VersionForDir added in v1.30.0

func VersionForDir(dir string) (string, error)

VersionForDir resolves the PHP version a directory's commands must run on. This is the single answer the CLI, the MCP server and the version-scoped tools all use, so a command can never exec into a different PHP than the container serving the same directory.

A worktree's own pin wins first: a worktree checked out inside its parent site matches that site by path, so resolving the site first would ignore the pin its vhost was generated from. A registered site's version comes next, because lerd link clamps to the framework's supported range and re-detecting would undo the clamp. Only then does the project's own configuration apply.

func WorktreeRootFor added in v1.30.0

func WorktreeRootFor(dir string) (string, *config.Site, bool)

WorktreeRootFor returns the worktree checkout containing dir and the site it belongs to. Git writes .git as a file in a worktree and as a directory in the main checkout, so the walk stops at the first .git either way.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL