VersionPress\Utils\WpConfigEditor::findPositionForAddingNewDefinition PHP Method

findPositionForAddingNewDefinition() private method

private findPositionForAddingNewDefinition ( $wpConfigContent )
    private function findPositionForAddingNewDefinition($wpConfigContent)
    {
        // https://regex101.com/r/aB8rY4/1
        $thatsAllCommentPattern = "/\\/\\*.*!.*\\*\\//";
        // one-line comment containing exclamation mark
        preg_match($thatsAllCommentPattern, $wpConfigContent, $matches, PREG_OFFSET_CAPTURE);
        if ($matches) {
            return $matches[0][1];
        }
        // https://regex101.com/r/fY6eC6/1
        $ifDefinedAbspathPattern = "/if.*defined.*ABSPATH.*/";
        preg_match($ifDefinedAbspathPattern, $wpConfigContent, $matches, PREG_OFFSET_CAPTURE);
        if ($matches) {
            return $matches[0][1];
        }
        // https://regex101.com/r/vG5rB0/1
        $requireWpSettingsPattern = "/require.*wp-settings/";
        preg_match($requireWpSettingsPattern, $wpConfigContent, $matches, PREG_OFFSET_CAPTURE);
        if ($matches) {
            return $matches[0][1];
        }
        return 0;
    }