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

Double namespacing issue when using nested namespace prefix #47

Closed
rickmacgillis opened this issue Aug 30, 2022 · 1 comment
Closed

Comments

@rickmacgillis
Copy link

Hi @BrianHenryIE. I'm having issues with Strauss adding the namespace prefix twice on my files. There doesn't appear to be any way to fix it. I've removed the custom prefix and let it use the default, and that default doesn't get added twice.

See: https://www.loom.com/share/dd52ab3e791840bdbf25bd45fcdeecf3

Here's a couple samples from the autoloader.

'Dragon\Dependencies\Dragon\Dependencies\Ramsey\Uuid\FeatureSet' => $strauss . '/ramsey/uuid/src/FeatureSet.php',
'Dragon\Dependencies\Dragon\Dependencies\Doctrine\Common\EventArgs' => $strauss . '/doctrine/event-manager/lib/Doctrine/Common/EventArgs.php',

Here's the relevant chunk from my composer.json file.

"extra": {
	    "strauss": {
			"target_directory": "strauss",
	        "namespace_prefix": "Dragon\\Dependencies\\",
	        "classmap_prefix": "DRAGON_",
	        "constant_prefix": "DRAGON_CONST_",
	        "packages": [
				"guzzlehttp/guzzle",
				"dragon-public/framework"
	        ],
	        "override_autoload": {
	        },
	        "exclude_from_copy": {
	            "packages": [
	            ],
	            "namespaces": [
	            ],
	            "file_patterns": [
	            ]
	        },
	        "exclude_from_prefix": {
	            "packages": [
	            ],
	            "namespaces": [
	            ],
	            "file_patterns": [
	                "/^psr.*$/"
	            ]
	        },
	        "namespace_replacement_patterns" : {
	        },
	        "delete_vendor_files": false
	    }
    }

Update:
It seems to only happen with nested namespace prefixes. Here's a sample after changing it to a single namespace. I'll use that, but it might be worth documenting/fixing.

'DragonDependencies\Ramsey\Uuid\FeatureSet' => $strauss . '/ramsey/uuid/src/FeatureSet.php',
'DragonDependencies\Doctrine\Common\EventArgs' => $strauss . '/doctrine/event-manager/lib/Doctrine/Common/EventArgs.php',
@BrianHenryIE
Copy link
Owner

This is fixed now. The problem was the the namespace being replace was a substring of the replacing namespace. The prefixer/replacer class is handed a list of classnames and their replacements:

array (
  'Dragon\\Email' => 'Dragon\\Dependencies\\Dragon\\Email',
  'Dragon\\Form' => 'Dragon\\Dependencies\\Dragon\\Form',
  'Dragon' => 'Dragon\\Dependencies\\Dragon',
  'Dragon\\Hooking' => 'Dragon\\Dependencies\\Dragon\\Hooking',
)

The problem here is that as the array is iterated through, after the first two replacements are made, the 'Dragon' => 'Dragon\\Dependencies\\Dragon', affects the updated string.

So the solution was to asort() so that that was done before any others.

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

2 participants