Joomla CMS
4.2.2
Documentation des API du CMS Joomla en version 4.2.2
|
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 | |
Validates options and merges them with default values.
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.
string|string[] | $allowedTypes One or more accepted types |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Références OptionsResolver\$allowedTypes, $option, $this, et OptionsResolver\formatOptions().
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.
string | $option | The option name |
mixed | $allowedValues | One or more acceptable values/closures |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Références OptionsResolver\$allowedValues, $option, $this, et OptionsResolver\formatOptions().
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.
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Références $option, $this, et OptionsResolver\formatOptions().
clear | ( | ) |
Removes all options.
AccessException | If called from a lazy option or normalizer |
Références $this, et Assert\lazy().
count | ( | ) |
Returns the number of set options.
This may be only a subset of the defined options.
AccessException | If accessing this method outside of resolve() |
Référencé par OptionsResolver\offsetGet(), et OptionsResolver\resolve().
define | ( | string | $option | ) |
|
private |
Références $option, $options, $prefix, et null.
Référencé par OptionsResolver\addAllowedTypes(), OptionsResolver\addAllowedValues(), OptionsResolver\addNormalizer(), OptionsResolver\getInfo(), OptionsResolver\offsetGet(), OptionsResolver\resolve(), OptionsResolver\setAllowedTypes(), OptionsResolver\setAllowedValues(), OptionsResolver\setDeprecated(), OptionsResolver\setInfo(), et OptionsResolver\setNormalizer().
|
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 (").
mixed | $value | The value to format as string |
Référencé par OptionsResolver\formatValues(), et OptionsResolver\offsetGet().
|
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.
Références $key, $value, et OptionsResolver\formatValue().
Référencé par OptionsResolver\offsetGet().
getDefinedOptions | ( | ) |
getInfo | ( | string | $option | ) |
Gets the info message for an option.
Références $option, OptionsResolver\formatOptions(), et null.
getMissingOptions | ( | ) |
Returns the names of all options missing a default value.
|
private |
Référencé par OptionsResolver\setDefault().
getRequiredOptions | ( | ) |
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.
Références $option.
isDefined | ( | string | $option | ) |
Returns whether an option is defined.
Returns true for any option passed to setDefault(), setRequired() or setDefined().
isDeprecated | ( | string | $option | ) |
Références $option.
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.
Références $option.
isNested | ( | string | $option | ) |
Références $option.
isPrototype | ( | ) |
isRequired | ( | string | $option | ) |
Returns whether an option is required.
An option is required if it was passed to setRequired().
Références $option.
offsetExists | ( | $option | ) |
offsetGet | ( | $option, | |
bool | $triggerDeprecation = true |
||
) |
Returns the resolved value of an option.
bool | $triggerDeprecation | Whether to trigger the deprecation or not (true by default) |
AccessException | If accessing this method outside of resolve() |
NoSuchOptionException | If the option is not set |
InvalidOptionsException | If the option doesn't fulfill the specified validation rules |
OptionDefinitionException | If 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 | ( | $option, | |
$value | |||
) |
Not supported.
AccessException |
offsetUnset | ( | $option | ) |
Not supported.
AccessException |
remove | ( | $optionNames | ) |
Removes the option with the given name.
Undefined options are ignored.
string|string[] | $optionNames One or more option names |
AccessException | If called from a lazy option or normalizer |
Références $option, $this, et Assert\lazy().
resolve | ( | array | $options = [] | ) |
Merges options with the default values stored in the container and validates them.
Exceptions are thrown if:
UndefinedOptionsException | If an option name is undefined |
InvalidOptionsException | If an option doesn't fulfill the specified validation rules |
MissingOptionsException | If a required option is missing |
OptionDefinitionException | If there is a cyclic dependency between lazy options and/or normalizers |
NoSuchOptionException | If a lazy option reads an unavailable option |
AccessException | If called from a lazy option or normalizer |
Références $option, $options, $this, $value, OptionsResolver\count(), et OptionsResolver\formatOptions().
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.
string|string[] | $allowedTypes One or more accepted types |
UndefinedOptionsException | If the option is undefined |
AccessException | If 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 | ( | 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.
string | $option | The option name |
mixed | $allowedValues | One or more acceptable values/closures |
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Références OptionsResolver\$allowedValues, $option, $this, et OptionsResolver\formatOptions().
Référencé par AbstractConnection\configureOptions().
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'] }
string | $option | The name of the option |
mixed | $value | The default value of the option |
AccessException | If 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 | ( | array | $defaults | ) |
AccessException | If called from a lazy option or normalizer |
Références OptionsResolver\$defaults, $option, $this, $value, et OptionsResolver\setDefault().
Référencé par AbstractConnection\configureOptions(), SessionFactory\configureSessionHandlerOptions(), TaskModel\configureTaskGetterOptions(), et Scheduler\configureTaskRunnerOptions().
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.
string|string[] | $optionNames One or more option names |
AccessException | If called from a lazy option or normalizer |
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.
string | $package | The name of the composer package that is triggering the deprecation |
string | $version | The version of the package that introduced the deprecation |
string | \Closure | $message | The deprecation message to use |
Références $message, $option, $this, $version, et OptionsResolver\formatOptions().
setInfo | ( | string | $option, |
string | $info | ||
) |
Sets an info message for an option.
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Références OptionsResolver\$info, $option, $this, et OptionsResolver\formatOptions().
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.
UndefinedOptionsException | If the option is undefined |
AccessException | If called from a lazy option or normalizer |
Références $option, $this, et OptionsResolver\formatOptions().
setPrototype | ( | bool | $prototype | ) |
Marks the whole options definition as array prototype.
AccessException | If called from a lazy option, a normalizer or a root definition |
Références OptionsResolver\$prototype, $this, et null.
setRequired | ( | $optionNames | ) |
Marks one or more options as required.
string|string[] | $optionNames One or more option names |
AccessException | If called from a lazy option or normalizer |
Référencé par SessionFactory\configureSessionHandlerOptions().
|
private |
Références $type, $val, $value, et null.
Référencé par OptionsResolver\offsetGet().
|
private |
A list of accepted types for each option.
Référencé par OptionsResolver\addAllowedTypes(), et OptionsResolver\setAllowedTypes().
|
private |
A list of accepted values for each option.
Référencé par OptionsResolver\addAllowedValues(), et OptionsResolver\setAllowedValues().
|
private |
A list of lazy options whose closure is currently being called.
This list helps detecting circular dependencies between lazy options.
|
private |
The default option values.
Référencé par OptionsResolver\setDefaults().
|
private |
The names of all defined options.
|
private |
A list of deprecated options.
|
private |
The list of options provided by the user.
|
private |
A list of info messages for each option.
Référencé par OptionsResolver\setInfo().
|
private |
A list of closures for evaluating lazy options.
|
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.
|
private |
|
private |
|
private |
Référencé par OptionsResolver\offsetGet().
|
private |
Whether the whole options definition is marked as array prototype.
Référencé par OptionsResolver\setPrototype().
|
private |
The prototype array's index that is being read.
|
private |
The names of required options.
|
private |
The resolved option values.
|
private |