_cfgsource

package
v0.0.0-...-02de949 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package deprecated source provides a slice type for handling config sources to be used in config/models.

In Mage world this is called ToOptionArray() or ToOptionHash().

Index

Constants

View Source
const (
	NotNullString uint8 = iota + 1
	NotNullInt
	NotNullFloat64
	NotNullBool
)

NotNull* are specifying which type has a non null value

Variables

View Source
var EnableDisable = NewByBool(Bools{
	{false, "Disable"},
	{true, "Enable"},
})

EnableDisable defines an immutable slice with enable and disable options.

View Source
var Protocol = MustNewByString(
	"", "",
	"http", "HTTP (unsecure)",
	"https", "HTTP (TLS)",
)

Protocol defines an immutable slice with available HTTP protocols

View Source
var YesNo = NewByBool(Bools{
	{false, "No"},
	{true, "Yes"},
})

YesNo defines an immutable slice with yes and no options.

Functions

This section is empty.

Types

type Bools

type Bools []struct {
	Value bool
	Label string
}

Bools a slice only used as argument to NewByBool.

type F64s

type F64s []struct {
	Value float64
	Label string
}

F64s a slice only used as argument to NewByFloat64.

type Ints

type Ints []struct {
	Value int
	Label string
}

Ints a slice only used as argument to NewByInt.

type Optioner

type Optioner interface {
	Options() Slice
}

Optioner defines how to retrieve all Options values. Mostly used for frontend output. @see site/lib/internal/Magento/Framework/Data/OptionSourceInterface.php

type Pair

type Pair struct {
	// NotNull defines which type is not null
	NotNull uint8
	String  string  `json:"-"`
	Int     int     `json:"-"`
	Float64 float64 `json:"-"`
	Bool    bool    `json:"-"`
	// contains filtered or unexported fields
}

Pair contains a different typed values and a label for printing in a browser. Especially useful for JS API and in total for value validation.

func (Pair) Label

func (p Pair) Label() string

Label returns the label and if empty the Value().

func (Pair) MarshalJSON

func (p Pair) MarshalJSON() ([]byte, error)

MarshalJSON encodes a pair into JSON

func (*Pair) UnmarshalJSON

func (p *Pair) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a pair from JSON

func (Pair) Value

func (p Pair) Value() string

Value returns the underlying value as a string

type Slice

type Slice []Pair

Slice type is returned by the SourceModel.Options() interface

func MustNewByString

func MustNewByString(vl ...string) Slice

MustNewByString same as NewByString but panics on error.

func NewByBool

func NewByBool(vl Bools) Slice

NewByBool creates a new slice with bool values

func NewByFloat64

func NewByFloat64(vl F64s) Slice

NewByFloat64 creates a new slice with float64 values

func NewByInt

func NewByInt(vl Ints) Slice

NewByInt creates a new slice with integer values

func NewByIntValue

func NewByIntValue(values ...int) Slice

NewByIntValue all passed arguments are values.

func NewByString

func NewByString(vl ...string) (Slice, error)

NewByString creates a new ValueLabelSlice (VLS) from key,value list. It panics when arguments are imbalanced. Example:

mySlice := NewValueLabelSlice("http", "HTTP (unsecure)", "https", "HTTPS (TLS)")

Error behaviour: NotValid.

func NewByStringValue

func NewByStringValue(values ...string) Slice

NewByStringValue all passed arguments are values.

func (Slice) ContainsLabel

func (s Slice) ContainsLabel(l string) bool

ContainsLabel checks if k has an entry as a label.

func (Slice) ContainsValBool

func (s Slice) ContainsValBool(k bool) bool

ContainsValBool checks if value k exists.

func (Slice) ContainsValFloat64

func (s Slice) ContainsValFloat64(k float64) bool

ContainsValFloat64 checks if value k exists.

func (Slice) ContainsValInt

func (s Slice) ContainsValInt(k int) bool

ContainsValInt checks if value k exists.

func (Slice) ContainsValString

func (s Slice) ContainsValString(k string) bool

ContainsValString checks if value k exists.

func (Slice) IndexLabel

func (s Slice) IndexLabel(l string) int

IndexLabel checks if label l exists and returns its first position. Returns -1 when the label was not found.

func (Slice) IndexValBool

func (s Slice) IndexValBool(k bool) int

IndexValBool checks if value k exists and returns its position. Returns -1 when the value was not found.

func (Slice) IndexValFloat64

func (s Slice) IndexValFloat64(k float64) int

IndexValFloat64 checks if value k exists and returns its position. Returns -1 when the value was not found.

func (Slice) IndexValInt

func (s Slice) IndexValInt(k int) int

IndexValInt checks if value k exists and returns its position. Returns -1 when the value was not found.

func (Slice) IndexValString

func (s Slice) IndexValString(k string) int

IndexValString checks if value k exists and returns its position. Returns -1 when the value was not found.

func (Slice) Len

func (s Slice) Len() int

Len returns the length of the slice

func (*Slice) Merge

func (s *Slice) Merge(sl Slice) Slice

Merge integrates the argument Slice into the receiver slice and overwrites the existing values of the receiver slice.

func (Slice) SortByBool

func (s Slice) SortByBool(direction int) Slice

SortByBool sorts by field Bool in asc = 0 or desc != 0 direction

func (Slice) SortByFloat64

func (s Slice) SortByFloat64(direction int) Slice

SortByFloat64 sorts by field Float64 in asc = 0 or desc != 0 direction

func (Slice) SortByInt

func (s Slice) SortByInt(direction int) Slice

SortByInt sorts by field Int in asc = 0 or desc != 0 direction

func (Slice) SortByLabel

func (s Slice) SortByLabel(direction int) Slice

SortByLabel sorts by label in asc = 0 or desc != 0 direction

func (Slice) SortByValue

func (s Slice) SortByValue(direction int) Slice

SortByValue sorts by value in asc = 0 or desc != 0 direction. The underlying value will be converted to a string. You might expect strange results when sorting integers or other non-strings.

func (Slice) String

func (s Slice) String() string

String converts the slice to JSON or returns an error string

func (Slice) Swap

func (s Slice) Swap(i, j int)

Swap swaps elements. Will panic when slice index does not exists.

func (Slice) ToJSON

func (s Slice) ToJSON() (string, error)

ToJSON returns a JSON string, convenience function.

func (*Slice) Unique

func (s *Slice) Unique() Slice

Unique removes duplicate entries.

Jump to

Keyboard shortcuts

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