Model/Config.php
private function getDesignExceptions()
    {
        $result = '';
        $tpl = "        %s (req.http.user-agent ~ \"%s\") {\n" . "            set req.hash += \"%s\";\n" . "        }";

        $expressions = $this->_scopeConfig->getValue(
            self::XML_VARNISH_PAGECACHE_DESIGN_THEME_REGEX,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
        if ($expressions) {
            try {
                $expressions = unserialize($expressions); // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode
            } catch (\Exception $e) {
                $expressions = [];
            }
            $rules = array_values($expressions);
            foreach ($rules as $i => $rule) {
                if (preg_match('/^[\W]{1}(.*)[\W]{1}(\w+)?$/', $rule['regexp'], $matches)) {
                    if (!empty($matches[2])) {
                        $pattern = sprintf("(?%s)%s", $matches[2], $matches[1]);
                    } else {
                        $pattern = $matches[1];
                    }
                    $if = $i == 0 ? 'if' : ' elsif';
                    $result .= sprintf($tpl, $if, $pattern, $rule['value']);
                }
            }
        }

        if (!empty($result)) {
            $result = 'if (req.url ~ "^/(pub/)?(media|static)/.*") {' . "\n" . $result . "\n    }";
        }

        return $result;
    }
private function getDesignExceptions()
    {
        $result = '';
        $tpl = "        %s (req.http.user-agent ~ \"%s\") {\n" . "            set req.hash += \"%s\";\n" . "        }";

        $expressions = $this->_scopeConfig->getValue(
            self::XML_VARNISH_PAGECACHE_DESIGN_THEME_REGEX,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
        if ($expressions) {
            try {
                $expressions = unserialize($expressions); // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode
            } catch (\Exception $e) {
                $expressions = [];
            }
            $rules = array_values($expressions);
            foreach ($rules as $i => $rule) {
                if (preg_match('/^[\W]{1}(.*)[\W]{1}(\w+)?$/', $rule['regexp'], $matches)) {
                    if (!empty($matches[2])) {
                        $pattern = sprintf("(?%s)%s", $matches[2], $matches[1]);
                    } else {
                        $pattern = $matches[1];
                    }
                    $if = $i == 0 ? 'if' : ' elsif';
                    $result .= sprintf($tpl, $if, $pattern, $rule['value']);
                }
            }
        }

        if (!empty($result)) {
            $result = 'if (req.url ~ "^/(pub/)?(media|static)/.*") {' . "\n" . $result . "\n    }";
        }

        return $result;
    }
private function getDesignExceptions ( ) { $ result = '' ; $ tpl = "        %s (req.http.user-agent ~ \"%s\") {\n" . "            set req.hash += \"%s\";\n" . "        }" ; $ expressions = $ this -> _scopeConfig -> getValue ( self :: XML_VARNISH_PAGECACHE_DESIGN_THEME_REGEX , \ Magento \ Store \ Model \ ScopeInterface :: SCOPE_STORE ) ; if ( $ expressions ) { try { $ expressions = unserialize ( $ expressions ) ; // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode } catch ( \ Exception $ e ) { $ expressions = [ ] ; } $ rules = array_values ( $ expressions ) ; foreach ( $ rules as $ i => $ rule ) { if ( preg_match ( '/^[\W]{1}(.*)[\W]{1}(\w+)?$/' , $ rule [ 'regexp' ] , $ matches ) ) { if ( ! empty ( $ matches [ 2 ] ) ) { $ pattern = sprintf ( "(?%s)%s" , $ matches [ 2 ] , $ matches [ 1 ] ) ; } else { $ pattern = $ matches [ 1 ] ; } $ if = $ i == 0 ? 'if' : ' elsif' ; $ result .= sprintf ( $ tpl , $ if , $ pattern , $ rule [ 'value' ] ) ; } } } if ( ! empty ( $ result ) ) { $ result = 'if (req.url ~ "^/(pub/)?(media|static)/.*") {' . "\n" . $ result . "\n    }" ; } return $ result ; }
Get regexs for design exceptions
Different browser user-agents may use different themes
Varnish supports regex with internal modifiers only so
we have to convert "/pattern/iU" into "(?Ui)pattern"

@return string
Get regexs for design exceptions Different browser user - agents may use different themes Varnish supports regex with internal modifiers only so we have to convert / pattern / iU into ( ?Ui ) pattern