Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatch between extended class name and the actual class name #27

Open
alexmigf opened this issue Jul 29, 2021 · 3 comments
Open

Mismatch between extended class name and the actual class name #27

alexmigf opened this issue Jul 29, 2021 · 3 comments

Comments

@alexmigf
Copy link

alexmigf commented Jul 29, 2021

Hi @BrianHenryIE

We are facing an issue using your library with the symfony/polyfill-intl-normalizer, as the /Resources/stubs/Normalizer.php extended class shows like this:

class Normalizer_Test_Normalizer extends Normalizer_Test\Symfony\Polyfill\Intl\Normalizer_Test_Normalizer\Normalizer
{

when the actual Normalizer.php class name in the library root dir is:

namespace Normalizer_Test\Symfony\Polyfill\Intl\Normalizer_Test_Normalizer;

class Normalizer_Test_Normalizer
{

The error:

Uncaught Error: Class 'Normalizer_Test\Symfony\Polyfill\Intl\Normalizer_Test_Normalizer\Normalizer' not found in /lib/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php:9

You can easily test this using your phar.php and this JSON in a test directory:

{
    "require": {
        "symfony/polyfill-intl-normalizer": "^1.23"
    },
    "extra": {
        "strauss": {
            "target_directory": "lib",
            "namespace_prefix": "Normalizer_Test\\",
            "classmap_prefix": "Normalizer_Test_",
            "packages": [],
            "override_autoload": {
            },
            "exclude_from_copy": {
                "packages": [
                ],
                "namespaces": [
                ],
                "patterns": [
                ]
            },
            "exclude_from_prefix": {
                "packages": [
                ],
                "namespaces": [
                ],
                "patterns": [
                    "/^psr.*$/"
                ]
            },
            "namespace_replacement_patterns" : {
            },
            "delete_vendor_files": false
        }
    },
    "scripts": {
        "strauss": [
            "@php strauss.phar"
        ],
        "post-install-cmd": [
            "@strauss"
        ],
        "post-update-cmd": [
            "@strauss"
        ]
    }
}
@alexmigf alexmigf changed the title Missmatch between extended class name and the actual class name Mismatch between extended class name and the actual class name Jul 29, 2021
@Spreeuw
Copy link

Spreeuw commented Jul 29, 2021

@BrianHenryIE as a more general question, would you say polyfills like these should be excluded from Strauss treatments?

Considering that for example this Normalizer polyfill defines missing global functions like normalizer_is_normalized and normalizer_normalize only when they're not defined in the first place, and that those functions aren't renamed themselves (or contained in a namespace)

BrianHenryIE added a commit that referenced this issue Aug 1, 2021
@BrianHenryIE
Copy link
Owner

I didn't mean to close this. Still more work to do!

@BrianHenryIE
Copy link
Owner

OK, @alexmigf , the actual bug is fixed.

But as @Spreeuw points out, this might not be worth prefixing.

bootstrap.php operates in the global namespace. Strauss adds prefixes to existing namespaces, it does not add a namespace to files with none in them (although that's an interesting idea and could work as an alternative to prefixing classnames).

So when our plugin autoloader runs, Symphony's boostrap is going to check for a global normalizer_is_normalized() function, and add it if absent. If another plugin has loaded an older (or newer) version of polyfill-intl-normalizer, normalizer_is_normalized() will already be defined and that code used.

So the problem Strauss aims to solve is not correctly addressed here. And I don't think there is any benefit to prefixing the namespace.

I've seen suggestions for unit testing global functions by redefining them inside the project root namespace. i.e. Normalizer_Test\normalizer_is_normalized(). I think if normalizer_is_normalized() is called within the Normalizer_Test namespace, it will call normalizer_is_normalized() if available and Normalizer_Test\normalizer_is_normalized() otherwise.

I'll leave this open for discussion and until I test that idea out.

This is the config for excluding it, and this may end up being the default configuration:

{
    "require": {
        "symfony/polyfill-intl-normalizer": "^1.23"
    },
    "extra": {
        "strauss": {
            "exclude_from_prefix": {
                "packages": [
                        "symfony/polyfill-intl-normalizer"
                ]
            }
        }
    }
}

@BrianHenryIE BrianHenryIE reopened this Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants