Skip to content

Does not play well with PHP Scoper #194

Description

@andrewjmead

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!

😁

Activity

  1. oschwald commented on Aug 4, 2022

    @oschwald
    Member

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

  2. andrewjmead commented on Aug 5, 2022

    @andrewjmead
    Author

    Yup. I'll test it tomorrow 👍

  3. andrewjmead commented on Aug 5, 2022

    @andrewjmead
    Author

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

  4. oschwald commented on Aug 5, 2022

    @oschwald
    Member

    Great! Thanks for testing!

  5. andrewjmead commented on Aug 5, 2022

    @andrewjmead
    Author

    Thanks to you for addressing it!

  6. added a commit that references this issue on Aug 6, 2022
    7648b11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions