Data.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Developer\Helper;
  7. /**
  8. * Developer config data helper
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Data extends \Magento\Framework\App\Helper\AbstractHelper
  14. {
  15. /**
  16. * Dev allow ips config path
  17. */
  18. const XML_PATH_DEV_ALLOW_IPS = 'dev/restrict/allow_ips';
  19. /**
  20. * Check if the client remote address is allowed developer ip
  21. *
  22. * @param string|null $storeId
  23. * @return bool
  24. */
  25. public function isDevAllowed($storeId = null)
  26. {
  27. $allow = true;
  28. $allowedIps = $this->scopeConfig->getValue(
  29. self::XML_PATH_DEV_ALLOW_IPS,
  30. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  31. $storeId
  32. );
  33. $remoteAddr = $this->_remoteAddress->getRemoteAddress();
  34. if (!empty($allowedIps) && !empty($remoteAddr)) {
  35. $allowedIps = preg_split('#\s*,\s*#', $allowedIps, null, PREG_SPLIT_NO_EMPTY);
  36. if (array_search($remoteAddr, $allowedIps) === false
  37. && array_search($this->_httpHeader->getHttpHost(), $allowedIps) === false
  38. ) {
  39. $allow = false;
  40. }
  41. }
  42. return $allow;
  43. }
  44. }