Ejemplo n.º 1
0
// Path option function to specify the configuration path. If one argument has been
// provided then it must be a full valid path. If more than one argument has been provided
// then the arguments will be joined together. Panics if nil arguments will be provided.
func Path(paths ...string) ArgFunc {
	// TODO(cs) validation of the path see typeConfigPath in app/code/Magento/Config/etc/system_file.xsd

	if false == isValidPath(paths...) {
		return func(a *arg) {
			a.lastErrors = append(a.lastErrors, ErrPathEmpty)
		}
	}

	var pa string
	lp := len(paths)
	var paSlice []string
	if lp >= hierarchyLevel {
		pa = scope.PathJoin(paths...)
		paSlice = paths
	} else {
		pa = paths[0]
		paSlice = scope.PathSplit(paths[0])
		if len(paSlice) < hierarchyLevel {
			return func(a *arg) {
				a.lastErrors = append(a.lastErrors, fmt.Errorf("Incorrect number of paths elements: want %d, have %d, Path: %v", hierarchyLevel, len(paSlice), paths))
			}
		}
	}
	return func(a *arg) {
		a.path = pa
		a.pathSlice = paSlice
	}
}
Ejemplo n.º 2
0
func (a arg) pathLevelAll() string { return scope.PathJoin(a.pathSlice...) }
Ejemplo n.º 3
0
func (a arg) pathLevel2() string   { return scope.PathJoin(a.pathSlice[:2]...) }