class ResultFilter

This class is used to filter the results of a query on a data source with the 'return path' defined in the source.

The return path can be a JSONPath or XPath expression, a CSS selector or a line and column number.

Properties

private array $functions
private array $phpfunctions

Methods

void
__construct()

Constructor of class ResultFilter

static mixed|null
filter(string $format, mixed $result, string $path, array $namespaces = array(), string $separator = ",", string $delimiter = "")

Filters the results of a query on a data source with the 'return path' defined in the source.

array
filterJSON(mixed $json, string $path)

Filters the JSON results of a query on a data source with the 'return path' defined in the source.

mixed
filterCSV(string $csv, string $path, string $separator, string $delimiter)

Filters the CSV results of a query on a data source with the 'return path' defined in the source.

array
filterHTML(Crawler $crawler, string $path, array $namespaces = array())

Filters the HTML results of a query on a data source with the 'return path' defined in the source.

array
filterXML(Crawler $crawler, string $path, array $namespaces = array())

Filters the XML results of a query on a data source with the 'return path' defined in the source.

string
replacePathFunctions(string $path)

Replaces the php functions in an XPath expression with the syntax required for their executions

createXML(string $node_name, array $arr = array())

Converts an array to a XML DOM document

string
bool2str(bool $v)

Converts a true/false (boolean) value to a string

bool
isValidTagName(string $tag)

Determines whether the given tag name is valid or not.

convertToXML(DomDocument $dom, string $node_name, array $arr = array())

Converts an array to a XML DOM node of a DOM document

array
createArray(DOMNodeList $xml)

Creates and returns an array from a list of XML DOM node

void
replaceTextKeys(array $array)

Replaces all '#text' keys of the given array by the corresponding text

bool
nodeHasChild(DOMNode $node)

Determines whether a DOM node has at least one DOM element as child.

array
convertToArray(DOMNodeList|DOMNode $xml)

Converts a list of XML DOM node to an array

array
xPathFilter(string $root, array $array, string $path)

Filters an array with an XPath expression

array
xPathDOMFilter(DOMDocument $doc, string $path, array $namespaces = array())

Filters an XML DOM document with an XPath expression and converts it to an array

static array|string
xml2array(array|object $xml)

Converts an array of SimpleXMLElement to an associative array

static int|null
timestamp(string $format, string $dateStr)

Parses a date string according to the given format and returns its timestamp

Details

at line 171
void __construct()

Constructor of class ResultFilter

Return Value

void

at line 188
static mixed|null filter(string $format, mixed $result, string $path, array $namespaces = array(), string $separator = ",", string $delimiter = "")

Filters the results of a query on a data source with the 'return path' defined in the source.

Parameters

string $format The result type (json, csv, html or xml)
mixed $result The results of a query
string $path The return path defined in the source.
array $namespaces (default: array() The list of namespaces if the result is in xml or html format
string $separator The field separator if the result is in csv format
string $delimiter The field delimiter if the result is in csv format

Return Value

mixed|null The filtered result

at line 214
protected array filterJSON(mixed $json, string $path)

Filters the JSON results of a query on a data source with the 'return path' defined in the source.

The return path is a JSONPath or a XPath expression

Parameters

mixed $json The JSON results
string $path The return path defined in the source.

Return Value

array The filtered result

at line 241
protected mixed filterCSV(string $csv, string $path, string $separator, string $delimiter)

Filters the CSV results of a query on a data source with the 'return path' defined in the source.

The return path is in the form "line number/column number"

Parameters

string $csv The CSV results
string $path The return path defined in the source.
string $separator The field separator
string $delimiter The field delimiter

Return Value

mixed The filtered result

at line 275
protected array filterHTML(Crawler $crawler, string $path, array $namespaces = array())

Filters the HTML results of a query on a data source with the 'return path' defined in the source.

The return path is a XPath expression or a CSS selector

Parameters

Crawler $crawler The HTML results
string $path The return path defined in the source.
array $namespaces (default: array() The list of namespaces

Return Value

array The filtered result

at line 308
protected array filterXML(Crawler $crawler, string $path, array $namespaces = array())

Filters the XML results of a query on a data source with the 'return path' defined in the source.

The return path is a XPath expression

Parameters

Crawler $crawler The XML results
string $path The return path defined in the source.
array $namespaces (default: array() The list of namespaces

Return Value

array The filtered result

at line 326
protected string replacePathFunctions(string $path)

Replaces the php functions in an XPath expression with the syntax required for their executions

Parameters

string $path The XPath expression

Return Value

string The new XPath expression

at line 345
protected DomDocument createXML(string $node_name, array $arr = array())

Converts an array to a XML DOM document

Parameters

string $node_name The root of the XML DOM document
array $arr (default: array() The array to be converted

Return Value

DomDocument The new XML DOM document

at line 361
protected string bool2str(bool $v)

Converts a true/false (boolean) value to a string

Parameters

bool $v The boolean value

Return Value

string The result of the conversion

at line 375
protected bool isValidTagName(string $tag)

Determines whether the given tag name is valid or not.

Parameters

string $tag The tag name

Return Value

bool true if the tag name is valid, false otherwise

at line 391
protected DOMNode convertToXML(DomDocument $dom, string $node_name, array $arr = array())

Converts an array to a XML DOM node of a DOM document

Parameters

DomDocument $dom &$dom The DOM document
string $node_name The name of the node
array $arr (default: array()) The array to be converted

Return Value

DOMNode The new DOM node

Exceptions

Exception

at line 457
protected array createArray(DOMNodeList $xml)

Creates and returns an array from a list of XML DOM node

Parameters

DOMNodeList $xml The list of XML DOM node

Return Value

array The new array

at line 471
protected void replaceTextKeys(array $array)

Replaces all '#text' keys of the given array by the corresponding text

Parameters

array $array &$array The given array

Return Value

void

at line 512
protected bool nodeHasChild(DOMNode $node)

Determines whether a DOM node has at least one DOM element as child.

Parameters

DOMNode $node The DOM node

Return Value

bool true if DOM node has at least one DOM element as child, false otherwise

at line 531
protected array convertToArray(DOMNodeList|DOMNode $xml)

Converts a list of XML DOM node to an array

Parameters

DOMNodeList|DOMNode $xml The list of XML DOM node

Return Value

array The new array

at line 564
protected array xPathFilter(string $root, array $array, string $path)

Filters an array with an XPath expression

Parameters

string $root A pseudo root node name for the XPath expression
array $array The array to be filtered
string $path The XPath expression

Return Value

array The new array

at line 579
protected array xPathDOMFilter(DOMDocument $doc, string $path, array $namespaces = array())

Filters an XML DOM document with an XPath expression and converts it to an array

Parameters

DOMDocument $doc The DOM document
string $path The XPath expression
array $namespaces (default: array() The list of namespaces

Return Value

array The new array

at line 600
static array|string xml2array(array|object $xml)

Converts an array of SimpleXMLElement to an associative array

Parameters

array|object $xml The array of SimpleXMLElement

Return Value

array|string The associative array

at line 634
static int|null timestamp(string $format, string $dateStr)

Parses a date string according to the given format and returns its timestamp

Parameters

string $format The given format
string $dateStr The date string

Return Value

int|null The timestamp or null if there is an error

Exceptions

Exception