VirtualIpAddressValidator.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Aug 23, 2018)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators;
  20. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Validators\BaseValidator;
  21. /**
  22. * Description of NumberValidator
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgardne.com>
  25. */
  26. class VirtualIpAddressValidator extends BaseValidator
  27. {
  28. protected $required = false;
  29. protected $public = true;
  30. public function __construct($required = false , $public = true)
  31. {
  32. $this->required = $required;
  33. $this->public = $public;
  34. }
  35. protected function validate($data, $additionalData = null)
  36. {
  37. if (!$this->required && empty($data))
  38. {
  39. return true;
  40. }
  41. if (!filter_var($data, FILTER_VALIDATE_IP))
  42. {
  43. $this->addValidationError('IP Address is not valid', false);
  44. return false;
  45. }
  46. if (!$this->public && filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE))
  47. {
  48. $this->addValidationError('The IP Address is not private', false);
  49. return false;
  50. }
  51. //@todo
  52. // if ($this->required && VmIpAddress::ofIp($data)->count())
  53. // {
  54. // $this->addValidationError('IP Address already exist', false);
  55. // return false;
  56. // }
  57. return true;
  58. }
  59. }