質問

モジュールの承認に問題があります。そしてMagento Connect検証レポートは次のメッセージを生成します。

$ _SERVER SUPERGLOBALの直接使用

の代替を使用する方法

$ _サーバ['remote_addr']

Magento 2の

役に立ちましたか?

解決

HELPERクラスを使用する/Magento/Framework/App/Helper/AbstractHelperクラスを拡張するには、次のようにします。

$this->_remoteAddress
.

AbstractHelperクラスコンストラクター:

に設定されています
public function __construct(Context $context)
{
    $this->_moduleManager = $context->getModuleManager();
    $this->_logger = $context->getLogger();
    $this->_request = $context->getRequest();
    $this->_urlBuilder = $context->getUrlBuilder();
    $this->_httpHeader = $context->getHttpHeader();
    $this->_eventManager = $context->getEventManager();
    $this->_remoteAddress = $context->getRemoteAddress();
    $this->_cacheConfig = $context->getCacheConfig();
    $this->urlEncoder = $context->getUrlEncoder();
    $this->urlDecoder = $context->getUrlDecoder();
    $this->scopeConfig = $context->getScopeConfig();
}
.

/Magento/Framework/App/Helper/Context.phpクラスから来ています:

/**
 * @return \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress
 */
public function getRemoteAddress()
{
    return $this->_remoteAddress;
}
.

とそれは\Magento\Framework\HTTP\PhpEnvironment\RemoteAddressのインスタンスです:

/**
 * Retrieve Client Remote Address
 *
 * @param bool $ipToLong converting IP to long format
 * @return string IPv4|long
 */
public function getRemoteAddress($ipToLong = false)
{
    if ($this->remoteAddress === null) {
        foreach ($this->alternativeHeaders as $var) {
            if ($this->request->getServer($var, false)) {
                $this->remoteAddress = $this->request->getServer($var);
                break;
            }
        }

        if (!$this->remoteAddress) {
            $this->remoteAddress = $this->request->getServer('REMOTE_ADDR');
        }
    }

    if (!$this->remoteAddress) {
        return false;
    }

    return $ipToLong ? ip2long($this->remoteAddress) : $this->remoteAddress;
}
.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top