BrianHenryIE / strauss

Prefix PHP namespaces and classnames to allow multiple versions of libraries to exist without conflict.
https://brianhenryie.github.io/strauss/
MIT License
143 stars 23 forks source link

It does not prefix everything #88

Closed sovetski closed 8 months ago

sovetski commented 8 months ago

Hi,

My composer.json:

{
    "require": {        
        "aws/aws-sdk-php": "^3.257"
    },
    "require-dev": {
        "brianhenryie/strauss": "^0.16.0"
    },
    "scripts": {
        "prefix-namespaces": [
            "strauss"
        ],
        "post-install-cmd": [
            "@prefix-namespaces"
        ],
        "post-update-cmd": [
            "@prefix-namespaces"
        ]
    },
    "extra": {
        "strauss": {
            "namespace_prefix": "MyCustomTest\\",
            "classmap_prefix": "MyCustomTest_"
        }
    }
}

I applied this suggestion which works as well, and it runs very quickly now.

But the problem is: The library does not prefix everything, in AWS example, before or after removing unused services, the problem is the same. It does not prefix this code (in: /vendor-prefixed/aws/aws-sdk-php/src/S3/S3Client.php):

    public function getObjectUrl($bucket, $key)
    {
        $command = $this->getCommand('GetObject', [
            'Bucket' => $bucket,
            'Key'    => $key
        ]);

        return (string) \Aws\serialize($command)->getUri(); // <<<---- HERE
    }

All other parts look fine, only this code is not prefixed, and I can not upload any files to AWS without this.

Any idea? I guess maybe it is because it starts with \?

BrianHenryIE commented 8 months ago

Great, thanks! That's merged into master now, https://github.com/BrianHenryIE/strauss/commit/a9bb376b70c3f0e1d2123bbb04d7f81dc9ca153a, and I added a test, https://github.com/BrianHenryIE/strauss/commit/6518699c8f96951a950f542a263d97a5f3fffb34. I also applied that removeUnusedServices script to some older tests that I had marked as skip because they were previously too slow, https://github.com/BrianHenryIE/strauss/commit/5b905e107ddcbcac174fa93326f10ef7f670fe9a.

In general, edge cases like these need to be identified from errors before I can fix them. I think it would be better if this tool were using nikic/PHP-Parser, but the regex approach has gotten us this far. The currently open issues are more around dealing with Composer than the replacements themselves so it's not a priority to look into yet.

I have some other work in-progress so I'm not going to create a release immediately.