code by Alan Dix, developed at Talis


class: ManageSLD

This is the main class. It has a number of helper methods (see code), but only the main public methods described here.

loading rules

parseFile( $sourceUrl=false )
Loads and parses the specifed filepath/url, or defaults to the Public Suffix list at Mozilla
parse( $source )

Parses the rule set in the source text.
The text is assumed to be formatted correctly as documented at the Public Suffix site. Badly formatted input will produce garbage output!
The output is a set of rules of the form:
     ( 'tld'=> $tld, 'pattern'=>$pattern, 'exception'=>$exception )
Note that $rule['pattern'] does not have leading '!' when it is an exception, instead $rule[exception] is set to true.
These rules are either returned as an array of rules as a result, or saved to the specified storage (see below). If they are saved, then the function returns a count of the number of rules saved.
Various parse statistics are also saved as public properties:
     line_ct - number of lines read
     rule_ct - number of rules found in the source
     read_time - time taken to retrieve the file (when parsed using parseFile)
     parse_time - time taken to parse the source

parseToStore(), parseToRuleset()
These toggle whether rules are sent to store or returned as a rule set. Default is return as rule set.
setStore( $rulestore=false )
Sets the store for saving rules. Default is memory-based RuleStoreSLD, but you can replace this with database storage. In gthe doanloads is an example replacement using a noSQL database, but culd also use a table in mySQL or some other databse.

retreiving rules

Finds rules in the rule set which match the domain, and then applies the algorithm as described in the Public Suffix documentation.
Returns resolved domain infomation in the form:
     ( public_suffix, primary_label, secondary_part, registerable_domain, pattern, flags )
For example: would return ( '', 'bham' 'www', '', '', 0 ) would return ( 'com', ex, 'www.developers',', 0 )
The flags are a bitmask using the following defined constants:
     PUBLIC_SUFFIX_EXCEPTION_FLAG - set if the matched rule is an exception rule
     PUBLIC_SUFFIX_CATCH_ALL_FLAG - set if the catch all "*" rule has been used
     PUBLIC_SUFFIX_LONG_RULE_FLAG - set if the rule is longer than the supplied domain (e.g. domain = '' rule = '*')
     PUBLIC_SUFFIX_EXAMPLE_FLAG - set if the domain suffix was example or
As above, but looks up the rules using the supplied storage.

class: RuleStoreSLD

Default memory based storage class.

addRule( $rule )
Saves the specified rule in the store.
$rule is a named array of the form ( 'tld'=> $tld, 'pattern'=>$pattern, 'exception'=>$exception )
See documentation of parse( $source ) above.
getRules( $tld )
Retrieves all rules for the given top level domain in the same form as above..