Documentation
¶
Index ¶
- Constants
- func ConvertContainerToYAML(container *Container) ([]byte, error)
- func ConvertRoutesToYAML(routes *Routes) ([]byte, error)
- func ConvertRoutesXMLFile(path string) (map[string]string, error)
- func ConvertServicesXMLFile(path string) (map[string]string, error)
- func IsAdminWorkerEnabledForProject(projectRoot, environment string) (bool, error)
- type ConfigFile
- type Container
- type ProjectConfig
- func (pc *ProjectConfig) Config(environment string) (map[string]any, error)
- func (pc *ProjectConfig) Env() (map[string]string, error)
- func (pc *ProjectConfig) Environments() []string
- func (pc *ProjectConfig) Files() []*ConfigFile
- func (pc *ProjectConfig) GetConfigValue(environment, path string) (any, bool, error)
- func (pc *ProjectConfig) GetResolvedConfigValue(environment, path string) (any, bool, error)
- func (pc *ProjectConfig) IsAdminWorkerEnabled(environment string) (bool, error)
- func (pc *ProjectConfig) PackageConfig(environment, pkg string) (any, bool, error)
- func (pc *ProjectConfig) ResolveEnvExpression(value any) (any, error)
- func (pc *ProjectConfig) ResolvedConfig(environment string) (map[string]any, error)
- func (pc *ProjectConfig) SetConfigValue(environment string, path string, value any) error
- type Routes
Constants ¶
const BaseEnvironment = "_base"
BaseEnvironment is the pseudo-environment that represents configuration which is loaded for every environment (the files directly in config/packages and the when@<env> blocks are resolved relative to it).
Variables ¶
This section is empty.
Functions ¶
func ConvertContainerToYAML ¶
ConvertContainerToYAML converts a parsed services.xml container into the equivalent services.yaml content. It returns an error whenever the XML contains something that cannot be expressed safely in YAML, so a conversion never silently drops configuration.
func ConvertRoutesToYAML ¶
ConvertRoutesToYAML converts a parsed routes.xml file into the equivalent routes.yaml content. Like the services conversion it refuses everything that cannot be expressed safely in YAML.
func ConvertRoutesXMLFile ¶
ConvertRoutesXMLFile converts a Symfony routes.xml file and any local XML files referenced through imports, with the same guarantees as ConvertServicesXMLFile.
func ConvertServicesXMLFile ¶
ConvertServicesXMLFile converts a Symfony services.xml file and any local XML files referenced through <imports> into the YAML format. The YAML files are written next to the XML files and the XML files are removed afterwards. Nothing is written when one of the involved files cannot be converted. It returns a map of the XML files to the created YAML files.
func IsAdminWorkerEnabledForProject ¶
IsAdminWorkerEnabledForProject loads the project's config/packages tree and reports whether the admin worker is enabled for the given environment. It is the convenience entry point for callers that only need this one value and do not otherwise hold a ProjectConfig. A project without a readable config/packages tree defaults to enabled.
Types ¶
type ConfigFile ¶
ConfigFile is a single parsed YAML file below config/packages. It keeps the original document node so writes can preserve comments and formatting. Files directly in config/packages use BaseEnvironment as Environment; files in config/packages/<env>/ use that <env>.
type Container ¶
type Container struct {
XMLName xml.Name `xml:"container"`
Imports *xmlImports `xml:"imports"`
Parameters *xmlParameters `xml:"parameters"`
Services *xmlServices `xml:"services"`
When []xmlWhen `xml:"when"`
Unknown []xmlUnknown `xml:",any"`
}
Container is the parsed representation of a Symfony services.xml file.
func ParseServicesXML ¶
ParseServicesXML parses the content of a Symfony services.xml file.
type ProjectConfig ¶
type ProjectConfig struct {
// contains filtered or unexported fields
}
ProjectConfig is the entry point for reading and mutating the config/packages tree of a Symfony project. Use NewProjectConfig to load it from disk.
func NewProjectConfig ¶
func NewProjectConfig(projectRoot string) (*ProjectConfig, error)
NewProjectConfig discovers and parses every YAML file below <projectRoot>/config/packages, including environment subdirectories. It does not resolve or merge anything yet; call Environments, Config or related methods for that. A project without a config/packages directory yields an empty ProjectConfig rather than an error.
func (*ProjectConfig) Config ¶
func (pc *ProjectConfig) Config(environment string) (map[string]any, error)
Config resolves the fully merged configuration for the given environment. The result is keyed by package name (e.g. "framework", "doctrine") and contains plain Go values (map[string]any, []any, scalars) so callers can inspect or transform arbitrary keys.
Merge order follows Symfony, lowest to highest precedence:
- config/packages/*.yaml (base files)
- when@<env> blocks in base files (resolved in base-file order)
- config/packages/<env>/*.yaml (environment files)
- when@<env> blocks in environment files
Maps are merged recursively; sequences and scalars from a higher-precedence source replace the lower-precedence value entirely.
func (*ProjectConfig) Env ¶
func (pc *ProjectConfig) Env() (map[string]string, error)
Env returns the project's environment variables parsed from its Symfony env files (.env.dist < .env < .env.local), merged with Symfony precedence. The returned map is the same source ResolvedConfig uses to resolve %env(...)% references. An empty map is returned when the project has no env files.
func (*ProjectConfig) Environments ¶
func (pc *ProjectConfig) Environments() []string
Environments returns the sorted list of environments the project defines, excluding BaseEnvironment. An environment is recognised either through a config/packages/<env>/ directory or through a when@<env> block in any file.
func (*ProjectConfig) Files ¶
func (pc *ProjectConfig) Files() []*ConfigFile
Files returns every parsed config file in load order. The returned slice is a copy; mutating it does not affect the ProjectConfig.
func (*ProjectConfig) GetConfigValue ¶
func (pc *ProjectConfig) GetConfigValue(environment, path string) (any, bool, error)
GetConfigValue resolves a single dotted path (rooted at the package name, e.g. "framework.cache.app") in the merged configuration of an environment. The second return value reports whether the path exists.
func (*ProjectConfig) GetResolvedConfigValue ¶
func (pc *ProjectConfig) GetResolvedConfigValue(environment, path string) (any, bool, error)
GetResolvedConfigValue is GetConfigValue with %env(...)% resolution applied to the returned value (and recursively to nested values).
func (*ProjectConfig) IsAdminWorkerEnabled ¶
func (pc *ProjectConfig) IsAdminWorkerEnabled(environment string) (bool, error)
IsAdminWorkerEnabled reports whether Shopware's admin worker is enabled for the given environment. The admin worker is enabled by default, so a project that does not configure it at all is treated as enabled. It is only considered disabled when enable_admin_worker resolves to a literal false.
func (*ProjectConfig) PackageConfig ¶
func (pc *ProjectConfig) PackageConfig(environment, pkg string) (any, bool, error)
PackageConfig is a convenience wrapper around Config that returns the merged configuration of a single package for an environment. The second return value reports whether the package is configured at all.
func (*ProjectConfig) ResolveEnvExpression ¶
func (pc *ProjectConfig) ResolveEnvExpression(value any) (any, error)
ResolveEnvExpression resolves a single value the way ResolvedConfig would: if it is a %env(...)% expression it is resolved against the project's .env files, otherwise it is returned unchanged.
func (*ProjectConfig) ResolvedConfig ¶
func (pc *ProjectConfig) ResolvedConfig(environment string) (map[string]any, error)
ResolvedConfig is like Config but additionally resolves %env(...)% references in string values against the project's .env files for that environment (.env.dist < .env < .env.local < .env.<env> < .env.<env>.local, following Symfony precedence). Values that are not env expressions are returned unchanged, and an unresolved variable becomes an empty string unless a default processor supplies a fallback.
Only string scalars are inspected; a successful cast processor (bool, int, json, ...) can change the Go type of the resulting value.
func (*ProjectConfig) SetConfigValue ¶
func (pc *ProjectConfig) SetConfigValue(environment string, path string, value any) error
SetConfigValue sets the value at the given dotted path for an environment and persists the change to disk. The path is rooted at the package name, e.g. "framework.cache.app" or "doctrine.dbal.url".
The target file is chosen to mirror where Symfony itself would read the value from, so existing comments, key order and formatting in unrelated parts of the file are preserved:
- If a file already defines the path (the deepest existing prefix wins), that file is edited in place.
- Otherwise, for an environment other than BaseEnvironment that has a config/packages/<env>/ directory, a file named <package>.yaml in that directory is used (created if necessary).
- Otherwise config/packages/<package>.yaml is used (created if necessary).
After a successful write the in-memory state is reloaded so subsequent reads observe the change.
type Routes ¶
Routes is the parsed representation of a Symfony routes.xml file.
func ParseRoutesXML ¶
ParseRoutesXML parses the content of a Symfony routes.xml file.