www/details_snippet.php
<?php

// Copyright 2020 Catchpoint Systems Inc.
// Use of this source code is governed by the Polyform Shield 1.0.0 license that can be
// found in the LICENSE.md file.

require 'common.inc';
require_once INCLUDES_PATH . '/include/TestInfo.php';
require_once INCLUDES_PATH . '/include/TestStepResult.php';


global $testPath, $run, $cached, $step;  // set in common.inc. This is for IDE to know what exists

$requestedSnippet = $_REQUEST["snippet"];
$useLinks = !GetSetting('nolinks');
$testInfo = TestInfo::fromFiles($testPath);
$stepResult = TestStepResult::fromFiles($testInfo, $run, $cached, $step);

if (!$stepResult->isValid()) {
    echo "No data for test step";
    exit(0);
}

switch ($requestedSnippet) {
    case "waterfall":
        require_once INCLUDES_PATH . '/include/WaterfallViewHtmlSnippet.php';

        $waterfallSnippet = new WaterfallViewHtmlSnippet($testInfo, $stepResult);
        echo $waterfallSnippet->create();
        break;

    case "connection":
        require_once INCLUDES_PATH . '/include/ConnectionViewHtmlSnippet.php';

        $waterfallSnippet = new ConnectionViewHtmlSnippet($testInfo, $stepResult);
        echo $waterfallSnippet->create();
        break;

    case "requestDetails":#
        require_once INCLUDES_PATH . '/include/RequestDetailsHtmlSnippet.php';

        $requestDetailsSnippet = new RequestDetailsHtmlSnippet($testInfo, $stepResult, $useLinks);
        echo $requestDetailsSnippet->create();
        break;

    case "requestHeaders":
        require_once INCLUDES_PATH . '/include/RequestHeadersHtmlSnippet.php';

        $requestHeadersSnippet = new RequestHeadersHtmlSnippet($stepResult, $useLinks);
        echo $requestHeadersSnippet->create();
        break;

    case "mimetypeBreakdown":
        require_once INCLUDES_PATH . '/include/MimetypeBreakdownHtmlSnippet.php';
        $snippetRv = new MimetypeBreakdownHtmlSnippet($testInfo, $stepResult);
        echo $snippetRv->create();
        break;

    case "domainBreakdown":
        require_once INCLUDES_PATH . '/include/DomainBreakdownHtmlSnippet.php';
        $snippetRv = new DomainBreakdownHtmlSnippet($testInfo, $stepResult);
        echo $snippetRv->create();
        break;

    case "performanceOptimization":
        require_once INCLUDES_PATH . '/include/PerformanceOptimizationHtmlSnippet.php';
        $snippet = new PerformanceOptimizationHtmlSnippet($testInfo, $stepResult);
        echo $snippet->create();
        break;

    default:
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found", true, 404);
        exit(0);
}
