OptionsResolverInterface.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\OptionsResolver;
  11. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  12. use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
  13. use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
  14. /**
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. *
  17. * @deprecated since version 2.6, to be removed in 3.0. Use {@link OptionsResolver} instead.
  18. */
  19. interface OptionsResolverInterface
  20. {
  21. /**
  22. * Sets default option values.
  23. *
  24. * The options can either be values of any types or closures that
  25. * evaluate the option value lazily. These closures must have one
  26. * of the following signatures:
  27. *
  28. * <code>
  29. * function (Options $options)
  30. * function (Options $options, $value)
  31. * </code>
  32. *
  33. * The second parameter passed to the closure is the previously
  34. * set default value, in case you are overwriting an existing
  35. * default value.
  36. *
  37. * The closures should return the lazily created option value.
  38. *
  39. * @param array $defaultValues A list of option names as keys and default
  40. * values or closures as values
  41. *
  42. * @return $this
  43. */
  44. public function setDefaults(array $defaultValues);
  45. /**
  46. * Replaces default option values.
  47. *
  48. * Old defaults are erased, which means that closures passed here cannot
  49. * access the previous default value. This may be useful to improve
  50. * performance if the previous default value is calculated by an expensive
  51. * closure.
  52. *
  53. * @param array $defaultValues A list of option names as keys and default
  54. * values or closures as values
  55. *
  56. * @return $this
  57. */
  58. public function replaceDefaults(array $defaultValues);
  59. /**
  60. * Sets optional options.
  61. *
  62. * This method declares valid option names without setting default values for them.
  63. * If these options are not passed to {@link resolve()} and no default has been set
  64. * for them, they will be missing in the final options array. This can be helpful
  65. * if you want to determine whether an option has been set or not because otherwise
  66. * {@link resolve()} would trigger an exception for unknown options.
  67. *
  68. * @param array $optionNames A list of option names
  69. *
  70. * @return $this
  71. */
  72. public function setOptional(array $optionNames);
  73. /**
  74. * Sets required options.
  75. *
  76. * If these options are not passed to {@link resolve()} and no default has been set for
  77. * them, an exception will be thrown.
  78. *
  79. * @param array $optionNames A list of option names
  80. *
  81. * @return $this
  82. */
  83. public function setRequired($optionNames);
  84. /**
  85. * Sets allowed values for a list of options.
  86. *
  87. * @param array $allowedValues A list of option names as keys and arrays
  88. * with values acceptable for that option as
  89. * values
  90. *
  91. * @return $this
  92. *
  93. * @throws InvalidOptionsException if an option has not been defined
  94. * (see {@link isKnown()}) for which
  95. * an allowed value is set
  96. */
  97. public function setAllowedValues($allowedValues);
  98. /**
  99. * Adds allowed values for a list of options.
  100. *
  101. * The values are merged with the allowed values defined previously.
  102. *
  103. * @param array $allowedValues A list of option names as keys and arrays
  104. * with values acceptable for that option as
  105. * values
  106. *
  107. * @return $this
  108. *
  109. * @throws InvalidOptionsException if an option has not been defined
  110. * (see {@link isKnown()}) for which
  111. * an allowed value is set
  112. */
  113. public function addAllowedValues($allowedValues);
  114. /**
  115. * Sets allowed types for a list of options.
  116. *
  117. * @param array $allowedTypes A list of option names as keys and type
  118. * names passed as string or array as values
  119. *
  120. * @return $this
  121. *
  122. * @throws InvalidOptionsException if an option has not been defined for
  123. * which an allowed type is set
  124. */
  125. public function setAllowedTypes($allowedTypes);
  126. /**
  127. * Adds allowed types for a list of options.
  128. *
  129. * The types are merged with the allowed types defined previously.
  130. *
  131. * @param array $allowedTypes A list of option names as keys and type
  132. * names passed as string or array as values
  133. *
  134. * @return $this
  135. *
  136. * @throws InvalidOptionsException if an option has not been defined for
  137. * which an allowed type is set
  138. */
  139. public function addAllowedTypes($allowedTypes);
  140. /**
  141. * Sets normalizers that are applied on resolved options.
  142. *
  143. * The normalizers should be closures with the following signature:
  144. *
  145. * <code>
  146. * function (Options $options, $value)
  147. * </code>
  148. *
  149. * The second parameter passed to the closure is the value of
  150. * the option.
  151. *
  152. * The closure should return the normalized value.
  153. *
  154. * @param array $normalizers An array of closures
  155. *
  156. * @return $this
  157. */
  158. public function setNormalizers(array $normalizers);
  159. /**
  160. * Returns whether an option is known.
  161. *
  162. * An option is known if it has been passed to either {@link setDefaults()},
  163. * {@link setRequired()} or {@link setOptional()} before.
  164. *
  165. * @param string $option The name of the option
  166. *
  167. * @return bool Whether the option is known
  168. */
  169. public function isKnown($option);
  170. /**
  171. * Returns whether an option is required.
  172. *
  173. * An option is required if it has been passed to {@link setRequired()},
  174. * but not to {@link setDefaults()}. That is, the option has been declared
  175. * as required and no default value has been set.
  176. *
  177. * @param string $option The name of the option
  178. *
  179. * @return bool Whether the option is required
  180. */
  181. public function isRequired($option);
  182. /**
  183. * Returns the combination of the default and the passed options.
  184. *
  185. * @param array $options The custom option values
  186. *
  187. * @return array A list of options and their values
  188. *
  189. * @throws InvalidOptionsException if any of the passed options has not
  190. * been defined or does not contain an
  191. * allowed value
  192. * @throws MissingOptionsException if a required option is missing
  193. * @throws OptionDefinitionException if a cyclic dependency is detected
  194. * between two lazy options
  195. */
  196. public function resolve(array $options = array());
  197. }