InvalidArgumentException.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Assert
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * If you did not receive a copy of the license and are unable to
  10. * obtain it through the world-wide-web, please send an email
  11. * to kontakt@beberlei.de so I can send you a copy immediately.
  12. */
  13. namespace Assert;
  14. class InvalidArgumentException extends \InvalidArgumentException implements AssertionFailedException
  15. {
  16. /**
  17. * @var string|null
  18. */
  19. private $propertyPath;
  20. /**
  21. * @var mixed
  22. */
  23. private $value;
  24. /**
  25. * @var array
  26. */
  27. private $constraints;
  28. public function __construct($message, $code, ?string $propertyPath = null, $value = null, array $constraints = [])
  29. {
  30. parent::__construct($message, $code);
  31. $this->propertyPath = $propertyPath;
  32. $this->value = $value;
  33. $this->constraints = $constraints;
  34. }
  35. /**
  36. * User controlled way to define a sub-property causing
  37. * the failure of a currently asserted objects.
  38. *
  39. * Useful to transport information about the nature of the error
  40. * back to higher layers.
  41. *
  42. * @return string|null
  43. */
  44. public function getPropertyPath()
  45. {
  46. return $this->propertyPath;
  47. }
  48. /**
  49. * Get the value that caused the assertion to fail.
  50. *
  51. * @return mixed
  52. */
  53. public function getValue()
  54. {
  55. return $this->value;
  56. }
  57. /**
  58. * Get the constraints that applied to the failed assertion.
  59. */
  60. public function getConstraints(): array
  61. {
  62. return $this->constraints;
  63. }
  64. }