Skip to content

specialLocations object

A specialLocations object defines locations of special significance to SARIF consumers.

specialLocations object

Tip

Generated with following command : php ./resources/serialize.php specialLocations docs/assets/sarif 192

docs/assets/sarif/specialLocations.json
{
    "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
    "version": "2.1.0",
    "runs": [
        {
            "tool": {
                "driver": {
                    "name": "CodeScanner",
                    "semanticVersion": "1.1.2-beta.12",
                    "informationUri": "https://codeScanner.dev"
                }
            },
            "originalUriBaseIds": {
                "WEBHOST": {
                    "uri": "http://www.example.com/"
                },
                "ROOT": {
                    "uri": "file:///"
                },
                "HOME": {
                    "uri": "home/user/",
                    "uriBaseId": "ROOT"
                },
                "PACKAGE": {
                    "uri": "mySoftware/",
                    "uriBaseId": "HOME"
                },
                "SRC": {
                    "uri": "src/",
                    "uriBaseId": "PACKAGE"
                }
            },
            "specialLocations": {
                "displayBase": {
                    "uriBaseId": "PACKAGE"
                }
            },
            "results": []
        }
    ]
}
examples/specialLocations.php
<?php declare(strict_types=1);
/**
 * This file is part of the Sarif-PHP-SDK package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Laurent Laville
 */

use Bartlett\Sarif\Definition\ArtifactLocation;
use Bartlett\Sarif\Definition\Run;
use Bartlett\Sarif\Definition\SpecialLocations;
use Bartlett\Sarif\Definition\Tool;
use Bartlett\Sarif\Definition\ToolComponent;
use Bartlett\Sarif\SarifLog;

require_once dirname(__DIR__) . '/vendor/autoload.php';

$driver = new ToolComponent();
$driver->setName('CodeScanner');
$driver->setInformationUri('https://codeScanner.dev');
$driver->setSemanticVersion('1.1.2-beta.12');

$tool = new Tool();
$tool->setDriver($driver);

$webHost = new ArtifactLocation();
$webHost->setUri('http://www.example.com/');

$root = new ArtifactLocation();
$root->setUri('file:///');

$home = new ArtifactLocation();
$home->setUri('home/user/');
$home->setUriBaseId('ROOT');

$package = new ArtifactLocation();
$package->setUri('mySoftware/');
$package->setUriBaseId('HOME');

$src = new ArtifactLocation();
$src->setUri('src/');
$src->setUriBaseId('PACKAGE');

$run = new Run();
$run->setTool($tool);
$run->addAdditionalProperties([
    'WEBHOST' => $webHost,
    'ROOT' => $root,
    'HOME' => $home,
    'PACKAGE' => $package,
    'SRC' => $src,
]);

$specialLocations = new SpecialLocations();
$artifactLocation = new ArtifactLocation();
$artifactLocation->setUri('');
$artifactLocation->setUriBaseId('PACKAGE');
$specialLocations->setDisplayBase($artifactLocation);

$run->setSpecialLocations($specialLocations);

$log = new SarifLog([$run]);

Note

This alternative API is available since release 1.5.0

examples/builder/specialLocations.php
<?php declare(strict_types=1);
/**
 * This file is part of the Sarif-PHP-SDK package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Laurent Laville
 */

require_once dirname(__DIR__, 2) . '/vendor/autoload.php';

use Bartlett\Sarif\Factory\BuilderFactory;

$factory = new BuilderFactory();

// @link https://github.com/llaville/sarif-php-sdk/blob/1.1/docs/reference/specialLocations.md
$spec = $factory->specification('2.1.0')
    ->addRun(
        $factory->run()
            ->tool(
                $factory->tool()
                    ->driver(
                        $factory->driver()
                            ->name('CodeScanner')
                            ->semanticVersion('1.1.2-beta.12')
                            ->informationUri('https://codeScanner.dev')
                    )
            )
            ->addOriginalUriBaseId(
                'WEBHOST',
                $factory->artifactLocation()
                    ->uri('http://www.example.com/')
            )
            ->addOriginalUriBaseId(
                'ROOT',
                $factory->artifactLocation()
                    ->uri('file:///')
            )
            ->addOriginalUriBaseId(
                'HOME',
                $factory->artifactLocation()
                    ->uri('home/user/')
                    ->uriBaseId('ROOT')
            )
            ->addOriginalUriBaseId(
                'PACKAGE',
                $factory->artifactLocation()
                    ->uri('mySoftware/')
                    ->uriBaseId('HOME')
            )
            ->addOriginalUriBaseId(
                'SRC',
                $factory->artifactLocation()
                    ->uri('src/')
                    ->uriBaseId('PACKAGE')
            )
            ->specialLocations(
                $factory->specialLocations()
                    ->displayBase(
                        $factory->artifactLocation()
                            ->uriBaseId('PACKAGE')
                    )
            )
    )
;