Esempio 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
	}
}
Esempio n. 2
0
// FindGroupByPath searches for a field using the all three path segments.
// If one argument is given then considered as the full path e.g. a/b/c
// If three arguments are given then each argument will be treated as a path part.
func (ss SectionSlice) FindFieldByPath(paths ...string) (*Field, error) {
	if len(paths) == 1 {
		paths = scope.PathSplit(paths[0])
	}
	if len(paths) < 3 {
		return nil, errgo.Mask(ErrFieldNotFound)
	}
	cg, err := ss.FindGroupByPath(paths...)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	return cg.Fields.FindByID(paths[2])
}
Esempio n. 3
0
// FindGroupByPath searches for a group using the first two path segments.
// If one argument is given then considered as the full path e.g. a/b/c
// If two or more arguments are given then each argument will be treated as a path part.
func (ss SectionSlice) FindGroupByPath(paths ...string) (*Group, error) {
	if len(paths) == 1 {
		paths = scope.PathSplit(paths[0])
	}
	if len(paths) < 2 {
		return nil, errgo.Mask(ErrGroupNotFound)
	}
	cs, err := ss.FindByID(paths[0])
	if err != nil {
		return nil, errgo.Mask(err)
	}
	return cs.Groups.FindByID(paths[1])
}