BIOSTALL
BIOSTALL

Reputation: 1696

Same namespaces used by 2 vendor packages: laravel and lumen

In my project we have both Laravel and Lumen being installed by a single composer.json. Laravel for a web project, Lumen for an API, both of which are part of the same 'project'.

So in the 'vendor' folder I have the following files:

vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/EventServiceProvider.php

and

vendor/laravel/lumen-framework/src/Foundation/Support/Providers/EventServiceProvider.php

Now both of these use the same namespace:

Illuminate\Foundation\Support\Providers\EventServiceProvider

In one of our classes I do:

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

The problem is that both packages in the 'vendor' folder use this namespace, yet the files and methods within the files are different.

Is there anyway to explicitly specify which version of the namespace we use? Or add an alias to one of them?

Obviously I can't change the packages because 'composer update' would override them.

Any ideas welcomed. Thanks

Upvotes: 2

Views: 703

Answers (1)

dlporter98
dlporter98

Reputation: 1630

There are two different namespaces (not one) containing two classes with the same name. Just use two alliases:

use Illuminate/Foundation/Support/Providers/EventServiceProvider as IlluminateEventServiceProvider;
use Foundation/Support/Providers/EventServiceProvider as LumenEventServiceProvider;

From here you will be able to call both classes without ambiguity.

Upvotes: 0

Related Questions