Postcode.php 786 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model\Address\Validator;
  7. class Postcode
  8. {
  9. /**
  10. * @var \Magento\Directory\Helper\Data
  11. */
  12. protected $directoryHelper;
  13. /**
  14. * @param \Magento\Directory\Helper\Data $directoryHelper
  15. */
  16. public function __construct(\Magento\Directory\Helper\Data $directoryHelper)
  17. {
  18. $this->directoryHelper = $directoryHelper;
  19. }
  20. /**
  21. * Check if postcode is valid
  22. *
  23. * @param string $countryId
  24. * @param string $postcode
  25. * @return bool
  26. */
  27. public function isValid($countryId, $postcode)
  28. {
  29. return $this->directoryHelper->isZipCodeOptional($countryId) || !empty($postcode);
  30. }
  31. }