BrianHenryIE / strauss

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

Having trouble to prefix classes using last stable version #106

Closed alexmigf closed 2 months ago

alexmigf commented 4 months ago

I'm having trouble to prefix the libraries classes using the latest stable version, not sure what I'm doing wrong:

{
    "name": "something/something",
        "autoload": {
            "psr-4": {
                "SOMETHING\\": "includes/",
                "SOMETHING\\ELSE\\": "src/"
            },
            "classmap": [
                "vendor/"
            ]
    },
    "extra": {
        "strauss": {
            "target_directory": "vendor",
            "namespace_prefix": "SOMETHING\\Vendor\\",
            "classmap_prefix": "SOMETHING_Vendor_",
            "constant_prefix": "SOMETHING_VENDOR_",
            "packages": [
            ],
            "update_call_sites": false,
            "override_autoload": {
            },
            "exclude_from_copy": {
                "packages": [
                ],
                "namespaces": [
                ],
                "file_patterns": [
                ]
            },
            "exclude_from_prefix": {
                "packages": [
                    "symfony/polyfill-mbstring",
                    "symfony/polyfill-iconv"
                ],
                "namespaces": [
                ],
                "patterns": [
                ]
            },
            "namespace_replacement_patterns" : {
            },
            "delete_vendor_packages": false,
            "delete_vendor_files": false
        }
    },
    "config": {
        "platform-check": false
    }
}

I'm targeting vendor but I tried with lib and I get the same output.

BrianHenryIE commented 3 months ago

Works for me. You left out the require part of your composer.json so I tested with composer require psr/log and it looks alright. Maybe post a fuller example and specific file that is not prefixed as expected.

alexmigf commented 3 months ago

Hi @BrianHenryIE,

The file is identical to the one above, except that I intentionally omitted the require statement, as it can be any library. I am testing with Dompdf, but the issue persists. The namespace has been correctly modified, and the class name remains Dompdf (I think it should be SOMETHING_Vendor_Dompdf).

alexmigf commented 3 months ago

@BrianHenryIE

Do you have any idea what might be causing the issue?

BrianHenryIE commented 2 months ago

The classname is unchanged when inside a namespace. It is only changed in the global namespace where it could conflict with another. Once the namespace it exists in is renamed, the problem is solved.

I was considering removing the class renaming altogether in favour of moving things from the global namespace into their own namespace. But at the glacial pace of development, that's not going to change anytime soon.

alexmigf commented 2 months ago

Thank you for the information!