classJsonSource
final class JsonSource
implements SourceExtension
Selects values of a JSON source with a subset of JSONPath.
A string value is its own text; any other value is its JSON encoding. Units are located by their JSON Pointer.
Methods§
public function __construct(private ResourceLoader $loader = new \Requirements\Source\ResourceLoader())Parameters
$loader | ResourceLoader | Reads the source document |
Calls 1
public function select(
Source $source,
string $selector,
string $directory,
bool $live,
): list<Unit>Selects the values a JSONPath matches.
Parameters
$source | Source | The source declaration |
$selector | string | The JSONPath |
$directory | string | The configuration directory |
$live | bool | Whether to read the current URI instead of a pinned snapshot |
Returns
list<Unit> One unit per matched value, located as json:POINTERThrows
JsonException When the source is not JSONRuntimeException When the path is unsupported or the source cannot be readTest cases 7
JsonSourceTest::testSelectAcceptsTheNestingLimitcallsJsonSourceTest::testSelectLocatesUnitsByJsonPointercallsJsonSourceTest::testSelectReadsThroughTheGivenLoadercallsJsonSourceTest::testSelectRejectsDocumentsNestedBeyondTheLimitcallsJsonSourceTest::testSelectRejectsInvalidJsoncallsJsonSourceTest::testSelectRejectsUnsupportedJsonPathInsteadOfSilentlySelectingcallsJsonSourceTest::testSelectStableDistinctUnitscalls
Calls 9
- function-call
json_decodeline 43 - method-call ResourceLoader::read() line 43
- method-call JsonPath::select() line 45
- new JsonPath line 45
- function-call
is_stringline 46 - function-call
json_encodeline 46 - new Unit line 47
- static-call Unit::normalize() line 47
- function-call
array_valuesline 49
Private surface 1§
Implementation details, listed for orientation only.
private ResourceLoader $loader = new \Requirements\Source\ResourceLoader()Test cases 20§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
JsonSourceTest::testSelectAcceptsTheNestingLimitcallsJsonSourceTest::testSelectLocatesUnitsByJsonPointercallsJsonSourceTest::testSelectReadsThroughTheGivenLoadercallsJsonSourceTest::testSelectRejectsDocumentsNestedBeyondTheLimitcallsJsonSourceTest::testSelectRejectsInvalidJsoncallsJsonSourceTest::testSelectRejectsUnsupportedJsonPathInsteadOfSilentlySelectingcallsJsonSourceTest::testSelectStableDistinctUnitscalls
Other tests reaching this symbol 13
LoaderTestcallsMarkdownDocumentTestcallsApplicationTestcallsCommandHandlerTestcallsCommandLineTestcallsExecutorTestcallsFormatterTestcallsAnalyzerTestcallsCoverageTestcallsEvidenceMatcherTestcallsSnapshotTestcallsRegistryTest::providerGetBuiltIncallsVerifierTestcalls