Joomla CMS  4.2.2
Documentation des API du CMS Joomla en version 4.2.2
Référence de la classe OptionsResolver
+ Graphe d'héritage de OptionsResolver:

Fonctions membres publiques

 setDefault (string $option, $value)
 
 setDefaults (array $defaults)
 
 hasDefault (string $option)
 
 setRequired ($optionNames)
 
 isRequired (string $option)
 
 getRequiredOptions ()
 
 isMissing (string $option)
 
 getMissingOptions ()
 
 setDefined ($optionNames)
 
 isDefined (string $option)
 
 getDefinedOptions ()
 
 isNested (string $option)
 
 setDeprecated (string $option)
 
 isDeprecated (string $option)
 
 setNormalizer (string $option, \Closure $normalizer)
 
 addNormalizer (string $option, \Closure $normalizer, bool $forcePrepend=false)
 
 setAllowedValues (string $option, $allowedValues)
 
 addAllowedValues (string $option, $allowedValues)
 
 setAllowedTypes (string $option, $allowedTypes)
 
 addAllowedTypes (string $option, $allowedTypes)
 
 define (string $option)
 
 setInfo (string $option, string $info)
 
 getInfo (string $option)
 
 setPrototype (bool $prototype)
 
 isPrototype ()
 
 remove ($optionNames)
 
 clear ()
 
 resolve (array $options=[])
 
 offsetGet ($option, bool $triggerDeprecation=true)
 
 offsetExists ($option)
 
 offsetSet ($option, $value)
 
 offsetUnset ($option)
 
 count ()
 

Fonctions membres privées

 verifyTypes (string $type, $value, array &$invalidTypes, int $level=0)
 
 formatValue ($value)
 
 formatValues (array $values)
 
 formatOptions (array $options)
 
 getParameterClassName (\ReflectionParameter $parameter)
 

Attributs privés

const VALIDATION_FUNCTIONS
 
const $defined = []
 
 $defaults = []
 
 $nested = []
 
 $required = []
 
 $resolved = []
 
 $normalizers = []
 
 $allowedValues = []
 
 $allowedTypes = []
 
 $info = []
 
 $lazy = []
 
 $calling = []
 
 $deprecated = []
 
 $given = []
 
 $locked = false
 
 $parentsOptions = []
 
 $prototype
 
 $prototypeIndex
 

Description détaillée

Validates options and merges them with default values.

Auteur
Bernhard Schussek bschu.nosp@m.ssek.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Tobias Schultze http://tobion.de

Documentation des fonctions membres

◆ addAllowedTypes()

addAllowedTypes ( string  $option,
  $allowedTypes 
)

Adds allowed types for an option.

The types are merged with the allowed types defined previously.

Any type for which a corresponding is_<type>() function exists is acceptable. Additionally, fully-qualified class or interface names may be passed.

Paramètres
string|string[]$allowedTypes One or more accepted types
Renvoie
$this
Exceptions
UndefinedOptionsExceptionIf the option is undefined
AccessExceptionIf called from a lazy option or normalizer

Références OptionsResolver\$allowedTypes, $option, $this, et OptionsResolver\formatOptions().

◆ addAllowedValues()

addAllowedValues ( string  $option,
  $allowedValues 
)

Adds allowed values for an option.

The values are merged with the allowed values defined previously.

Instead of passing values, you may also pass a closures with the following signature:

function ($value) {
    // return true or false
}

The closure receives the value as argument and should return true to accept the value and false to reject the value.

Paramètres
string$optionThe option name
mixed$allowedValuesOne or more acceptable values/closures
Renvoie
$this
Exceptions
UndefinedOptionsExceptionIf the option is undefined
AccessExceptionIf called from a lazy option or normalizer

Références OptionsResolver\$allowedValues, $option, $this, et OptionsResolver\formatOptions().

◆ addNormalizer()

addNormalizer ( string  $option,
\Closure  $normalizer,
bool  $forcePrepend = false 
)

Adds a normalizer for an option.

The normalizer should be a closure with the following signature:

function (Options $options, $value): mixed {
    // ...
}

The closure is invoked when resolve() is called. The closure has access to the resolved values of other options through the passed Options instance.

The second parameter passed to the closure is the value of the option.

The resolved option value is set to the return value of the closure.

Renvoie
$this
Exceptions
UndefinedOptionsExceptionIf the option is undefined
AccessExceptionIf called from a lazy option or normalizer

