[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/symfony/options-resolver/ -> OptionsResolver.php (summary)

(no description)

File Size: 1347 lines (46 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

OptionsResolver:: (38 methods):
  setDefault()
  setDefaults()
  hasDefault()
  setRequired()
  isRequired()
  getRequiredOptions()
  isMissing()
  getMissingOptions()
  setDefined()
  isDefined()
  getDefinedOptions()
  isNested()
  setDeprecated()
  isDeprecated()
  setNormalizer()
  addNormalizer()
  setAllowedValues()
  addAllowedValues()
  setAllowedTypes()
  addAllowedTypes()
  define()
  setInfo()
  getInfo()
  setPrototype()
  isPrototype()
  remove()
  clear()
  resolve()
  offsetGet()
  verifyTypes()
  offsetExists()
  offsetSet()
  offsetUnset()
  count()
  formatValue()
  formatValues()
  formatOptions()
  getParameterClassName()


Class: OptionsResolver  - X-Ref

Validates options and merges them with default values.

setDefault(string $option, $value)   X-Ref
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 {@link resolve()} is called. The
closure has access to the resolved values of other options through the
passed {@link 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 {@link 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: string $option The name of the option
param: mixed  $value  The default value of the option
return: $this

setDefaults(array $defaults)   X-Ref

return: $this

hasDefault(string $option)   X-Ref
Returns whether a default value is set for an option.

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

return: bool

setRequired($optionNames)   X-Ref
Marks one or more options as required.

param: string|string[] $optionNames One or more option names
return: $this

isRequired(string $option)   X-Ref
Returns whether an option is required.

An option is required if it was passed to {@link setRequired()}.

return: bool

getRequiredOptions()   X-Ref
Returns the names of all required options.

return: string[]

isMissing(string $option)   X-Ref
Returns whether an option is missing a default value.

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

return: bool

getMissingOptions()   X-Ref
Returns the names of all options missing a default value.

return: string[]

setDefined($optionNames)   X-Ref
Defines a valid option name.

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

param: string|string[] $optionNames One or more option names
return: $this

isDefined(string $option)   X-Ref
Returns whether an option is defined.

Returns true for any option passed to {@link setDefault()},
{@link setRequired()} or {@link setDefined()}.

return: bool

getDefinedOptions()   X-Ref
Returns the names of all defined options.

return: string[]

isNested(string $option)   X-Ref
No description

setDeprecated(string $option)   X-Ref
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 {@link resolve()} is called. The parameter
passed to the closure is the value of the option after validating it
and before normalizing it.

param: string          $package The name of the composer package that is triggering the deprecation
param: string          $version The version of the package that introduced the deprecation
param: string|\Closure $message The deprecation message to use
return: $this

isDeprecated(string $option)   X-Ref
No description

setNormalizer(string $option, \Closure $normalizer)   X-Ref
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 {@link resolve()} is called. The closure
has access to the resolved values of other options through the passed
{@link 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.

return: $this

addNormalizer(string $option, \Closure $normalizer, bool $forcePrepend = false)   X-Ref
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 {@link resolve()} is called. The closure
has access to the resolved values of other options through the passed
{@link 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.

return: $this

setAllowedValues(string $option, $allowedValues)   X-Ref
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: string $option        The option name
param: mixed  $allowedValues One or more acceptable values/closures
return: $this

addAllowedValues(string $option, $allowedValues)   X-Ref
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: string $option        The option name
param: mixed  $allowedValues One or more acceptable values/closures
return: $this

setAllowedTypes(string $option, $allowedTypes)   X-Ref
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: string|string[] $allowedTypes One or more accepted types
return: $this

addAllowedTypes(string $option, $allowedTypes)   X-Ref
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: string|string[] $allowedTypes One or more accepted types
return: $this

define(string $option)   X-Ref
Defines an option configurator with the given name.


setInfo(string $option, string $info)   X-Ref
Sets an info message for an option.

return: $this

getInfo(string $option)   X-Ref
Gets the info message for an option.


setPrototype(bool $prototype)   X-Ref
Marks the whole options definition as array prototype.

return: $this

isPrototype()   X-Ref
No description

remove($optionNames)   X-Ref
Removes the option with the given name.

Undefined options are ignored.

param: string|string[] $optionNames One or more option names
return: $this

clear()   X-Ref
Removes all options.

return: $this

resolve(array $options = [])   X-Ref
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.

return: array

offsetGet($option, bool $triggerDeprecation = true)   X-Ref
Returns the resolved value of an option.

param: bool $triggerDeprecation Whether to trigger the deprecation or not (true by default)
return: mixed

verifyTypes(string $type, $value, array &$invalidTypes, int $level = 0)   X-Ref
No description

offsetExists($option)   X-Ref
Returns whether a resolved option with the given name exists.

param: string $option The option name
return: bool

offsetSet($option, $value)   X-Ref
Not supported.

return: void

offsetUnset($option)   X-Ref
Not supported.

return: void

count()   X-Ref
Returns the number of set options.

This may be only a subset of the defined options.

return: int

formatValue($value)   X-Ref
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: mixed $value The value to format as string

formatValues(array $values)   X-Ref
Returns a string representation of a list of values.

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


formatOptions(array $options)   X-Ref
No description

getParameterClassName(\ReflectionParameter $parameter)   X-Ref
No description



Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer