maxmind / GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
https://maxmind.github.io/GeoIP2-php/
Apache License 2.0
2.33k stars 276 forks source link

Does not play well with PHP Scoper #194

Closed andrewjmead closed 2 years ago

andrewjmead commented 2 years ago

I'm using this library in a WordPress plugin that uses PHP Scoper to scope all dependencies.

I noticed that this library does not support PHP Scoper out of the box due to its use of string class names as seen here, here, and here.

I was able to patch this in PHP Scoper using the following patcher, but it would be awesome to see built-in support. Keep in mind this just patches the two instances in Reader.php and doesn't attempt to patch the instance in Client.php:

    'patchers' => [
        static function (string $filePath, string $prefix, string $contents): string {
            $parts = explode('vendor', $filePath);

            // Fix an issue with geoip2 where the reader has string class names
            if ($parts[1] === '/geoip2/geoip2/src/Database/Reader.php') {
                return preg_replace(
                    '%\$class = \'GeoIp2%',
                    '$class = \'' . $prefix . '\\\\GeoIp2',
                    $contents
                );
            }

            return $contents;
        },
    ],

I was encourage to open a separate issue by @oschwald in #170. Thanks!

😁

oschwald commented 2 years ago

Would you be willing to test #195 to confirm that it resolves the issue for you?

andrewjmead commented 2 years ago

Yup. I'll test it tomorrow 👍

andrewjmead commented 2 years ago

I just installed the branch using composer require geoip2/geoip2:dev-greg/no-stringy-class-names and it fixed the issue right away!

oschwald commented 2 years ago

Great! Thanks for testing!

andrewjmead commented 2 years ago

Thanks to you for addressing it!