Références $option, $this, et OptionsResolver\formatOptions().

◆ clear()

clear ( )

Removes all options.

Renvoie
$this
Exceptions
AccessExceptionIf called from a lazy option or normalizer

Références $this, et Assert\lazy().

◆ count()

count ( )

Returns the number of set options.

This may be only a subset of the defined options.

Renvoie
int
Exceptions
AccessExceptionIf accessing this method outside of resolve()
Voir également
::count()

Référencé par OptionsResolver\offsetGet(), et OptionsResolver\resolve().

◆ define()

define ( string  $option)

Defines an option configurator with the given name.

Références $option, et $this.

◆ formatOptions()

◆ formatValue()

formatValue (   $value)
private

Returns a string representation of the value.

This method returns the equivalent PHP tokens for most scalar types (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped in double quotes (").

Paramètres
mixed$valueThe value to format as string

Références $value, et null.

Référencé par OptionsResolver\formatValues(), et OptionsResolver\offsetGet().

◆ formatValues()

formatValues ( array  $values)
private

Returns a string representation of a list of values.

Each of the values is converted to a string using formatValue(). The values are then concatenated with commas.

Voir également
formatValue()

Références $key, $value, et OptionsResolver\formatValue().

Référencé par OptionsResolver\offsetGet().

◆ getDefinedOptions()

getDefinedOptions ( )

Returns the names of all defined options.

Renvoie
string[]
Voir également
isDefined()

◆ getInfo()

getInfo ( string  $option)

Gets the info message for an option.

Références $option, OptionsResolver\formatOptions(), et null.

◆ getMissingOptions()

getMissingOptions ( )

Returns the names of all options missing a default value.

Renvoie
string[]

◆ getParameterClassName()

getParameterClassName ( \ReflectionParameter  $parameter)
private

Références $type, et null.

Référencé par OptionsResolver\setDefault().

◆ getRequiredOptions()

getRequiredOptions ( )

Returns the names of all required options.

Renvoie
string[]
Voir également
isRequired()

◆ hasDefault()

hasDefault ( string  $option)

Returns whether a default value is set for an option.

Returns true if setDefault() was called for this option. An option is also considered set if it was set to null.

Renvoie
bool

Références $option.

◆ isDefined()

isDefined ( string  $option)

Returns whether an option is defined.

Returns true for any option passed to setDefault(), setRequired() or setDefined().

Renvoie
bool

◆ isDeprecated()

isDeprecated ( string  $option)

Références $option.

◆ isMissing()

isMissing ( string  $option)

Returns whether an option is missing a default value.

An option is missing if it was passed to setRequired(), but not to setDefault(). This option must be passed explicitly to resolve(), otherwise an exception will be thrown.

Renvoie
bool

Références $option.

◆ isNested()

isNested ( string  $option)

Références $option.

◆ isPrototype()

isPrototype ( )

◆ isRequired()

isRequired ( string  $option)

Returns whether an option is required.

An option is required if it was passed to setRequired().

Renvoie
bool

Références $option.

◆ offsetExists()

offsetExists (   $option)

Returns whether a resolved option with the given name exists.

Paramètres
string$optionThe option name
Renvoie
bool
Exceptions
AccessExceptionIf accessing this method outside of resolve()
Voir également
::offsetExists()

Références $option.

◆ offsetGet()

offsetGet (   $option,
bool  $triggerDeprecation = true 
)

Returns the resolved value of an option.

Paramètres
bool$triggerDeprecationWhether to trigger the deprecation or not (true by default)
Renvoie
mixed
Exceptions
AccessExceptionIf accessing this method outside of resolve()
NoSuchOptionExceptionIf the option is not set
InvalidOptionsExceptionIf the option doesn't fulfill the specified validation rules
OptionDefinitionExceptionIf there is a cyclic dependency between lazy options and/or normalizers

Références $item, $message, $option, OptionsResolver\$parentsOptions, $this, $type, $value, OptionsResolver\count(), OptionsResolver\formatOptions(), OptionsResolver\formatValue(), OptionsResolver\formatValues(), Assert\lazy(), null, et OptionsResolver\verifyTypes().

◆ offsetSet()

offsetSet (   $option,
  $value 
)

Not supported.

Renvoie
void
Exceptions
AccessException

◆ offsetUnset()

offsetUnset (   $option)

Not supported.

Renvoie
void
Exceptions
AccessException

◆ remove()

remove (   $optionNames)

Removes the option with the given name.

Undefined options are ignored.

Paramètres
string|string[]$optionNames One or more option names
Renvoie
$this
Exceptions
AccessExceptionIf called from a lazy option or normalizer

Références $option, $this, et Assert\lazy().

◆ resolve()

resolve ( array  $options = [])

Merges options with the default values stored in the container and validates them.

Exceptions are thrown if:

  • Undefined options are passed;
  • Required options are missing;
  • Options have invalid types;
  • Options have invalid values.
Renvoie
array
Exceptions
UndefinedOptionsExceptionIf an option name is undefined
InvalidOptionsExceptionIf an option doesn't fulfill the specified validation rules
MissingOptionsExceptionIf a required option is missing
OptionDefinitionExceptionIf there is a cyclic dependency between lazy options and/or normalizers
NoSuchOptionExceptionIf a lazy option reads an unavailable option
AccessExceptionIf called from a lazy option or normalizer

Références $option, $options, $this, $value, OptionsResolver\count(), et OptionsResolver\formatOptions().

◆ setAllowedTypes()

setAllowedTypes ( string  $option,
  $allowedTypes 
)

Sets allowed types for an option.

Any type for which a corresponding is_<type>() function exists is acceptable. Additionally, fully-qualified class or interface names may be passed.

Paramètres
string|string[]$allowedTypes One or more accepted types
Renvoie
$this
Exceptions
UndefinedOptionsExceptionIf the option is undefined
AccessExceptionIf called from a lazy option or normalizer

Références OptionsResolver\$allowedTypes, $option, $this, et OptionsResolver\formatOptions().

Référencé par AbstractConnection\configureOptions(), Connection\configureOptions(), et SessionFactory\configureSessionHandlerOptions().

◆ setAllowedValues()

setAllowedValues ( string  $option,
  $allowedValues 
)

Sets allowed values for an option.

Instead of passing values, you may also pass a closures with the following signature:

function ($value) {
    // return true or false
}

The closure receives the value as argument and should return true to accept the value and false to reject the value.

Paramètres
string$optionThe option name
mixed$allowedValuesOne or more acceptable values/closures
Renvoie
$this
Exceptions
UndefinedOptionsExceptionIf the option is undefined
AccessExceptionIf called from a lazy option or normalizer

Références OptionsResolver\$allowedValues, $option, $this, et OptionsResolver\formatOptions().

Référencé par AbstractConnection\configureOptions().

◆ setDefault()

setDefault ( string  $option,
  $value 
)

Sets the default value of a given option.

If the default value should be set based on other options, you can pass a closure with the following signature:

function (Options $options) {
    // ...
}

The closure will be evaluated when resolve() is called. The closure has access to the resolved values of other options through the passed Options instance:

function (Options $options) {
    if (isset($options['port'])) {
        // ...
    }
}

If you want to access the previously set default value, add a second argument to the closure's signature:

$options->setDefault('name', 'Default Name');

$options->setDefault('name', function (Options $options, $previousValue) {
    // 'Default Name' === $previousValue
});

This is mostly useful if the configuration of the Options object is spread across different locations of your code, such as base and sub-classes.

If you want to define nested options, you can pass a closure with the following signature:

$options->setDefault('database', function (OptionsResolver $resolver) {
    $resolver->setDefined(['dbname', 'host', 'port', 'user', 'pass']);
}

To get access to the parent options, add a second argument to the closure's signature:

function (OptionsResolver $resolver, Options $parent) {
    // 'default' === $parent['connection']
}
Paramètres
string$optionThe name of the option
mixed$valueThe default value of the option
Renvoie
$this
Exceptions
AccessExceptionIf called from a lazy option or normalizer

Références $option, $params, $this, $type, $value, class, OptionsResolver\getParameterClassName(), Assert\lazy(), et null.

Référencé par AbstractConnection\configureOptions(), Connection\configureOptions(), et OptionsResolver\setDefaults().

◆ setDefaults()

setDefaults ( array  $defaults)

◆ setDefined()

setDefined (   $optionNames)

Defines a valid option name.

Defines an option name without setting a default value. The option will be accepted when passed to resolve(). When not passed, the option will not be included in the resolved options.

Paramètres
string|string[]$optionNames One or more option names
Renvoie
$this
Exceptions
AccessExceptionIf called from a lazy option or normalizer

Références $option, et $this.

◆ setDeprecated()

setDeprecated ( string  $option)

Deprecates an option, allowed types or values.

Instead of passing the message, you may also pass a closure with the following signature:

function (Options $options, $value): string {
    // ...
}

The closure receives the value as argument and should return a string. Return an empty string to ignore the option deprecation.

The closure is invoked when resolve() is called. The parameter passed to the closure is the value of the option after validating it and before normalizing it.

Paramètres
string$packageThe name of the composer package that is triggering the deprecation
string$versionThe version of the package that introduced the deprecation
string | \Closure$messageThe deprecation message to use
Renvoie
$this

Références $message, $option, $this, $version, et OptionsResolver\formatOptions().

◆ setInfo()

setInfo ( string  $option,
string  $info 
)

Sets an info message for an option.

Renvoie
$this
Exceptions
UndefinedOptionsExceptionIf the option is undefined
AccessExceptionIf called from a lazy option or normalizer

Références OptionsResolver\$info, $option, $this, et OptionsResolver\formatOptions().

◆ setNormalizer()

setNormalizer ( string  $option,
\Closure  $normalizer 
)

Sets the normalizer for an option.

The normalizer should be a closure with the following signature:

function (Options $options, $value) {
    // ...
}

The closure is invoked when resolve() is called. The closure has access to the resolved values of other options through the passed Options instance.

The second parameter passed to the closure is the value of the option.

The resolved option value is set to the return value of the closure.

Renvoie
$this
Exceptions
UndefinedOptionsExceptionIf the option is undefined
AccessExceptionIf called from a lazy option or normalizer

Références $option, $this, et OptionsResolver\formatOptions().

◆ setPrototype()

setPrototype ( bool  $prototype)

Marks the whole options definition as array prototype.

Renvoie
$this
Exceptions
AccessExceptionIf called from a lazy option, a normalizer or a root definition

Références OptionsResolver\$prototype, $this, et null.

◆ setRequired()

setRequired (   $optionNames)

Marks one or more options as required.

Paramètres
string|string[]$optionNames One or more option names
Renvoie
$this
Exceptions
AccessExceptionIf called from a lazy option or normalizer

Références $option, et $this.

Référencé par SessionFactory\configureSessionHandlerOptions().

◆ verifyTypes()

verifyTypes ( string  $type,
  $value,
array &  $invalidTypes,
int  $level = 0 
)
private

Références $type, $val, $value, et null.

Référencé par OptionsResolver\offsetGet().

Documentation des champs

◆ $allowedTypes

$allowedTypes = []
private

A list of accepted types for each option.

Référencé par OptionsResolver\addAllowedTypes(), et OptionsResolver\setAllowedTypes().

◆ $allowedValues

$allowedValues = []
private

A list of accepted values for each option.

Référencé par OptionsResolver\addAllowedValues(), et OptionsResolver\setAllowedValues().

◆ $calling

$calling = []
private

A list of lazy options whose closure is currently being called.

This list helps detecting circular dependencies between lazy options.

◆ $defaults

$defaults = []
private

The default option values.

Référencé par OptionsResolver\setDefaults().

◆ $defined

const $defined = []
private

The names of all defined options.

◆ $deprecated

$deprecated = []
private

A list of deprecated options.

◆ $given

$given = []
private

The list of options provided by the user.

◆ $info

$info = []
private

A list of info messages for each option.

Référencé par OptionsResolver\setInfo().

◆ $lazy

$lazy = []
private

A list of closures for evaluating lazy options.

◆ $locked

$locked = false
private

Whether the instance is locked for reading.

Once locked, the options cannot be changed anymore. This is necessary in order to avoid inconsistencies during the resolving process. If any option is changed after being read, all evaluated lazy options that depend on this option would become invalid.

◆ $nested

$nested = []
private

◆ $normalizers

$normalizers = []
private

◆ $parentsOptions

$parentsOptions = []
private

Référencé par OptionsResolver\offsetGet().

◆ $prototype

$prototype
private

Whether the whole options definition is marked as array prototype.

Référencé par OptionsResolver\setPrototype().

◆ $prototypeIndex

$prototypeIndex
private

The prototype array's index that is being read.

◆ $required

$required = []
private

The names of required options.

◆ $resolved

$resolved = []
private

The resolved option values.

◆ VALIDATION_FUNCTIONS

const VALIDATION_FUNCTIONS
private
Valeur initiale :
= [
'bool' => 'is_bool'

La documentation de cette classe a été générée à partir du fichier suivant :