classDomSource
final class DomSource
implements SourceExtension
Selects elements of HTML, XML, IETF XML and Markdown sources with CSS selectors.
Markdown is rendered to HTML first. XML may not declare a DTD or entities. An evidence selector may also be an exact Text Fragment within an HTML scope. A selection may not contain both an element and one of its descendants.
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 elements a CSS selector or Text Fragment identifies.
Parameters
$source | Source | The source declaration |
$selector | string | A CSS selector, or an exact Text Fragment within the HTML scope |
$directory | string | The configuration directory |
$live | bool | Whether to read the current URI instead of a pinned snapshot |
Returns
list<Unit> One unit per element, located by its node pathThrows
CommonMarkException When a Markdown source cannot be renderedRuntimeException When the source is unsafe or malformed, a fragment is misused or ancestors and descendants are selected togetherTest cases 20
DomSourceTest::testSelectAcceptsHtmlDoctypecallsDomSourceTest::testSelectAcceptsSiblingsSharingALocationPrefixcallsDomSourceTest::testSelectAcceptsSiblingsSharingAnIndexPrefixcallsDomSourceTest::testSelectDirectiveSelectsEveryUnitWithTheTextcallsDomSourceTest::testSelectDirectiveStillRejectsNestedScopescallsDomSourceTest::testSelectExactDirectiveLocatesTheSameUnitAsCssWithoutChangingTheScopecallsDomSourceTest::testSelectLeavesNoXmlErrorsBehindcallsDomSourceTest::testSelectLocatesUnitsByNodePathWithNormalizedTextcallsDomSourceTest::testSelectMarkdownIsRenderedSafelycallsDomSourceTest::testSelectReadsThroughTheGivenLoadercallsDomSourceTest::testSelectRejectsDirectivesBeforeReadingTheSourcecallsDomSourceTest::testSelectRejectsDirectivesOutsideHtmlcallsDomSourceTest::testSelectRejectsDtdAndEntityDeclarationscallsDomSourceTest::testSelectRejectsMalformedXmlcallsDomSourceTest::testSelectRejectsNestedCoverageUnitscallsDomSourceTest::testSelectRestoresInternalXmlErrorHandlingcallsDomSourceTest::testSelectStableDistinctUnitscallsDomSourceTest::testSelectTextDirectivesCannotReplaceTheCoverageScopecallsDomSourceTest::testSelectVerifiesSnapshotHashcallsDomSourceTest::testSelectXmlEntitiesAreRejectedcalls
Calls 21
- static-call TextFragment::isFragment() line 48
- static-call TextFragment::text() line 48
- new
RuntimeExceptionline 50 - method-call ResourceLoader::read() line 52
- new
Crawlerline 53 - function-call
in_arrayline 54 - function-call
striposline 55 - new
DOMDocumentline 58 - function-call
libxml_use_internal_errorsline 59 - method-call
DOMDocument::loadXML()line 61 - function-call
libxml_clear_errorsline 63 - method-call
Crawler::addDocument()line 69 - method-call
CommonMarkConverter::convert()line 72 - new
CommonMarkConverterline 72 - method-call
Crawler::addHtmlContent()line 74 - method-call
Crawler::filter()line 77 - new Unit line 81
- static-call Unit::normalize() line 81
- function-call
str_starts_withline 87 - function-call
array_valuesline 92 - function-call
array_filterline 92
Private surface 1§
Implementation details, listed for orientation only.
private ResourceLoader $loader = new \Requirements\Source\ResourceLoader()Test cases 34§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 20
DomSourceTest::testSelectAcceptsHtmlDoctypecallsDomSourceTest::testSelectAcceptsSiblingsSharingALocationPrefixcallsDomSourceTest::testSelectAcceptsSiblingsSharingAnIndexPrefixcallsDomSourceTest::testSelectDirectiveSelectsEveryUnitWithTheTextcallsDomSourceTest::testSelectDirectiveStillRejectsNestedScopescallsDomSourceTest::testSelectExactDirectiveLocatesTheSameUnitAsCssWithoutChangingTheScopecallsDomSourceTest::testSelectLeavesNoXmlErrorsBehindcallsDomSourceTest::testSelectLocatesUnitsByNodePathWithNormalizedTextcallsDomSourceTest::testSelectMarkdownIsRenderedSafelycallsDomSourceTest::testSelectReadsThroughTheGivenLoadercallsDomSourceTest::testSelectRejectsDirectivesBeforeReadingTheSourcecallsDomSourceTest::testSelectRejectsDirectivesOutsideHtmlcallsDomSourceTest::testSelectRejectsDtdAndEntityDeclarationscallsDomSourceTest::testSelectRejectsMalformedXmlcallsDomSourceTest::testSelectRejectsNestedCoverageUnitscallsDomSourceTest::testSelectRestoresInternalXmlErrorHandlingcallsDomSourceTest::testSelectStableDistinctUnitscallsDomSourceTest::testSelectTextDirectivesCannotReplaceTheCoverageScopecallsDomSourceTest::testSelectVerifiesSnapshotHashcallsDomSourceTest::testSelectXmlEntitiesAreRejectedcalls
Other tests reaching this symbol 14
LoaderTestcallsMarkdownDocumentTestcallsApplicationTestcallsCommandHandlerTestcallsCommandLineTestcallsExecutorTestcallsFormatterTestcallsAnalyzerTestcallsCoverageTestcallsEvidenceMatcherTestcallsSnapshotTestcallsRegistryTest::providerGetBuiltIncallsRegistryTest::testGetConfiguredExtensionReplacesABuiltIncallsVerifierTestcalls