IpException.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. declare(strict_types=1);
  7. namespace Respect\Validation\Exceptions;
  8. /**
  9. * @author Alexandre Gomes Gaigalas <alganet@gmail.com>
  10. * @author Danilo Benevides <danilobenevides01@gmail.com>
  11. * @author Henrique Moody <henriquemoody@gmail.com>
  12. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  13. */
  14. final class IpException extends ValidationException
  15. {
  16. public const NETWORK_RANGE = 'network_range';
  17. /**
  18. * {@inheritDoc}
  19. */
  20. protected $defaultTemplates = [
  21. self::MODE_DEFAULT => [
  22. self::STANDARD => '{{name}} 必须是IP地址',
  23. self::NETWORK_RANGE => '{{name}} 必须是 {{range}} 范围内的IP地址',
  24. ],
  25. self::MODE_NEGATIVE => [
  26. self::STANDARD => '{{name}} 不能是IP地址',
  27. self::NETWORK_RANGE => '{{name}} 不能是 {{range}} 范围内的IP地址',
  28. ],
  29. ];
  30. /**
  31. * {@inheritDoc}
  32. */
  33. protected function chooseTemplate(): string
  34. {
  35. if (!$this->getParam('range')) {
  36. return self::STANDARD;
  37. }
  38. return self::NETWORK_RANGE;
  39. }
  40. }