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

Cannot declare class because the name is already in use in #3

Open
AliHichem opened this issue Jul 8, 2021 · 1 comment
Open

Cannot declare class because the name is already in use in #3

AliHichem opened this issue Jul 8, 2021 · 1 comment

Comments

@AliHichem
Copy link

AliHichem commented Jul 8, 2021

Hi,

Thank you for this amazing tool, it works perfectly and helps me decrease the size of my lambda funtions on aws.
In a Symfony project and on a dev evironment it works like a charm but on prod I get the error symfony prod Cannot declare class because the name is already in use in

My .vendor_compress file is :

<?php
declare(strict_types=1);

use Donatorsky\VendorCompress\Config;
use Donatorsky\VendorCompress\FileFilters\BasenameFilter;
use Donatorsky\VendorCompress\FileFilters\BasenameRegexFilter;
use Donatorsky\VendorCompress\FileFilters\ExtensionFilter;
use Donatorsky\VendorCompress\FileFilters\IsDirectoryFilter;
use Donatorsky\VendorCompress\FileFilters\IsFileFilter;
use Donatorsky\VendorCompress\FileFilters\VendorPackageFilter;
use Donatorsky\VendorCompress\FileProcessors\MinifyJsonFileProcessor;
use Donatorsky\VendorCompress\FileProcessors\StripWhitespacesPhpFileProcessor;

return Config::create()
	->setFilesCompressionMethod(Phar::NONE)
	->setArchiveCompressionMethod(Phar::NONE)
	->setExcluded([
		new VendorPackageFilter('donatorsky', 'vendor-compress'),
		new IsDirectoryFilter(new BasenameFilter('docs')),
		new IsDirectoryFilter(new BasenameFilter('tests')),
		//new IsDirectoryFilter(new BasenameFilter('src')),
		//new IsDirectoryFilter(new BasenameFilter('public')),
		//new IsDirectoryFilter(new BasenameFilter('config')),
		new IsFileFilter(new BasenameFilter('composer.json')),
		new IsFileFilter(new BasenameFilter('composer.lock')),
		new IsFileFilter(new BasenameFilter('.gitignore')),
		new IsFileFilter(new BasenameRegexFilter('/^(?:README|CHANGELOG|phpunit.*\.xml.*$)/i')),
	])
	//->addFileProcessor(new MinifyJsonFileProcessor(), new ExtensionFilter('json'))
	//->addFileProcessor(new StripWhitespacesPhpFileProcessor(), new ExtensionFilter('php'))
	;

I had to disable json minification due to a different error but it's okay.
I thought this autoloading duplicates was caused but the StripWhitespacesPhpFileProcessor but disabling it didn't solve the issue on prod ..

Any idea ? I would really love to use this tool but until now I can't since it's broken on prod evironment

PS: when I say "prod" I mean the environment state within my symfony project.

Thank you !

@donatorsky
Copy link
Owner

Hi,

Happy to see that You are using this tool! It's going to be quite hard to find a solution for that without accessing Your project and playing with it and Vendor Compress, but I understand it may be impossible for You to share it.

A couple of thoughts on this:

  • The Cannot declare class because the name is already in use error occurs when some file is included/required more than once, but it shouldn't be. Most probably, there is some include_once/require_once call which tries to load file, thus disabling filters won't help.
  • Originally, this project was created to work with Composer v1, and it was not updated since the release of v2. The autoloading may have changed, and as Vendor Compress works by modifying these autoloading files, I see this as a potential root cause of the problem.
  • By dev or prod You probably mean different environment configurations and project building conditions. I suppose there are some differences in building process, different composer install flags, perhaps. It is a good practise to enable --optimize-autoloader or --classmap-authoritative options when preparing production build. You can try disabling them (or their combination) for now, but it may affect the performance of Your application.

I'll look into this more thoroughly and configure it in my projects in a spare time, but it certainly won't happen in the next week... Sorry for that!

Anyway, thanks for Your feedback, and apologies for not helping You more! I will let You know when I find a solution.

BTW,
Regarding a compression issues, I noticed, that Phars with archive compression are not always working correctly. Try enabling files compression only. I remember that Phar::GZ was working for me.

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