DockerComposerConfig
in package
Parses and exposes Docker Composer configuration from Composer metadata.
Table of Contents
Constants
- EXTRA_KEY = 'docker-composer'
- Names the Composer extra key used by this plugin.
- MODE_EXEC = 'exec'
- Selects Docker Compose exec mode.
- MODE_RUN = 'run'
- Selects Docker Compose run mode.
- KNOWN_KEYS = ['service', 'mode', 'compose-files', 'project-directory', 'workdir', 'exclude', 'service-mapping']
- Lists supported configuration keys.
Properties
- $composeFiles : array<int, string>
- Stores extra Docker Compose file arguments.
- $duplicateServiceMappingScripts : array<int, array{service: string, script: string}>
- Stores duplicate script entries found within the same service mapping.
- $exclude : array<int, string>
- Stores script names excluded from Docker redirection.
- $mode : string
- Stores the Docker Compose invocation mode.
- $projectDirectory : string|null
- Stores the Docker Compose project directory.
- $scriptServices : array<string, string>
- Stores Docker Compose service overrides keyed by Composer script name.
- $service : string|null
- Stores the Docker Compose service name.
- $unknownKeys : array<int, string>
- Stores unknown configuration keys.
- $workdir : string|null
- Stores the service working directory.
Methods
- forScript() : self
- Creates a copy that uses the service configured for a script.
- fromComposer() : self
- Creates configuration from Composer package metadata.
- getComposeFiles() : array<int, string>
- Gets configured Docker Compose file paths.
- getDuplicateServiceMappingScripts() : array<int, array{service: string, script: string}>
- Gets duplicate script mappings found within the same service.
- getMode() : string
- Gets the configured Docker Compose mode.
- getProjectDirectory() : string|null
- Gets the configured Docker Compose project directory.
- getService() : string
- Gets the configured Docker Compose service name.
- getServiceForScript() : string
- Gets the Docker Compose service name for a script.
- getUnknownKeys() : array<int, string>
- Gets unrecognized configuration keys.
- getWorkdir() : string|null
- Gets the configured service working directory.
- isConfigured() : bool
- Checks whether a Docker Compose service is configured.
- isConfiguredForScript() : bool
- Checks whether a Docker Compose service is configured for a script.
- isExcluded() : bool
- Checks whether a Composer script is excluded.
- __construct() : mixed
- Creates an immutable configuration value.
- composeFiles() : array<int, string>
- Reads Docker Compose file settings.
- empty() : self
- Creates an empty configuration object.
- mode() : string
- Reads the configured Docker Compose mode.
- object() : array<string, mixed>
- Normalizes a decoded Composer object.
- optionalString() : string|null
- Reads an optional non-empty `string` value.
- serviceMapping() : array<string, string>
- Reads service mapping settings as Composer script service overrides.
- stringList() : array<int, string>
- Reads a list of non-empty `string` values.
Constants
EXTRA_KEY
Names the Composer extra key used by this plugin.
public
string
EXTRA_KEY
= 'docker-composer'
Stores the extra object key containing Docker Composer settings.
MODE_EXEC
Selects Docker Compose exec mode.
public
string
MODE_EXEC
= 'exec'
Stores the mode that executes scripts in an existing service container.
MODE_RUN
Selects Docker Compose run mode.
public
string
MODE_RUN
= 'run'
Stores the mode that creates a one-off service container for scripts.
KNOWN_KEYS
Lists supported configuration keys.
private
array<int, string>
KNOWN_KEYS
= ['service', 'mode', 'compose-files', 'project-directory', 'workdir', 'exclude', 'service-mapping']
Stores accepted keys from the extra.docker-composer object.
Properties
$composeFiles
Stores extra Docker Compose file arguments.
private
array<int, string>
$composeFiles
$duplicateServiceMappingScripts
Stores duplicate script entries found within the same service mapping.
private
array<int, array{service: string, script: string}>
$duplicateServiceMappingScripts
$exclude
Stores script names excluded from Docker redirection.
private
array<int, string>
$exclude
Stores Composer script names that should run on the host.
$mode
Stores the Docker Compose invocation mode.
private
string
$mode
$projectDirectory
Stores the Docker Compose project directory.
private
string|null
$projectDirectory
$scriptServices
Stores Docker Compose service overrides keyed by Composer script name.
private
array<string, string>
$scriptServices
$service
Stores the Docker Compose service name.
private
string|null
$service
$unknownKeys
Stores unknown configuration keys.
private
array<int, string>
$unknownKeys
Stores keys kept for warning output.
$workdir
Stores the service working directory.
private
string|null
$workdir
Methods
forScript()
Creates a copy that uses the service configured for a script.
public
forScript(string $scriptName) : self
Parameters
- $scriptName : string
-
The Composer script name to resolve.
Return values
self —Returns configuration with the effective service set as the default.
fromComposer()
Creates configuration from Composer package metadata.
public
static fromComposer(Composer $composer) : self
Parameters
- $composer : Composer
-
The Composer instance that owns the package metadata.
Return values
self —Returns parsed Docker Composer configuration.
getComposeFiles()
Gets configured Docker Compose file paths.
public
getComposeFiles() : array<int, string>
Return values
array<int, string> —Returns paths passed to Docker Compose with --file.
getDuplicateServiceMappingScripts()
Gets duplicate script mappings found within the same service.
public
getDuplicateServiceMappingScripts() : array<int, array{service: string, script: string}>
Return values
array<int, array{service: string, script: string}> —Returns duplicate script entries ignored during service mapping parsing.
getMode()
Gets the configured Docker Compose mode.
public
getMode() : string
Return values
string —Returns "exec" or "run".
getProjectDirectory()
Gets the configured Docker Compose project directory.
public
getProjectDirectory() : string|null
Return values
string|null —Returns the directory path, or null for Docker Compose defaults.
getService()
Gets the configured Docker Compose service name.
public
getService() : string
Return values
string —Returns the non-empty service name.
getServiceForScript()
Gets the Docker Compose service name for a script.
public
getServiceForScript(string $scriptName) : string
Parameters
- $scriptName : string
-
The Composer script name to resolve.
Return values
string —Returns the per-script service override or the default service.
getUnknownKeys()
Gets unrecognized configuration keys.
public
getUnknownKeys() : array<int, string>
Return values
array<int, string> —Returns keys ignored by the plugin after warning output.
getWorkdir()
Gets the configured service working directory.
public
getWorkdir() : string|null
Return values
string|null —Returns the service working directory, or null for service defaults.
isConfigured()
Checks whether a Docker Compose service is configured.
public
isConfigured() : bool
Return values
bool —Returns true when a service name is available.
isConfiguredForScript()
Checks whether a Docker Compose service is configured for a script.
public
isConfiguredForScript(string $scriptName) : bool
Parameters
- $scriptName : string
-
The Composer script name to check.
Return values
bool —Returns true when scriptName has an override or default service.
isExcluded()
Checks whether a Composer script is excluded.
public
isExcluded(string $scriptName) : bool
Parameters
- $scriptName : string
-
The Composer script name to check.
Return values
bool —Returns true when scriptName should run on the host.
__construct()
Creates an immutable configuration value.
private
__construct(string|null $service, array<string, string> $scriptServices, array<int, array{service: string, script: string}> $duplicateServiceMappingScripts, string $mode, array<int, string> $composeFiles, string|null $projectDirectory, string|null $workdir, array<int, string> $exclude, array<int, string> $unknownKeys) : mixed
Parameters
- $service : string|null
-
The Docker Compose service name, or
nullwhen missing. - $scriptServices : array<string, string>
-
The Docker Compose services keyed by Composer script name.
- $duplicateServiceMappingScripts : array<int, array{service: string, script: string}>
-
The duplicate same-service script mappings retained for warnings.
- $mode : string
-
The Docker Compose mode, either
"exec"or"run". - $composeFiles : array<int, string>
-
The Docker Compose files passed with
--file. - $projectDirectory : string|null
-
The Docker Compose project directory, or
nullfor the default. - $workdir : string|null
-
The service working directory, or
nullfor the service default. - $exclude : array<int, string>
-
The Composer script names that should not be redirected.
- $unknownKeys : array<int, string>
-
The unrecognized config keys retained for warnings.
composeFiles()
Reads Docker Compose file settings.
private
static composeFiles(array<string, mixed> $raw) : array<int, string>
Parameters
- $raw : array<string, mixed>
-
The normalized configuration object.
Return values
array<int, string> —Returns file paths configured by compose-files.
empty()
Creates an empty configuration object.
private
static empty() : self
Return values
self —Returns configuration that leaves scripts on the host.
mode()
Reads the configured Docker Compose mode.
private
static mode(array<string, mixed> $raw) : string
Parameters
- $raw : array<string, mixed>
-
The normalized configuration object.
Return values
string —Returns "exec" when omitted, otherwise "exec" or "run".
object()
Normalizes a decoded Composer object.
private
static object(array<string|int, mixed> $raw) : array<string, mixed>
Parameters
- $raw : array<string|int, mixed>
-
The raw value decoded from Composer
extrametadata.
Return values
array<string, mixed> —Returns raw with verified string keys.
optionalString()
Reads an optional non-empty `string` value.
private
static optionalString(array<string, mixed> $raw, string $key) : string|null
Parameters
- $raw : array<string, mixed>
-
The normalized configuration object.
- $key : string
-
The configuration key to read.
Return values
string|null —Returns the configured string, or null when omitted.
serviceMapping()
Reads service mapping settings as Composer script service overrides.
private
static serviceMapping(array<string, mixed> $raw, array<int, array{service: string, script: string}> &$duplicateWarnings) : array<string, string>
Parameters
- $raw : array<string, mixed>
-
The normalized configuration object.
- $duplicateWarnings : array<int, array{service: string, script: string}>
-
The duplicate same-service script mappings found while parsing.
Return values
array<string, string> —Returns Docker Compose services keyed by Composer script name.
stringList()
Reads a list of non-empty `string` values.
private
static stringList(array<string, mixed> $raw, string $key) : array<int, string>
Parameters
- $raw : array<string, mixed>
-
The normalized configuration object.
- $key : string
-
The configuration key to read.
Return values
array<int, string> —Returns the configured list, or an empty list when omitted.