serbanghita / Mobile-Detect

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
http://mobiledetect.net
MIT License
10.55k stars 2.68k forks source link

Use getters (ie. getTabletDevices()) #928

Closed pquerner closed 1 year ago

pquerner commented 1 year ago

(Using version 2.8.34)

We have getters like public static function getTabletDevices() but they dont seem to be used; which makes it hard to overwrite, or add stuff to the big regex data arrays, for instance protected static $tabletDevices.

If we want to extend the class Mobile_Detect and add to the $tabletDevices data array by extending getTabletDevices it would be the easiest way.

Ie this:

foreach (self::$tabletDevices as $_regex) {
            if ($this->match($_regex, $userAgent)) {
                return true;
            }
        }

changes to

foreach (static::getTabletDevices() as $_regex) {
    if ($this->match($_regex, $userAgent)) {
        return true;
    }
}

And then the extending class can overwrite getTabletDevices properly.

serbanghita commented 1 year ago

@pquerner you have a point, can you submit a PR? Are you using PHP5?

pquerner commented 1 year ago

Yes I can give you a PR. I'll do that in the coming days. I have an application stuck on PHP 7.0 for now, hence why I am on the 2.x Branch. :(

serbanghita commented 1 year ago

@pquerner 👍 I made changes to 3.74.x branch and will publish soon

pquerner commented 1 year ago

@serbanghita I saw. I commented on the commit, can you check it please?