SelectorSyntaxMatcher
extends AbstractMatcher
in package
Block a HTML element by CSS-like selectors, e.g. `div[class="my-class"]`.
Table of Contents
Constants
- DATA_FORCE_RESULT = 'SelectorSyntaxMatcher.forceResult'
- Allows to force-use this result for the blocking mechanism. This allows to block elements already through the `addSelectorSyntaxMap()` functionality.
Properties
- $blockable : mixed
- $blockAutomatically : mixed
- $headlessContentBlocker : mixed
Methods
- __construct() : mixed
- C'tor.
- applyConsentAttributes() : mixed
- Create HTML attributes for the content blocker.
- calculateAllKeepAttributes() : array<string|int, string>
- Calculate all keep-attributes from plugins and configuration.
- createPlainResultFromMatch() : mixed
- Create a basic `BlockedResult` from an `AbstractMatch`.
- createResult() : BlockedResult
- See `AbstractMatcher`.
- getBlockable() : mixed
- Getter.
- getBlockables() : array<string|int, AbstractBlockable>
- Getter.
- getHeadlessContentBlocker() : mixed
- Getter.
- isBlockAutomatically() : mixed
- Getter.
- iterateBlockablesInString() : mixed
- Iterate our blockables in a given string and save results to the `BlockedResult`.
- match() : BlockedResult
- See `AbstractMatcher`.
- probablyDisableDueToSkipped() : mixed
- Disable blocked result if it has the skipped-attribute.
- applyCheckResultHooks() : mixed
- Allows to run hooks on a blocked result instance.
- applyCommonAttributes() : mixed
- Apply common attributes for our blocked element:
- applyNewLinkElement() : mixed
- Prepare the new transformed link attribute.
- applyReplaceAlwaysAttributes() : mixed
- Replace all known attributes which should be always replaced.
- applyVisualParent() : mixed
- Prepare visual parent depending on class.
- prepareChunksFromString() : mixed
- Prepare chunks cause `pcre.jit` can lead to `PREG_JIT_STACKLIMIT_ERROR` errors In a customer scenario, it lead to an error with a string length of `8191`.
Constants
DATA_FORCE_RESULT
Allows to force-use this result for the blocking mechanism. This allows to block elements already through the `addSelectorSyntaxMap()` functionality.
public
mixed
DATA_FORCE_RESULT
= 'SelectorSyntaxMatcher.forceResult'
Properties
$blockable
private
mixed
$blockable
$blockAutomatically
private
mixed
$blockAutomatically
$headlessContentBlocker
private
mixed
$headlessContentBlocker
Methods
__construct()
C'tor.
public
__construct(HeadlessContentBlocker $headlessContentBlocker, AbstractBlockable $blockable[, bool $blockAutomatically = true ]) : mixed
Parameters
- $headlessContentBlocker : HeadlessContentBlocker
- $blockable : AbstractBlockable
- $blockAutomatically : bool = true
-
By default a selector-syntax matcher automatically blocks the found matches
applyConsentAttributes()
Create HTML attributes for the content blocker.
public
applyConsentAttributes(BlockedResult $result, AbstractMatch $match) : mixed
Parameters
- $result : BlockedResult
- $match : AbstractMatch
calculateAllKeepAttributes()
Calculate all keep-attributes from plugins and configuration.
public
calculateAllKeepAttributes(AbstractMatch $match) : array<string|int, string>
Parameters
- $match : AbstractMatch
Return values
array<string|int, string>createPlainResultFromMatch()
Create a basic `BlockedResult` from an `AbstractMatch`.
public
createPlainResultFromMatch(AbstractMatch $match) : mixed
Parameters
- $match : AbstractMatch
createResult()
See `AbstractMatcher`.
public
createResult(SelectorSyntaxMatch $match) : BlockedResult
Parameters
- $match : SelectorSyntaxMatch
Return values
BlockedResultgetBlockable()
Getter.
public
getBlockable() : mixed
getBlockables()
Getter.
public
getBlockables() : array<string|int, AbstractBlockable>
Return values
array<string|int, AbstractBlockable>getHeadlessContentBlocker()
Getter.
public
getHeadlessContentBlocker() : mixed
isBlockAutomatically()
Getter.
public
isBlockAutomatically() : mixed
Tags
iterateBlockablesInString()
Iterate our blockables in a given string and save results to the `BlockedResult`.
public
iterateBlockablesInString(BlockedResult $result, string $string[, bool $useContainsRegularExpression = false ][, bool $multilineRegexp = false ][, array<string|int, string> $useRegularExpressionFromMap = null ][, AbstractBlockable $useBlockables = null ]) : mixed
Parameters
- $result : BlockedResult
- $string : string
- $useContainsRegularExpression : bool = false
- $multilineRegexp : bool = false
- $useRegularExpressionFromMap : array<string|int, string> = null
- $useBlockables : AbstractBlockable = null
match()
See `AbstractMatcher`.
public
match(SelectorSyntaxMatch $match) : BlockedResult
Parameters
- $match : SelectorSyntaxMatch
Return values
BlockedResultprobablyDisableDueToSkipped()
Disable blocked result if it has the skipped-attribute.
public
probablyDisableDueToSkipped(BlockedResult $result, AbstractMatch $match) : mixed
Parameters
- $result : BlockedResult
- $match : AbstractMatch
applyCheckResultHooks()
Allows to run hooks on a blocked result instance.
protected
applyCheckResultHooks(BlockedResult $result, AbstractMatch $match) : mixed
Parameters
- $result : BlockedResult
- $match : AbstractMatch
applyCommonAttributes()
Apply common attributes for our blocked element:
protected
applyCommonAttributes(BlockedResult $result, AbstractMatch $match[, string $linkAttribute = null ][, string $link = null ]) : mixed
- Visual parent
- Replaced link attribute (optional)
- Consent attributes depending on blocked item (
consent-required
, ...) - Replace always attributes
Parameters
- $result : BlockedResult
- $match : AbstractMatch
- $linkAttribute : string = null
- $link : string = null
applyNewLinkElement()
Prepare the new transformed link attribute.
protected
applyNewLinkElement(AbstractMatch $match, string $linkAttribute, string $link) : mixed
Parameters
- $match : AbstractMatch
- $linkAttribute : string
- $link : string
applyReplaceAlwaysAttributes()
Replace all known attributes which should be always replaced.
protected
applyReplaceAlwaysAttributes(AbstractMatch $match) : mixed
Parameters
- $match : AbstractMatch
applyVisualParent()
Prepare visual parent depending on class.
protected
applyVisualParent(AbstractMatch $match) : mixed
Parameters
- $match : AbstractMatch
prepareChunksFromString()
Prepare chunks cause `pcre.jit` can lead to `PREG_JIT_STACKLIMIT_ERROR` errors In a customer scenario, it lead to an error with a string length of `8191`.
protected
prepareChunksFromString(string $string[, int $maxChunkLength = 5000 ][, int $copySiblingChunkStringLength = 100 ]) : mixed
As we are using preg_match
we need to ensure, that the blockable expression can find
strings between two chunks (yeah, this can happen). So, add a small part of the previous
and next chunk ($copySiblingChunkStringLength
).
Parameters
- $string : string
- $maxChunkLength : int = 5000
- $copySiblingChunkStringLength : int = 100