Callbacks.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Wikimedia\ParamValidator;
  3. use Psr\Http\Message\UploadedFileInterface;
  4. /**
  5. * Interface defining callbacks needed by ParamValidator
  6. *
  7. * The user of ParamValidator is expected to pass an object implementing this
  8. * interface to ParamValidator's constructor.
  9. *
  10. * All methods in this interface accept an "options array". This is the same `$options`
  11. * passed to ParamValidator::getValue(), ParamValidator::validateValue(), and the like
  12. * and is intended for communication of non-global state.
  13. *
  14. * @since 1.34
  15. * @unstable
  16. */
  17. interface Callbacks {
  18. /**
  19. * Test if a parameter exists in the request
  20. * @param string $name Parameter name
  21. * @param array $options Options array
  22. * @return bool True if present, false if absent.
  23. * Return false for file upload parameters.
  24. */
  25. public function hasParam( $name, array $options );
  26. /**
  27. * Fetch a value from the request
  28. *
  29. * Return `$default` for file-upload parameters.
  30. *
  31. * @param string $name Parameter name to fetch
  32. * @param mixed $default Default value to return if the parameter is unset.
  33. * @param array $options Options array
  34. * @return string|string[]|mixed A string or string[] if the parameter was found,
  35. * or $default if it was not.
  36. */
  37. public function getValue( $name, $default, array $options );
  38. /**
  39. * Test if a parameter exists as an upload in the request
  40. * @param string $name Parameter name
  41. * @param array $options Options array
  42. * @return bool True if present, false if absent.
  43. */
  44. public function hasUpload( $name, array $options );
  45. /**
  46. * Fetch data for a file upload
  47. * @param string $name Parameter name of the upload
  48. * @param array $options Options array
  49. * @return UploadedFileInterface|null Uploaded file, or null if there is no file for $name.
  50. */
  51. public function getUploadedFile( $name, array $options );
  52. /**
  53. * Record non-fatal conditions.
  54. * @param ValidationException $condition
  55. * @param array $options Options array
  56. */
  57. public function recordCondition( ValidationException $condition, array $options );
  58. /**
  59. * Indicate whether "high limits" should be used.
  60. *
  61. * Some settings have multiple limits, one for "normal" users and a higher
  62. * one for "privileged" users. This is used to determine which class the
  63. * current user is in when necessary.
  64. *
  65. * @param array $options Options array
  66. * @return bool Whether the current user is privileged to use high limits
  67. */
  68. public function useHighLimits( array $options );
  69. }