class Parser extends ParserBase

Properties

protected array $config from  ParserBase
protected Parser $parser from  ParserBase
static protected Client $client
static protected string|null $clientCacheDir

Methods

__construct(Parser $parser, array $config)

Constructor

void
setUp()

Plugin's setup

void
parse(string $text, array $matches)

No description

static void
filterTag(Tag $tag, Parser $tagStack, array $hosts, array $sites, string|null $cacheDir)

Filter a MEDIA tag

static bool
addNamedCaptures(array $attributes, string $string, array $regexps)

Add named captures from a set of regular expressions to a set of attributes

static Tag
createTag(string $tagName, Parser $tagStack, Tag $tag)

Create a tag for a media embed

static array
getAttributes(string $url, array $config, string|null $cacheDir)

Return a set of attributes for given URL based on a site's config

static Client
getHttpClient(string|null $cacheDir)

Return a cached instance of the HTTP client

static string
getSiteIdFromUrl(string $url, array $hosts)

Return the siteId that corresponds to given URL

static string
interpolateVars(string $str, array $vars)

Interpolate {@vars} in given string

static void
scrape(array $attributes, string $url, array $config, string|null $cacheDir)

Scrape values and add them to current attributes

static string
wget(string $url, string|null $cacheDir, array $config)

Retrieve external content

Details

in ParserBase at line 30
final __construct(Parser $parser, array $config)

Constructor

Parameters

Parser $parser
array $config

in ParserBase at line 43
protected void setUp()

Plugin's setup

Return Value

void

at line 30
void parse(string $text, array $matches)

No description

Parameters

string $text
array $matches

If the config array has a "regexp" key, the corresponding matches are passed as second parameter. Otherwise, an empty array is passed

Return Value

void

at line 57
static void filterTag(Tag $tag, Parser $tagStack, array $hosts, array $sites, string|null $cacheDir)

Filter a MEDIA tag

This will always invalidate the original tag, and possibly replace it with the tag that corresponds to the media site

Parameters

Tag $tag

The original tag

Parser $tagStack

Parser instance, so that we can add the new tag to the stack

array $hosts

Map of [hostname => siteId]

array $sites

Map of [siteId => siteConfig]

string|null $cacheDir

Path to the cache directory

Return Value

void

at line 85
static protected bool addNamedCaptures(array $attributes, string $string, array $regexps)

Add named captures from a set of regular expressions to a set of attributes

Parameters

array $attributes

Associative array of strings

string $string

Text to match

array $regexps

List of [regexp, map] pairs

Return Value

bool

Whether any regexp matched

at line 111
static protected Tag createTag(string $tagName, Parser $tagStack, Tag $tag)

Create a tag for a media embed

Parameters

string $tagName

Tag's name

Parser $tagStack
Tag $tag

Reference tag

Return Value

Tag

New tag

at line 139
static protected array getAttributes(string $url, array $config, string|null $cacheDir)

Return a set of attributes for given URL based on a site's config

Parameters

string $url

Original URL

array $config

Site config

string|null $cacheDir

Path to the cache directory

Return Value

array

Associative array of attributes

at line 157
static protected Client getHttpClient(string|null $cacheDir)

Return a cached instance of the HTTP client

Parameters

string|null $cacheDir

Return Value

Client

at line 175
static protected string getSiteIdFromUrl(string $url, array $hosts)

Return the siteId that corresponds to given URL

Parameters

string $url

Original URL

array $hosts

Map of [hostname => siteId]

Return Value

string

URL's siteId, or an empty string

at line 197
static protected string interpolateVars(string $str, array $vars)

Interpolate {@vars} in given string

Parameters

string $str

Original string

array $vars

Associative array

Return Value

string

Interpolated string

at line 218
static protected void scrape(array $attributes, string $url, array $config, string|null $cacheDir)

Scrape values and add them to current attributes

Parameters

array $attributes Attributes
string $url

Original URL

array $config

Scraping config

string|null $cacheDir

Path to the cache directory

Return Value

void

at line 243
static protected string wget(string $url, string|null $cacheDir, array $config)

Retrieve external content

Parameters

string $url URL
string|null $cacheDir

Path to the cache directory

array $config

Scraping config

Return Value

string

Response body