jeremykendall / php-domain-parser

Public Suffix List based domain parsing implemented in PHP
MIT License
1.16k stars 128 forks source link

Consider modifying Rules::$rules to be public or have a getter #356

Closed TWithers closed 4 months ago

TWithers commented 5 months ago

I would like to be able to use the Rules::$rules object to do additional inspections on known domains. Right now, I am unable to access the $rules property because it is private.

What I am trying to accomplish is outside the scope of this project, but essentially it is doing some rough typo checking against domain suffixes.

For example: yahoo.cou.uk uk is the resolved as the suffix, with cou as the second level domain, and yahoo as the subdomain. I would like to leverage the $rules property to do additional checks for the known *.uk suffixes and see if I can make a match (uk has 10+ suffixes, cou.uk is very similar to co.uk, the domain should be yahoo.co.uk)

Right now, the Rules class is final, $rules is private, and parse() is private, so I am stuck copying/duplicating the code myself or hacking something together using the reflection api... both of which I don't really like.

nyamsprod commented 5 months ago

@TWithers thanks for using the library. There's a reason why the $rules property is private it is because from the POV of the library it is an implementation detail. The way the package parse and subsequently works with the Mozilla PSL is really internal. The algorithm can be changed or modified without impacted the public API. As such, the list stays the same but the way it is consumed and store can differ a lot.

What I can advise you to do is to look into https://github.com/usrflo/registered-domain-libs/tree/master which is the original library which has inspired the current one. There the "ancestor" of what is $rules represents is available as an independent include php script. Maybe that will resolve your issue.

Hope the suggestion helps you resolve your issue.