system

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PHPSourceEnv  = "PHP_BINARY"
	PHPSourcePath = phpdiscover.SourcePath
	PHPSourceFlag = "flag"
)

Sources a PHPInstallation can be discovered from.

Variables

View Source
var ComposeProjectNameRegexp = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]*$`)

ComposeProjectNameRegexp matches names that are valid as a Docker Compose project name. Docker Compose only allows lowercase letters, digits, dashes and underscores, and the name must start with a lowercase letter or digit.

View Source
var ErrCacheNotFound = errors.New("cache item not found")

ErrCacheNotFound is returned when a cache item cannot be found

Functions

func CloseCaches

func CloseCaches() error

CloseCaches closes all tracked caches collecting the first error if multiple occur. It is safe to call multiple times; subsequent calls will no-op as the slice is cleared.

func CopyFiles

func CopyFiles(currentPath string, targetPath string) error

func DecompressReader

func DecompressReader(r io.Reader) (io.Reader, error)

DecompressReader detects gzip and zstd compression from the leading magic bytes and returns a transparently decompressing reader. Close the returned reader when it implements io.Closer to release decompressor resources.

func DockerRunUserArgs

func DockerRunUserArgs(projectDir string) []string

DockerRunUserArgs returns the arguments for a raw `docker run` so that the container process runs as the host user with the project directory's group. An arbitrary UID has no passwd entry inside the image, which would leave HOME unset/unwritable, so HOME and COMPOSER_HOME are pointed at a writable location.

func ExpandEnv

func ExpandEnv(s string) string

func GetAvailablePHPExtensions

func GetAvailablePHPExtensions(ctx context.Context) ([]string, error)

GetAvailablePHPExtensions returns the list of loaded PHP extensions by parsing `php -m` output.

func GetInstalledNodeVersion

func GetInstalledNodeVersion(ctx context.Context) (string, error)

GetInstalledNodeVersion checks the installed Node.js version on the system.

func GetInstalledPHPVersion

func GetInstalledPHPVersion(ctx context.Context) (string, error)

GetInstalledPHPVersion checks the installed PHP version on the system.

func GetPHPVersionOfBinary

func GetPHPVersionOfBinary(ctx context.Context, phpPath string) (string, error)

GetPHPVersionOfBinary executes the given PHP binary and returns the normalized version it reports. It fails when the binary cannot be executed or does not produce PHP's version banner.

func GetShopwareCliCacheDir

func GetShopwareCliCacheDir() string

GetShopwareCliCacheDir returns the base cache directory for shopware-c

func IsCIEnvironment

func IsCIEnvironment(getenv func(string) string) bool

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

func IsDockerMountable

func IsDockerMountable() bool

func IsDockerUsingLibkrun

func IsDockerUsingLibkrun() bool

IsDockerUsingLibkrun checks if Docker is using libkrun (Docker VMM) for improved host mount performance on macOS.

func IsGitInstalled

func IsGitInstalled() bool

func IsInsideContainer

func IsInsideContainer() bool

func IsInteractionEnabled

func IsInteractionEnabled(ctx context.Context) bool

IsInteractionEnabled returns true if interaction is enabled in the context. It defaults to true if not set or if the stored value is not a bool.

func IsNodeVersionAtLeast

func IsNodeVersionAtLeast(ctx context.Context, requiredVersion string) (bool, error)

IsNodeVersionAtLeast checks if the installed Node.js version meets the minimum required version.

func IsPHPVersionAtLeast

func IsPHPVersionAtLeast(ctx context.Context, requiredVersion string) (bool, error)

func IsSymfonyCliInstalled

func IsSymfonyCliInstalled() bool

func IsUnderHomebrew

func IsUnderHomebrew(binaryPath string) bool

IsUnderHomebrew reports whether binaryPath is installed in Homebrew's bin directory.

func IsWSL

func IsWSL() bool

func IsWSLWindowsMount

func IsWSLWindowsMount(path string) bool

func OpenURL

func OpenURL(ctx context.Context, url string) error

OpenURL opens the given URL in the user's default browser.

func PHPVersionPin

func PHPVersionPin(phpVersion string) string

PHPVersionPin renders the major.minor pin persisted in the project config (e.g. "8.3.19" becomes "8.3"). The patch level is dropped so the pin survives a PHP package update.

func ProjectUserSpec

func ProjectUserSpec(dir string) string

ProjectUserSpec returns the "uid:gid" the container should run as for the given project directory: the calling user's UID combined with the directory's owning group. Using the directory's group makes shared setups work (e.g. a projects dir owned by a dev group with the setgid bit): files created by the container belong to the shared group, so other members can collaborate. Falls back to the caller's primary GID when the directory cannot be inspected. Returns "" on non-Linux platforms: only there do bind mounts expose raw host UIDs; Docker Desktop's VM handles ownership mapping on macOS and Windows.

func RenderMissingDependencies

func RenderMissingDependencies(useDocker bool, missing []MissingDependency, action, dockerHint string) string

func ResolveComposer

func ResolveComposer(ctx context.Context) (path string, isPhar bool, err error)

ResolveComposer returns a usable Composer executable, preferring composer from PATH. When none is installed, it downloads the Composer PHAR into the shopware-cli cache directory (once) and returns its path. isPhar reports that the returned path must be run through a PHP binary instead of directly.

func ResolvePinnedPHPBinary

func ResolvePinnedPHPBinary(ctx context.Context, pin string) (string, error)

ResolvePinnedPHPBinary returns the PHP executable matching the version pinned by the project config, ignoring PHP_BINARY. An empty pin returns an empty string. A pin that matches no installed PHP fails with *PHPVersionNotFoundError instead of falling back to another version.

func ResolveProjectPHPBinary

func ResolveProjectPHPBinary(ctx context.Context, pin string) (string, error)

ResolveProjectPHPBinary returns the PHP executable a project's local commands run, following the precedence: PHP_BINARY > the pinned php_version > the php found in PATH (an empty return value). An unusable PHP_BINARY is an error rather than a reason to fall back to another PHP.

func UnusablePHPBinaryEnv

func UnusablePHPBinaryEnv(ctx context.Context) error

UnusablePHPBinaryEnv reports why a configured PHP_BINARY cannot be used, or nil when it is unset or usable. DiscoverPHPInstallations omits an unusable PHP_BINARY, so callers reading discovery directly must check this to avoid silently falling back to another PHP.

func ValidateDockerComposeName

func ValidateDockerComposeName(name string) error

ValidateDockerComposeName reports whether name can be used as a Docker Compose project name. The charset also permits underscores, which are not valid in a DNS label — callers deriving a hostname from the name must map them to dashes first (see proxy.ProjectHostname).

func ValidateProjectDependencies

func ValidateProjectDependencies(ctx context.Context, useDocker bool, phpConstraint PHPVersionChecker, action, dockerHint, phpBinary string) error

ValidateProjectDependencies runs CheckProjectDependencies and, when something is missing, prints the rendered explanation to stderr and returns an error. action and dockerHint are passed through to RenderMissingDependencies to phrase the help text for the calling command. phpBinary optionally selects the PHP executable to check instead of the ambient one.

func WithInteraction

func WithInteraction(ctx context.Context, interaction bool) context.Context

WithInteraction returns a new context with the interaction state set.

Types

type Cache

type Cache interface {
	// Get retrieves a cached item by key. Returns ErrCacheNotFound if not found.
	Get(ctx context.Context, key string) (io.ReadCloser, error)

	// Set stores an item in the cache with the given key
	Set(ctx context.Context, key string, data io.Reader) error

	// GetFilePath returns a file path for direct access to the cached item.
	// For local caches, this returns the actual file path.
	// For remote caches, this downloads the item to a temp file and returns that path.
	// Returns ErrCacheNotFound if the item doesn't exist.
	GetFilePath(ctx context.Context, key string) (string, error)

	// StoreFolderCache stores an entire folder structure in the cache with the given key.
	// The folderPath should be the root directory to cache.
	StoreFolderCache(ctx context.Context, key string, folderPath string) error

	// GetFolderCachePath returns a folder path for direct access to the cached folder.
	// For local caches, this returns the actual folder path.
	// For remote caches, this downloads and extracts the folder to a temp directory.
	// Returns ErrCacheNotFound if the folder doesn't exist.
	GetFolderCachePath(ctx context.Context, key string) (string, error)

	// RestoreFolderCache extracts/copies a cached folder to the specified target directory.
	// This is useful when you want to restore cached content to a specific location.
	// Returns ErrCacheNotFound if the cached folder doesn't exist.
	RestoreFolderCache(ctx context.Context, key string, targetPath string) error

	// Close cleans up any temporary files or resources held by the cache
	Close() error
}

Cache provides a unified interface for caching operations

func GetCacheWithPrefix

func GetCacheWithPrefix(prefix string) Cache

GetCacheWithPrefix returns a cache instance with a custom prefix using the factory

func GetDefaultCache

func GetDefaultCache() Cache

GetDefaultCache returns a default cache instance using the factory

type CacheFactory

type CacheFactory interface {
	CreateCache() Cache
}

CacheFactory creates cache instances based on the environment

type CountingReader

type CountingReader struct {
	Reader io.Reader
	// contains filtered or unexported fields
}

CountingReader wraps a reader and counts the bytes read through it, e.g. for progress reporting against a known total size.

func (*CountingReader) BytesRead

func (c *CountingReader) BytesRead() int64

BytesRead returns the number of bytes read so far.

func (*CountingReader) Read

func (c *CountingReader) Read(p []byte) (int, error)

type DefaultCacheFactory

type DefaultCacheFactory struct{}

DefaultCacheFactory implements CacheFactory

func NewCacheFactory

func NewCacheFactory() *DefaultCacheFactory

NewCacheFactory creates a new cache factory

func (*DefaultCacheFactory) CreateCache

func (f *DefaultCacheFactory) CreateCache() Cache

CreateCache creates a cache instance based on the environment

func (*DefaultCacheFactory) CreateCacheWithPrefix

func (f *DefaultCacheFactory) CreateCacheWithPrefix(prefix string) Cache

CreateCacheWithPrefix creates a cache instance with a custom prefix/directory

type DiskCache

type DiskCache struct {
	// contains filtered or unexported fields
}

DiskCache implements Cache interface using local filesystem

func NewDiskCache

func NewDiskCache(basePath string) *DiskCache

NewDiskCache creates a new disk-based cache

func (*DiskCache) Close

func (c *DiskCache) Close() error

Close cleans up any resources (no-op for disk cache)

func (*DiskCache) Get

func (c *DiskCache) Get(ctx context.Context, key string) (io.ReadCloser, error)

Get retrieves a cached item by key

func (*DiskCache) GetFilePath

func (c *DiskCache) GetFilePath(ctx context.Context, key string) (string, error)

GetFilePath returns the file path for direct access to the cached item

func (*DiskCache) GetFolderCachePath

func (c *DiskCache) GetFolderCachePath(ctx context.Context, key string) (string, error)

GetFolderCachePath returns the folder path for direct access to the cached folder

func (*DiskCache) RestoreFolderCache

func (c *DiskCache) RestoreFolderCache(ctx context.Context, key string, targetPath string) error

RestoreFolderCache copies a cached folder to the specified target directory

func (*DiskCache) Set

func (c *DiskCache) Set(ctx context.Context, key string, data io.Reader) error

Set stores an item in the cache with the given key

func (*DiskCache) StoreFolderCache

func (c *DiskCache) StoreFolderCache(ctx context.Context, key string, folderPath string) error

StoreFolderCache stores an entire folder structure in the cache

type GitHubActionsCache

type GitHubActionsCache struct {
	// contains filtered or unexported fields
}

GitHubActionsCache implements Cache interface using GitHub Actions cache

func NewGitHubActionsCache

func NewGitHubActionsCache(prefix string) (*GitHubActionsCache, error)

NewGitHubActionsCache creates a new GitHub Actions cache

func (*GitHubActionsCache) Close

func (c *GitHubActionsCache) Close() error

Close cleans up all temporary files created by GetFilePath

func (*GitHubActionsCache) Get

Get retrieves a cached item by key

func (*GitHubActionsCache) GetFilePath

func (c *GitHubActionsCache) GetFilePath(ctx context.Context, key string) (string, error)

GetFilePath downloads the cache item to a temporary file and returns the file path

func (*GitHubActionsCache) GetFolderCachePath

func (c *GitHubActionsCache) GetFolderCachePath(ctx context.Context, key string) (string, error)

GetFolderCachePath downloads and extracts the cached folder to a temporary directory

func (*GitHubActionsCache) RestoreFolderCache

func (c *GitHubActionsCache) RestoreFolderCache(ctx context.Context, key string, targetPath string) error

RestoreFolderCache downloads and extracts a cached folder to the specified target directory

func (*GitHubActionsCache) Set

func (c *GitHubActionsCache) Set(ctx context.Context, key string, data io.Reader) error

Set stores an item in the cache with the given key

func (*GitHubActionsCache) StoreFolderCache

func (c *GitHubActionsCache) StoreFolderCache(ctx context.Context, key string, folderPath string) error

StoreFolderCache stores an entire folder structure in the cache

type Incompatibility

type Incompatibility struct {
	Title       string
	Description string
}

func CheckIncompatibilities

func CheckIncompatibilities(useDocker bool, projectFolder string) []Incompatibility

CheckIncompatibilities returns soft-warning issues with the chosen setup (e.g. macOS Docker without libkrun, or a project folder on a Windows-mounted path under WSL) that don't block project creation but degrade performance.

type MissingDependency

type MissingDependency struct {
	Name   string
	Reason string
}

func CheckProjectDependencies

func CheckProjectDependencies(ctx context.Context, useDocker bool, phpConstraint PHPVersionChecker, phpBinary string) []MissingDependency

CheckProjectDependencies returns the dependencies required to set up a Shopware project that are not currently available. When useDocker is true and we are not already inside a container, only Docker is required; otherwise PHP 8.2+ must be present locally (Composer is not required — a PHAR copy is downloaded on demand when it is missing, see ResolveComposer). If phpConstraint is non-nil and the checked PHP does not satisfy it, that mismatch is reported as well. phpBinary selects the PHP executable to check; when empty, the ambient PHP (PHP_BINARY or PATH) is checked instead.

type PHPBinaryError

type PHPBinaryError struct {
	Path   string
	Reason string
	Err    error
}

PHPBinaryError describes why a specific PHP binary path is not usable.

func (*PHPBinaryError) Error

func (e *PHPBinaryError) Error() string

func (*PHPBinaryError) Unwrap

func (e *PHPBinaryError) Unwrap() error

type PHPInstallation

type PHPInstallation struct {
	Binary  string // absolute/canonical executable path
	Version string // normalized version reported by the executable
	Source  string // e.g. PHP_BINARY, PATH, homebrew, system package
	Default bool   // true for the executable a plain `php` resolves to on PATH
}

PHPInstallation describes a usable PHP executable found on the machine.

func DefaultPHPInstallation

func DefaultPHPInstallation(installations []PHPInstallation) *PHPInstallation

DefaultPHPInstallation returns the installation a plain `php` resolves to on PATH, or nil when there is none.

func DiscoverPHPInstallations

func DiscoverPHPInstallations(ctx context.Context) []PHPInstallation

DiscoverPHPInstallations returns the usable PHP executables installed on the machine via github.com/shyim/go-php-discover, plus an explicitly configured PHP_BINARY when set, newest version first with PHP_BINARY hoisted to the front.

func FilterCompatiblePHP

func FilterCompatiblePHP(installations []PHPInstallation, checker PHPVersionChecker) []PHPInstallation

FilterCompatiblePHP returns the installations whose version satisfies the given constraint. A nil checker matches everything.

func FindPHPByBinary

func FindPHPByBinary(installations []PHPInstallation, binary string) *PHPInstallation

FindPHPByBinary returns the installation with the given binary path, or nil when the list contains no such entry.

func FindPHPBySource

func FindPHPBySource(installations []PHPInstallation, source string) *PHPInstallation

FindPHPBySource returns the first installation discovered from the given source, or nil when there is none.

func FindPHPByVersionPin

func FindPHPByVersionPin(installations []PHPInstallation, pin string) *PHPInstallation

FindPHPByVersionPin returns the newest installation matching the pin, or nil when none does. The pin is a version prefix at any depth: "8" matches every 8.x, "8.3" every 8.3.x, "8.3.19" only that patch release. Unlike phpdiscover.FindVersion it works on an already discovered list, which also carries the PHP_BINARY entry.

func PreferredPHPInstallation

func PreferredPHPInstallation(installations []PHPInstallation) *PHPInstallation

PreferredPHPInstallation returns the installation to preselect for the user: the PHP_BINARY candidate when present, otherwise the PATH default, otherwise the first entry (the newest version). Returns nil for an empty list.

func ProbePHPBinary

func ProbePHPBinary(ctx context.Context, path, source string) (*PHPInstallation, error)

ProbePHPBinary canonicalizes the given path, verifies that it is an executable file, and executes it to obtain its PHP version. It is used to validate an explicitly configured PHP binary (e.g. PHP_BINARY).

func (PHPInstallation) String

func (i PHPInstallation) String() string

String renders the installation for user-facing output, e.g. "PHP 8.3.19 — /opt/homebrew/opt/php@8.3/bin/php".

type PHPVersionChecker

type PHPVersionChecker interface {
	Check(phpVersion string) bool
	String() string
}

PHPVersionChecker is satisfied by anything that can verify a PHP version string against a constraint (e.g. shop.PHPConstraint). The interface keeps the system package free of cyclic imports.

type PHPVersionNotFoundError

type PHPVersionNotFoundError struct {
	Pin           string
	Installations []PHPInstallation
}

PHPVersionNotFoundError reports that the PHP version pinned by the project config is not installed on this machine.

func (*PHPVersionNotFoundError) Error

func (e *PHPVersionNotFoundError) Error() string

Jump to

Keyboard shortcuts

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